ext3 filesystem bad superblock recovery

原贴:http://edseek.com/archives/2004/02/25/ext3-filesystem-bad-superblock-recovery/

Posted in Quick Guides at 10:06 pm by jasonb

You did write down the backup superblocks you were given by ext3 when you created your new filesystem, right?

No? Oops.

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值