blog.lsweb.eu

05 February

How to repair an ext3 filesystem after mkdosfs format

After shrinking a large ext3 partition using gparted to make space for an additional partition, I did not take sufficient care to notice the leading partition I newly created with cfdisk subsequently was denoted as sdc2 instead of sdc1, as one might expect.

Thus woe ensued when I issued a mkdosfs -F 32 /dev/sdc1 command without a closer look at the new partition numbering.

So the interesting question now was, what can be salvaged from an ext3 filesystem with overwritten superblock (as well as a few of the inodes)?

Luckily, the erroneous reformatting was FAT32, not ext3, which would have caused the inode block pointers to be zeroed, to quote the ext3 FAQ:
In order to ensure that ext3 can safely resume an unlink after a crash, it actually zeros out the block pointers in the inode, whereas ext2 just marks these blocks as unused in the block bitmaps and marks the inode as "deleted" and leaves the block pointers alone.

What could be done was this:
  1. Find out the location of the backup superblocks, either using

    • mke2fs -n /dev/sdc1 or
    • testdisk (Advanced>Choose sdc2>Superblock)

  2. Call e2fsck -b 163840 -B 4096 /dev/sdc1 (for a blocksize of 4096 that backup superblock at 163840 should be in the list you produced in the step before)
  3. Check lost+found for what has been be salvaged by e2fsck - not bad at all, without having had to resort to file scrubbing tools like foremost or magicrescue (both available in Ubuntu)
  4. At actual loss were the inodes directly overwritten by the two FATs - sort of a black eye I came away with, really...
posted at 20:42:44 on 02/05/09 by lss - Category: SysAdmin

Comments

No comments yet

Add Comments

You must be logged in as a member to add comment to this blog