You did write down the backup superblocks you were given by ext3 when you created your new filesystem, right?
If you used the defaults or remember what options you used, never fear.
The recover procedure is simple:
First, obtain the size of the damaged filesystem in question. If your system still has df functioning, you can run df and grab the filesystem size that way. The output reports the number of 1K (1,024 bytes) blocks the filesystem is using.
Next, find a working system if the box with the broken filesystem has lost its root filesystem. Now, invoke the magic of dd. For example, my filesystem showed up as using 101,086 blocks. So I used the following command:
dd if=/dev/zero of=/tmp/foo bs=1024 count=101086
Now, we’re nearly finished. Finally, build an ext3 filesystem on your new file.
jasonb@faith:~$ /sbin/mkfs.ext2 /tmp/foo mke2fs 1.32 (09-Nov-2002) /tmp/foo is not a block special device. Proceed anyway? (y,n) y Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 25272 inodes, 101086 blocks 5054 blocks (5.00%) reserved for the super user First data block=1 13 block groups 8192 blocks per group, 8192 fragments per group 1944 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729
(The careful reader will notice I used mkfs.ext2, but the results are the same.)
Look, your missing superblocks are revealed!
Now, to recover, call fsck.ext3 on the damaged system.
/sbin/fsck.ext3 -b 57345 /dev/sda1
Carefully evaluate the prompts and decide if you want to allow fsck to proceed with filesystem repairs. If the backup superblock is also invalid, try another or follow the steps above again and double check your numbers.
But what if you don’t have enough space to create a file as big as your lost partition? If that is the case or the partition is so huge you don’t want to wait that long for dd to complete, there is another option. The superblock locations vary depending on the blocksize used. The ext3 filesystem varies between 1024, 2048, and 4096 bytes depending on the size of the filesystem. Since the locations are neither magic or random, you can create, say, a 500MB partition and force the blocksize to match that of the damaged filesystem.
/sbin/mkfs.ext3 -j -b 4096 /tmp/foo
The presence or absence of a journal does not effect the location of the backup superblocks.
Perhaps I should’ve titled this fishing for superblocks instead.