Fixing a corrupt FAT32 boot sector with DEBUG

These are quick and dirty instructions, and I don't take any responsibility for any damage you might do to your disk while using them.

I figured this technique out after some over-eager anti-virus software over-wrote my boot sector and master boot record with older copies. This wouldn't have been so bad, except I'd resized the main partition with Partition Magic a few days before, so the cluster size was different! After fixing the partition size with Linux's fdisk (preferred over the DOS version for doing recovery work because it doesn't overwrite any data), the directory still looked garbled because of the incorrect cluster size. The procedure below restored the drive to perfect health.

Microsoft, perhaps having anticipated us, has thoughtfully provided a backup copy of the boot sector at sector 6. We're going to copy this to sector 0.

First, run DEBUG and load the backup boot sector into memory. The number in bold is the drive number, with 2 corresponding to the first hard disk.

-L 100 2 6 1

If you've overwritten the boot sector with something totally unrecognizable, DEBUG may just give you an error. If so, you'll have to use a sector editor instead. Otherwise, it's a good idea to take a look at the first part of the sector you just grabbed, and make sure it's actually a boot sector:

-D 100
xxxx:0100  EB 58 90 4D 53 57 49 4E-34 2E 31 00 02 40 20 00   .X.MSWIN4.1..@ .
xxxx:0110  02 00 00 00 00 F8 00 00-3F 00 FF 00 3F 00 00 00   ........?...?...
xxxx:0120  82 91 A8 04 63 25 00 00-00 00 00 00 CC 00 00 00   ....c%..........
xxxx:0130  01 00 06 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
xxxx:0140  80 00 29 FD 1C 1C 2A 4F-53 50 52 45 59 00 00 00   ..)...*OSPREY...
xxxx:0150  00 00 46 41 54 33 32 20-20 20 FA 33 C9 8E D1 BC   ..FAT32   .3....
xxxx:0160  F8 7B 8E C1 BD 78 00 C5-76 00 1E 56 16 55 BF 22   .{...x..v..V.U."
xxxx:0170  05 89 7E 00 89 4E 02 B1-0B FC F3 A4 8E D9 BD 00   ..~..N..........

Looks good -- notice the "MSWIN4.1" and "FAT32" system IDs. Yours may vary a little, but you should see something like this. (OSPREY is the volume label of this partition.)

Now, write the backup boot sector to sector 0:

-W 100 2 0 1

That's it. Exit DEBUG (with the "Q" command) and immediately reboot to force the system to re-read the boot sector.

Note that these instructions are for recovering the boot sector of the first partition on the drive. If it's a later partition you've corrupted, you'll have to offset the sector values by the starting sector of the partition. In that case, it may be easier to use a sector editor that will do some of the math for you.

gull@cyberspace.org

Valid HTML 3.2!