Linux 分区 Super block 损坏,可以尝试手工修复,本文对此进行简要说明。
注意:操作有风险!操作前请务必先手工创建快照,防止数据丢失!
1、查找 super block 位置
- $ dumpe2fs /dev/xvdb1 | grep --before-context=1 superblock
- dumpe2fs 1.41.12 (17-May-2010)
- Group 0: (Blocks 0-32767)
- Primary superblock at 0, Group descriptors at 1-1
- --
- Group 1: (Blocks 32768-65535)
- Backup superblock at 32768, Group descriptors at 32769-32769
- --
- Group 3: (Blocks 98304-131071)
- Backup superblock at 98304, Group descriptors at 98305-98305
- --
- Group 5: (Blocks 163840-196607)
- Backup superblock at 163840, Group descriptors at 163841-163841
- --
- Group 7: (Blocks 229376-262143)
- Backup superblock at 229376, Group descriptors at 229377-229377
- --
- Group 9: (Blocks 294912-327679)
- Backup superblock at 294912, Group descriptors at 294913-294913
- --
- Group 25: (Blocks 819200-851967)
- Backup superblock at 819200, Group descriptors at 819201-819201
- --
- Group 27: (Blocks 884736-917503)
- Backup superblock at 884736, Group descriptors at 884737-884737
- 从上面操作可以看出,在第 1、3、5、7、9、25、27 这几个 Block Group 上存放有 superblock 备份。所以 super block 放置在如下这些块上(mke2fs -n /dev/xvdb1 可以更直观的显示出来):
- 32768, 98304, 163840, 229376, 294912, 819200, 884736
2、破坏 super block 测试
- $ dd if=/dev/zero of=/dev/xvdb1 bs=1 count=1024 seek=1024
- 1024+0 records in
- 1024+0 records out
- 1024 bytes (1.0 kB) copied, 0.00852143 s, 120 kB/s
- 这时候我们根本无法从dumpe2fs和tune2fs看到Backup superblock的位置
- $ dumpe2fs /dev/xvdb1 | grep --before-context=1 superblock
- dumpe2fs 1.41.12 (17-May-2010)
- dumpe2fs: Bad magic number in super-block while trying to open /dev/xvdb1
- Couldn't find valid filesystem superblock.
3、mke2fs 方式修复示例
- $ mke2fs -S /dev/xvdb1
- 可以看到已经修复
- $ dumpe2fs /dev/xvdb1 | grep --before-context=1 superblock
- dumpe2fs 1.41.12 (17-May-2010)
- Group 0: (Blocks 0-32767)
- Primary superblock at 0, Group descriptors at 1-1
- --
- Group 1: (Blocks 32768-65535)
- Backup superblock at 32768, Group descriptors at 32769-32769
- --
- Group 3: (Blocks 98304-131071)
- Backup superblock at 98304, Group descriptors at 98305-98305
- --
- Group 5: (Blocks 163840-196607)
- Backup superblock at 163840, Group descriptors at 163841-163841
- --
- Group 7: (Blocks 229376-262143)
- Backup superblock at 229376, Group descriptors at 229377-229377
- --
- Group 9: (Blocks 294912-327679)
- Backup superblock at 294912, Group descriptors at 294913-294913
- --
- Group 25: (Blocks 819200-851967)
- Backup superblock at 819200, Group descriptors at 819201-819201
- --
- Group 27: (Blocks 884736-917503)
- Backup superblock at 884736, Group descriptors at 884737-884737
4、e2fsck 方式修复示例
- $ dd if=/dev/zero of=/dev/xvdb1 bs=1 count=1024 seek=1024
- $ e2fsck /dev/xvdb1
- 或者
- $ e2fsck -b 884736 /dev/xvdb1
- # 放置备份的super block的块