No, this is not the latest horror from the Microsoft Research Labs
Biotech Division, but a story of what happens when you have a failing
disk, no backups, but more than enough confidence that "something can
surely be arranged".
Chapter 1: The background
Imagine a 3Gb hard disk, several years old. Imagine a 1.5Gb partition
on it. Imagine Windows 98 preinstalled on that partition, along with
miscellaneous software - some of it vendor installed, some downloaded
from the net, some from $DEITY knows where. To complete the picture,
also imagine user data files scattered all over the place.
Now imagine said disk starting to develop read errors at an increasing
frequency. Soon enough, the truth must be faced. This disk is dying.
Chapter 2: Enter the Penguin
A brand new disk, a whopping 17Gb in size, is purchased, and installed
in place of the old one. Now all that is needed is something to make
it boot. That something turns out to be a new Storm Linux install CD,
costing 47FIM with a rather nice magazine attached.
Meanwhile, a hopeful plan has begun to form. Thus is the new disk
partitioned, with 2.5Gb for Linux root, 2.5Gb set aside for Windows,
a little bit for swap and odds and ends, and the rest split into two
partitions for user data, one called "/home" and the other "D:".
Chapter 3: Last minute rescue mission
Now the first hack begins. Hoping that it might be good for one more
read, the old disk is attached in place of the CD-ROM drive. Linux is
booted, a root shell opened, and the rescue mission commences:
# dd if=/dev/hdb1 of=hdb1.image conv=sync,noerror 2>hdb1.log
Hours later, we have a disk image. While it looks like swiss cheese,
most of it is nonetheless there. But we're not done yet! Knowing the
read failures are largely random, a _second_ image is produced. This
takes even longer, and has even more holes, but in *different* places.
Chapter 4: Patching it together
Perl to the rescue! A one-liner is written to read the two disk
images, OR the bits together, and write out the result. Meanwhile,
another script is used to combine the logs to produce a list of the
blocks that didn't make it into either image. There are a good dozen
of them left, but hopefully the result is usable:
# losetup /dev/loop0 hdb1.image
# mount -r -t auto /dev/loop0 /mnt/old
And lo and behold, the old filesystem is all there, safe inside the
image on the new, working disk.
Chapter 5: Evaluating damage
But are the important files all there? There's only one way to tell.
Yet one more Perl script is written to parse to list of remaining bad
blocks and overwrite each of them with "BADBLOCK" x 64. Another Perl
script then loops on the output of "find /mnt/old -type f", grepping
for "BADBLOCK". Returning from my coffee break, there are two names
listed on the console:
/mnt/old/windows/system/odbcji32.dll
/mnt/old/win386.swp
Chapter 6: Resurrection
All that remains now is moving the files from the disk image onto the
actual new partition. Unfortunately mtools refuses to make sense of
the image, and mkdosfs doesn't seem to be much use in formatting the
new partition either.
So it is time to leave the comfort of Linux for a while, and apply a
boot disk from a Win95 laptop that I managed to borrow. "FORMAT C:"
and "SYS C:" later, I'm back in Linux, and ready to see just how much
abuse Windows will take:
# mount -t auto /dev/hda2 /mnt/new
# cp -a /mnt/old/* /mnt/new/
Will it boot? One way to find out.. Add a few lines to lilo.conf, run
/sbin/lilo, press Ctrl-Alt-Del, select "dos", and pray.
Chapter 7: It's alive!
There wasn't much time for prayer, though. Windows was up and running
in record time - the disk was new, and I'd effectively defragged it in
the process. Just to make sure everything was fine, I ran Scandisk,
which did complain about a bunch of character coding problems in file
names, but fixed those easily.
And thus was Windows restored, and all the precious software and user
files too. And there was much rejoicing. (And Linux remained on the
system, and for that there was much rejoicing as well..)
Maybe I should write a HOWTO about this.
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method." -- Abigail in c.l.p.m