Thursday, November 1, 2018

How-To Recover Accidentally Deleted Disk Partition -Part2

Method 2

The earlier method was a bit lengthy and needs proper planning and implementation. Now, let’s discuss about using “parted” tool to recover corrupted or deleted partition table details. This method is rather easy and straight farword which doesn’t need so many steps to be performed as we did earlier.

The “parted” tool is a powerful disk utility which can do many functions such as recovery of partition data, resize etc., and also the default utility being used if disk size is greater than 2.2TB. Another powerful feature of “parted” is that it is GPT aware.

Let's replicate the issue: Destroy partition table of ‘/dev/sdb’. Again, we'd use "dd" command to destroy the partition table details of device "/dev/sdb" now and later recover it using "parted" tool.

Let's recover partition tableStep 1

Restore partition table using “parted”

Now, let’s restore the available partition table details using “parted” command. We’d need to run “parted” command with “rescue” and need to define starting and ending points. If a partition is found then ‘parted’ tool would ask for confirmation to add it. Before running ‘rescue’ operation it is necessary to initialize the label as “msdos” as shown here:

Let’s run ‘rescue 0% 100%’(need to specify beginning and end points) command to restore first partition as shown:

Yes, it is has restored the missing first partition now. Now, let’s run the ‘rescue’ again and this time we know that our starting point should be “633MB” and ending point should be “100%” as we don’t know the end:

Again, the ‘parted’ tool recovered second partition table successfully. As we are not sure if there any further partitions, let’s run ‘rescue’ again and check. There was no further partition details found as shown:

Exit the “parted” command and verify if data can be recovered now.

Step 2

Mount & verify recovered partitions

Let’s check if recovered partitions are shown in “fdisk” command now.

There seems to be some misalignment as reported by fdisk, since this was created by ‘parted’ tool. So, to correct this, delete and re-create using “fdisk” with correct size:

Let’s mount ‘/dev/sdb1’ on ‘/data1’ and check if data is available.

Yes, we got the data back from ‘/dev/sdb1’. Now, let’s try to mount ‘/dev/sdb2’ and verify. In this case it would fail since it is physical volume which needs to be restored using “vgcfgrestore” as we did before. So, let’s run it and verify:

That’s it, we got our data back successfully!NOTE: In case of XFS file system, the command "xfs_info <mount-point>" could be used to get the file system meta data details such as "Block size", "Block count" etc., There are many other open-source tools available such as "testdisk" which could also be used to recover deleted partition details easily.

PageViews

About Me.

This is just about me, my experience, my interest, my passion.... I am from Mysuru which is so popularly known as Cultural Capital of Karnataka(India). I started my carrier as a technical support person, my interest grew on Linux, started working on Linux operating system, currently working as Infrastructure Lead in a private company. Although I got enough experience in this Linux world I still feel there is some empty space which needs to be filled up every day, so, every day there is a new learning, that is what we say, learning is a never ending path. We are all here to share/learn/spread the knowledge. There is much more to learn/gain in this open-source world. Happy Learning.....