Recovering a Lost Partition Table


Note: This is an archived page. I am keeping it available because people still find it useful - but the contents of this page will likely become gradually out of date.

I never thought it'd happen to me... My computer was functioning just fine. I went into the BIOS to check something or another, and noticed the time was off a bit. So I changed the time, saved the settings, and viola! Suddenly there was "no operating system" on my disk. Somehow, some way, my partition table was gone.

Of course I hadn't backed anything up yet! I'd recently installed Red Hat Linux, and was dual-booting my system between RHL and Windows 98SE. I had seven partitions set up on my laptop, and my first thought was "AAAAAHH!! All my programs! All my data! They're toast!!" But once I calmed down and was able to think clearly, I began to think about how maybe, just MAYBE, I could recover from this.

It certainly wasn't easy, and I spent several hours finding the answers; but in the end I was able to recover my partition table. In the end no data or programs were lost at all. I'm writing this page to consolidate the information I found useful, in the hope that I can make this process a lot less painful for someone else. It might not work for you, but then again it just might save you a lot of grief!

What NOT to do

Do not start reinstalling your operating system(s). Once you repartition your disk and begin re-installation, there's no turning back. First, try the steps I'll detail below. They're not guaranteed to work, but they did work for me. You've got very little to lose, and lots to gain! After all, your programs and data are already gone...

What an intelligent person should have already done

Everyone should have a copy of their partition table data ahead of time. This is easy in Linux. Just type "fdisk -l" and it'll spit out a list of your partitions. What you really need to know is the starting and ending cylinder numbers for each partition, along with the partition type/ID. The types are in hexadecimal - #83 is your basic Linux ext2 type, #0b is a Windows FAT32 partition, #82 is a Linux swap partition, and so on. The fdisk utility can generate a list of all the types, but you don't really need to know them all - only the ones you have on your disk. ;-)

Here's a copy of mine:

     Disk /dev/hda: 255 heads, 63 sectors, 1467 cylinders
     Units = cylinders of 16065 * 512 bytes 
        Device Boot    Start       End    Blocks   Id  System
     /dev/hda1   *        26       254   1839411    b  Win95 FAT32
     /dev/hda2             1        22    176683+  84  OS/2 hidden C: drive
     /dev/hda3           255       257     24097+  83  Linux
     /dev/hda4           258      1467   9719325    f  Win95 Ext'd (LBA)
     /dev/hda5           258      1026   6176961   83  Linux
     /dev/hda6          1027      1067    329301   82  Linux swap
     /dev/hda7          1068      1467   3212968+   b  Win95 FAT32
     Partition table entries are not in disk order

With this information, rebuilding your partition table is a piece of cake. All you need is fdisk, Partition Magic, or something similar.

Well, Trav, you're saying you had this info ahead of time?

Um... No. Note that the previous section referred to an intelligent person.

Waah! I don't have it either! Tell me what to do!

First things first. This whole process is based on the assumption that your problems don't stem from a damaged hard drive. If your disk is damaged this procedure is not likely to work. Also, you are the best judge of your own comfort level when it comes to computers. You don't need to be a Unix Guru, but I assume you have a basic understanding of using system commands and utilities (and can read man pages if you don't understand something).

If you're a Windows-only user, you might have an easier time of it. Just use your Windows boot disk, and have MBRwork handy. It works well, but only on Windows-type partitions. This was the first thing I tried. It correctly found my FAT32 partitions, but of course couldn't define the others in between.

For the rest of you: Take a deep breath and try to relax. I assume you're at a different, and functional, computer - follow this link to get a copy of GNU Parted. This program basically is a freeware work-alike to Partition Magic. They even have a bootable floppy disk image available! I didn't find out about Parted until after the fact, but now it's one tool I always keep handy. Note that the fdisk utility can be used instead of parted.

Of course, Parted isn't going to tell you where your partition boundaries used to be. For that you need the tool gpart. Gpart attempts to guess your partition boundaries and types by scanning your hard disk. It's not perfect - in its initial pass of my disk it got the correct types and settings, but its final report mysteriously left out a couple partitions and tried to tell me the extended partition started a partition earlier than was the case. So you really need to have some basic knowledge of your disk layout. It's also important to remember that partitions should always end on a cylinder boundary. When "creating" your new partitions, Parted will catch this if you make a mistake; but fdisk will not.

If you didn't grab the Parted boot floppy, you're going to need is a stand-alone system on a disk. I snagged a set of Slackware floppies from a co-worker, but most Linux distributions can also generate these. Note that your Linux rescue disks do not qualify - those generally boot and then mount the existing partition(s) on your hard drive.

The actual procedure is quite simple, but it's still nerve-wracking because of the importance of what you're doing. You boot using the floppy, then run gpart. Based on that information write down, on paper, the way your partition table should look. Finally run fdisk (or parted) to rebuild your partition table. I ended up using fdisk because I was more familiar with it. Either way, just set up the partitions one by one, using the info you gained from gpart (tempered by your previous knowledge of the disk's layout). Once you've got it all set up, just tell fdisk to write the new partition table. That's it!

If you're lucky, your system should now boot. Linux users may have to boot with their rescue disks and run LILO beforehand. I will tell you that, once I saw all my data and drives were back, I felt like I'd dodged a bullet!

What if it doesn't work?

You can actually try this procedure again if necessary; for example, if some of the information from gpart was ambiguous there might be a couple different possible disk layouts. But after two or three tries you're probably out of luck.

[Back to Trav's main page]


All contents © 2001 Travis Saling
Document last modified on 05/10/2001