修复super block(ext4)

数据无价,请谨慎操作。
通常在作磁盘操作之前应该备份磁盘的数据,在作这个操作之前也应该把磁盘上的所有内容备份到另一个磁盘中。就是说如果这个故障盘是20g的话,就需要一个20G的备份空间。备份的命令如下:
#dd if=/dev/baddrive of=/storagearea

注意:首先确定设备文件系统类型
file -s /dev/sdb

[root@dhcp-0-175 ~]# dumpe2fs /dev/sdb1
dumpe2fs 1.39 (29-May-2006)
dumpe2fs: Bad magic number in super-block while trying to open /dev/sdb1
Couldn't find valid filesystem superblock.
[root@dhcp-0-175 ~]# tune2fs -l /dev/sdb1
tune2fs 1.39 (29-May-2006)
tune2fs: Bad magic number in super-block while trying to open /dev/sdb1
Couldn't find valid filesystem superblock.
根本无法从dumpe2fs和tune2fs看到Backup superblock的位置。

查看super block备份 
[root@10-4-1-38 ~]# mke2fs -n /dev/vdb
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3276800 inodes, 13107200 blocks
655360 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
4096000, 7962624, 11239424

上面的super block可以依次尝试修复
[root@dhcp-0-175 ~]# fsck.ext3 -b 98304 /dev/sdb1
e2fsck 1.39 (29-May-2006)
sdb1 was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

sdb1: ***** FILE SYSTEM WAS MODIFIED *****
sdb1: 11/123648 files (9.1% non-contiguous), 8298/246991 blocks

修改完成后:
[root@dhcp-0-175 ~]# dumpe2fs /dev/sdb1
dumpe2fs 1.39 (29-May-2006)
Filesystem volume name: sdb1
Last mounted on:
Filesystem UUID: 0293bd85-b911-43bf-853e-6588b3eaaf39
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal resize_inode dir_index filetype sparse_super large_file
Default mount options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 123648
Block count: 246991
Reserved block count: 12349
Free blocks: 238693
Free inodes: 123637
First block: 0
Block size: 4096
... ...
如果上述方法不行,则可以尝试如下方法,但有风险
man mkfs.ext4可以看到-S参数
-S     Write superblock and group descriptors only.  This is useful if all of the superblock and backup superblocks are  corrupted,  and  a last-ditch  recovery  method  is desired.  It causes mke2fs to reinitialize the superblock and group descriptors, while not touching the inode table and the block and inode bitmaps.  The e2fsck program should be run immediately after this option is used, and  there is  no  guarantee  that  any  data  will be salvageable.  It is critical to specify the correct filesystem blocksize when using this option, or there is no chance of recovery.

[root@dhcp-0-175 ~]# mke2fs -S /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
24480 inodes, 97656 blocks
4882 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
12 block groups
8192 blocks per group, 8192 fragments per group
2040 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@dhcp-0-175 ~]# mount /dev/sdb1 /mnt/
[root@dhcp-0-175 ~]# ls /mnt
foo a b
原文地址:https://www.cnblogs.com/lixuebin/p/10814392.html