3 Aug 2005 coywolf   » (Journeyer)

The night before last, I did a dd if=bioboot of=/dev/hda6 while I was playing with the OpenBSD bootloader on my home desktop. The biosboot is an exactly 512-byte boot sector, and the /dev/hda6 is vfat. No, I don't use windows. The box was shipped with windows, so there're hda1, hda5, hda6 (c:, d:, e:) exist as vfat.

I didn't realise the problem when I did the dd. I thought it was FAT partition. The first sector is boot sector, solely for booting. FAT tables are certainly not in that small area. I thought it was safe since I don't have to boot from it.

Last night I found I couldn't mount hda6, I realised I was in trouble. I may lost that file system. But I didn't have time to repair. Someone else was using my pc.

Tonight, I've reliased how severe the trouble is after some trying. I may lost that filesystem with 12G data. The kernel reports

FAT: Filesystem panic (dev hda6)
    fat_get_cluster: invalid cluster chain (i_pos 0)

The fact is that FAT uses the first sector also as a superblock. It even stores the media type on it. That explains why previous linux bootsector had to make guesses on track sector numbers. :-(

Is there any hope? In the boot sector, the 062-063(in octal), stores the backup boot sector location. So I checked that value from hda5, it's 6.

# od -t x1 hda5.b
0000000 eb fe 90 4d 53 57 49 4e 34 2e 31 00 02 20 42 00
0000020 02 00 00 00 00 f8 00 00 3f 00 ff 00 7b 3f 43 02
0000040 c5 fe 3a 01 af 13 00 00 00 00 00 00 02 00 00 00
0000060 01 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00
0000100 80 00 29 04 1e 41 6e 4e 4f 20 4e 41 4d 45 20 20
0000120 20 20 46 41 54 33 32 20 20 20 00 00 00 00 00 00
0000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*
0000760 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa
0001000

Then I restored the boot sector from the sector 6 on hda6. I assume hda5 and hda6 are of the same backup boot sector location.

dd if=/dev/hda6 of=hda6-skip6.b bs=512 count=1 skip=6

# file hda6-skip6.b
hda6-skip6.b: x86 boot sector, code offset 0xfe, OEM-ID "MSWIN4.1", sectors/cluster 32, M
edia descriptor 0xf8, heads 255, hidden sectors 58605183, sectors 38764782 (volu
mes > 32 MB) , FAT (32 bit), sectors/FAT 9471, rootdir cluster 348, reserved3 0x
800000, serial number 0x71eb915a, label: " DISK1_VOL3"

Yeah, that's it. I see a big hope.

dd if=hda6-skip6.b of=/dev/hda6

Now, it's recovered. Everything looks ok. mount runs ok, files are still there. It seems just like nothing has had happend! :-)

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!