Restore partition table in Linux after formatting drive

Q In my frustration at trying to get a new SATA drive to format, I accidentally formatted the wrong drive, which had three partitions (/, /home and swap). I must admit I was using the Windows XP install disk (last resort, honest!). I managed to press the reset button a few seconds in after failing to stop it with Esc or Ctrl+Alt+Del. The hard drive is of course unbootable now, but when I load up Knoppix and QtParted it still seems as if the /home partition is there (the desktop icon is present), although the other partitions have bitten the dust (unformatted space). If I try to get the partition (hda3) to mount by double-clicking on its icon on the Knoppix desktop, an error code says something like 'filesystem not defined', which I suppose has something to do with the first chunk of hard drive having been formatted (is that where the 'TOC' info is held?). Can you help?

A If you know the sizes of the partitions, you can create them again in Cfdisk. As long as you have not created any new filesystems in their place, the filesystems should still be on the disk - you have probably only deleted the partition table. It may take some trial and error to find the correct sizes for each partition, but as long as you mount each one read- only (add -o ro to the mount command) you can't make things worst. It is not surprising that you can no longer boot from the disk, as you have removed the root partition from the partition table, so Grub cannot find its files.

There are a couple of utilities for automating the process: Gpart (not to be confused with GParted) and TestDisk. They are both on the Knoppix 5.0.1 CD and DVD. You should be aware that these programs are trying to guess your partition layout from leftover data; the Gpart man page sums it up nicely with, "It should be stressed that Gpart does a very heuristic job, never believe its output without any plausibility checks. It can be easily right in its guesswork but it can also be terribly wrong. You have been warned." Whichever program you try, read the man page thoroughly before you touch a byte of your disk, and be patient. Both programs take a long time to run, as they are scanning every sector of your hard disk, so an extra few minutes spent reading won't make much difference to the overall time taken, but could have a huge effect on the result.

Incidentally, a TOC (table of contents) is used on CD and DVD filesystems. Hard disks have a partition table at the start of the disk, with the directory information contained in the filesystem itself.

Back to the list