ext4文件系统的superblock修复
操作系统版本
- [ ✔️] CentOS 7.x / RHEL 7.x
问题描述
ext4文件系统的superblock损坏,利用备份块恢复
修复过程
检查文件系统
fsck.ext4 /dev/sdb
-a: 自动修复文件系统,不询问任何问题
-A: 依照/etc/fstab配置文件的内容,检查文件内所列的全部文件系统
-t <文件系统类型>: 指定要检查的文件系统类型
-y: 自动输入yes
获取superblock位置
dumpe2fs /dev/sdb |grep superblock
# dumpe2fs /dev/sdb |grep -i superblock
dumpe2fs 1.42.9 (28-Dec-2013)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit
flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Primary superblock at 0, Group descriptors at 1-63
Backup superblock at 32768, Group descriptors at 32769-32831
Backup superblock at 98304, Group descriptors at 98305-98367
Backup superblock at 163840, Group descriptors at 163841-163903
Backup superblock at 229376, Group descriptors at 229377-229439
Backup superblock at 294912, Group descriptors at 294913-294975
Backup superblock at 819200, Group descriptors at 819201-819263
Backup superblock at 884736, Group descriptors at 884737-884799
Backup superblock at 1605632, Group descriptors at 1605633-1605695
Backup superblock at 2654208, Group descriptors at 2654209-2654271
Backup superblock at 4096000, Group descriptors at 4096001-4096063
Backup superblock at 7962624, Group descriptors at 7962625-7962687
Backup superblock at 11239424, Group descriptors at 11239425-11239487
Backup superblock at 20480000, Group descriptors at 20480001-20480063
Backup superblock at 23887872, Group descriptors at 23887873-23887935
Backup superblock at 71663616, Group descriptors at 71663617-71663679
Backup superblock at 78675968, Group descriptors at 78675969-78676031
Backup superblock at 102400000, Group descriptors at 102400001-102400063
可以看到superblock的备份位置:
Primary是主superblock, Backup superblock at xxxx
修复方法
$ sudo fsck.ext4 -b 98304 /dev/sdb
e2fsck 1.42.9 (28-Dec-2013)
/dev/sdb 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
/dev/sdb: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdb: 11/1310720 files (0.0% non-contiguous), 126322/5242880 blocks
-b 指定superblock的备份块位置, 即dumpe2fs中输出的备份位置,随便选一个都一样
-f 强制执行
另外也可以通过如下方法查看superblock
$ mke2fs -n -t ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
mke2fs: Permission denied while trying to determine filesystem size
[wanglin@unicloudos ~]$ sudo mke2fs -n -t ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
160 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
mke2fs -n参数是模拟执行,不实际生产,和实际分区时的参数是一致的
最后输出Superblock的备份位置number 32768...