Friday, May 18, 2007

How to recover ext3 partitions

Short version: use TestDisk. Get it now, before you need it. Download from here. Or get it on a boot CD, such as Hiren's. Then keep it near your PC.

Longer version:

I'm the buildmeister for a software company, and we build on 3 different Linux distros, so the build machine has 4 distros installed, each to its own partition. Plus a partition for the source code, plus a partition for the releases, and finally one for the developers to do private builds on. Plus swap. So it currently has 8 ext3 partitions. And has had a few "partition panics" over the years.

The machine is rarely rebooted - Mandriva 2007 is a "host" OS, and we chroot into the other for actual builds. In fact the only time I really reboot it is when I have to install another OS, like today. They asked for builds on CentOS, so I grabbed a DVD, rebooted and ... oh dear here we go again.

The installation routine for CentOS insists my partition table is "too corrupted" to read, and refuses to install (well, it did kindly offer to wipe the entire disk, but we won't go there). Interestingly switching consoles after the installation has disdained the disk, reveals that all the various partitions are mountable, so I figured the installation disk was the problem. Burn another DVD, same problem, re-download and re-burn, same problem. All right, all right, so it might be the partition table.

Rule one for fixing "problem with your partitions" is:
  1. you're always going to lose at least one partition in trying to recover the others.
YMMV, but it always seems to happen to me.

Today it was the Fedora Core 3 partition which "disappeared", and just as I realised I was about to dig a deeper hole in trying to get it back, I remembered the one tool that was always the last tool I used in all other partition problems: TestDisk. Even if is the first tool I try it's still the last, because I never need anything else afterwards.

It is not always the first because "partition down" always brings me out in a wee panic, and I grab the first tool to hand. The only thing wrong with TestDisk, is that the name does not suggest "partition recovery", especially when the wee panic is building !

So I ran it - and it could not get back the FC3 partition at the same time as all the others, but it did allow me to access it for long enough to backup the data. Then it found all the other partitions, allowed me to re-activate them, and recreate an FC3 partition. Restore data, and machine is back to where it was.

Except that this time, the partition table is written correctly, so: put the CentOS DVD back in, reboot, and now it starts the install routine just fine.

Of course I needed to do a bit of squeezing to make room for the CentOS partition, and ... oooh look, gparted can resize partitions on the fly. I'll have a wee go with that after installation, and then I may just wonder why the partition table is hosed when I reboot in six months to add another OS.

They really should put TestDisk on the installation disk for all Linux distros, so that it is easily accessible from the "linux rescue" console.

Labels: , , , ,

1 Comments:

Blogger Unknown said...

Have to say, I'm very angry with you right now...

it took far too many queries to google for me to find this post /=

9:00 p.m.  

Post a Comment

<< Home