Share |

3.3 Recovering lost partitions (testdisk, gpart, fdisk)

It can happen that you did something stupid or something inexplicable happened and your partition table has gone or is corrupted.

To recover your partition tables, there are a few methods.

Fdisk

I'm not referring to the Microsoft dos version of fdisk, but to the fdisk on Linux.
Actually what you do with this is to manually redesign your partition table. Of course, the risk here is that you have absolutely no idea how your partition table looked before or even if you had more than one partition. So this is a good strategy in the case of a disk having only a single partition.
Let us say, in this case, that the partition contains an NTFS filesystem on /dev/hda1
Make sure nothing is mounted (run umountallfs)
Run fdisk:
-'fdisk /dev/hda'
-In fdisk: press 'p' to print your actual partition table
If your actual partition table is a bad one, erase by removing each partition with 'd' and answer with the right partition number (in case of logical drives, first remove everything equal and above 5).
-'n' for new partition
Choose primary partition, press enter for start and end sector. Fdisk automatically assigns it as a Linux native partition.
-'t' to toggle the partition type. Ntfs is '7'
-'a' to make it active (choose '1'), since it's probably the bootpartition
-'w' to write your changes

If this was your previous partition layout, you should now already be able to mount the ntfs partition. If not, you probably won't be able to boot from it either. But it should be, since this is the way to do it when the problem was simply a lost partition table.

Testdisk

This is the more advanced method of recovering partitions. Run 'testdisk' at the command line, the rest speaks for itself (Intel partition table => Analyze => etc.). Read the testdisk documentation atwww.cgsecurity.org
Testdisk is also very nice to repair bootsectors. Just play with it a little on a test machine to see what it all does. I have played around with it myself, and although there is no guarantee that you will be able to repair the bootsector every time, it still did a pretty good job where others failed.
Another thing I can recommend to you about testdisk: if it does not find all of your partitions in the first minute, there is probably not much left but some free disk space without a valid filesystem. It is safe to cancel already if you think it found all you need.

Cfdisk

A menu based fdisk replacement, easier to use than the standard fdisk

Gpart

Guess partitions: a utility that might recover your partitions too. However, it has not been maintained for a few years and I have not yet tested it myself.

Updated: July 28, 2010