Ext4文件系统修复
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Ext4⽂件系统修复
Ext4⽂件系统修复
⽬录
⼀、super block
硬盘分区开头、开头的第⼀个byte是byte0,从byte1024开始往后的⼀部分数据。
由于block size最⼩时1024bytes,所以superblock在block1中(此时block的⼤⼩正好是1024bytes),也可能是在block 0中。
超级块保存了⽂件系统设定的⽂件块⼤⼩、操作函数、inode链表等重要信息。
⼆、查看分区设备信息
⼀般情况下我们是能够通过⼀些命令查看到分区的⼀些信息,如果super block有损坏,则该分区设备则不能够正常使⽤,还有可能不能通过命令查看设备分区的信息。
命令:
dumpe2fs /dev/sdb1
tune2fs -h /dev/sdb1
linux-iu82:/ # dumpe2fs -h /dev/sdb1
dumpe2fs 1.43.8 (1-Jan-2018)
Filesystem volume name: <none> #⽂件系统的名称
Last mounted on: /a #是否挂载及挂载点
Filesystem UUID: cd22c2f7-d461-4cbe-973b-16d0b584a7b2
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean #正常,异常:clean with errors或not clean whith errors
Errors behavior: Continue
Filesystem OS type: Linux #⽂件系统类型
Inode count: 655360 #inode总的个数
Block count: 2621440 #block总的个数
Reserved block count: 131072
Free blocks: 2554687 #空闲的block个数
Free inodes: 655344 #空闲的iNode个数
First block: 0 #第⼀个超级块编号=0
Block size: 4096 #块⼤⼩,这⾥是4k
Fragment size: 4096 #分块⼤⼩
Group descriptor size: 64
Reserved GDT blocks: 1024 #保留的GDT块⼤⼩
Blocks per group: 32768 #每个块组的block的个数
Fragments per group: 32768
Inodes per group: 8192 #每个块组的inode个数
Inode blocks per group: 512
…………
三、查看备份块
mkfs.ext4 -n /dev/sdb1(查看备份块时需要将分区卸载)
linux-iu82:/ # mkfs.ext4 -n /dev/sdb1
mke2fs 1.43.8 (1-Jan-2018)
/dev/sdb1 contains a ext4 file system
last mounted on /a on Wed Jun 1211:03:202019
Proceed anyway? (y,N) y
Creating filesystem with 2621440 4k blocks and 655360 inodes #块⼤⼩4k
Filesystem UUID: 9e8e093e-183d-42ed-9e1f-b414673add53
Superblock backups stored on blocks: #查看备份超级块
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
四、尝试修复超级块
1. 1. 已知⽂件系统格式
1.1. 在已知⽂件系统的情况下可以直接使⽤:
mkfs.type -n /dev/sdb1
进⾏查看分区的备份块。
(注意查看备份块的时候需要将分区卸载)
1.2. 尝试挂载备份块
当⽂件系统出现损坏时,分区是挂载不上去的,这个时候尝试对分区备份块进⾏挂载,如果该备份超级块块可以被挂载上,并且上⾯数据没有问题,那么就可以使⽤该备份超级块进⾏修复
mount -t ext4 -o sb=131072 /dev/sdb1 /a #以32768为例,block的⼤⼩是4k,⽽mount的sb参数的块⼤⼩是1k,所以挂载时需要进⾏单位转换,转换成1k则是32768*4=131072。
若挂载成功则可以使⽤该备份块进⾏修复
1.3. 尝试使⽤备份块修复⽂件系统
尝试修复前⼀定要先卸载该设备,否则会导致部分数据丢失
且修复过程中需要确认的信息要⾃⼰观察分析,避免丢失数据
wyc:/ # fsck.ext4 -b 32768 /dev/sdb1
e2fsck 1.43.8 (1-Jan-2018)
/dev/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
Free blocks count wrong for group #6 (32254, counted=32253).
Fix<y>? yes
Free blocks count wrong for group #42 (32254, counted=32252).
Fix<y>? yes
Free blocks count wrong for group #50 (32254, counted=32253).
Fix<y>? yes
Free blocks count wrong for group #58 (32254, counted=32253).
Fix<y>? yes
Free blocks count wrong (2558144, counted=2558139).
Fix<y>? yes
Free inodes count wrong for group #0 (8181, counted=8180).
Fix<y>? yes
Free inodes count wrong for group #6 (8192, counted=8191).
Fix<y>? yes
Directories count wrong for group #6 (0, counted=1).
Fix<y>? yes
Free inodes count wrong for group #42 (8192, counted=8189).
Fix<y>? yes
Directories count wrong for group #42 (0, counted=1).
Fix ('a' enables 'yes' to all) <y>? yes
Free inodes count wrong for group #50 (8192, counted=8191).
Fix ('a' enables 'yes' to all) <y>? yes
Directories count wrong for group #50 (0, counted=1).
Fix ('a' enables 'yes' to all) <y>? yes
Free inodes count wrong for group #58 (8192, counted=8191).
Fix ('a' enables 'yes' to all) <y>? yes
Directories count wrong for group #58 (0, counted=1).
Fix<y>? yes
Free inodes count wrong (655349, counted=655342).
Fix<y>? yes
/dev/sdb1: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdb1: 18/655360 files (0.0% non-contiguous), 63301/2621440 blocks
1.4. 全部super block损坏修复(数据丢失风险⼤)
在所有superblock损坏后,只能通过重建进⾏修复
命令: mkfs.ext4 -S /dev/sdb1
wyc:~ # mkfs.ext4 -S /dev/sdb1
mke2fs 1.43.8 (1-Jan-2018)
Creating filesystem with 2621440 4k blocks and 655360 inodes
Filesystem UUID: 5c9e2db1-5cf6-4353-b051-7eefef7c6018
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
/dev/sdb1 may be further corrupted by superblock rewrite
Proceed anyway? (y,N) y
Skipping journal creation in super-only mode
Writing superblocks and filesystem accounting information: done
重建完成后进⾏修复:fsck.ext4 -y /dev/sdb1
wyc:~ # fsck.ext4 -y /dev/sdb1
e2fsck 1.43.8 (1-Jan-2018)
One or more block group descriptor checksums are invalid. Fix<y>? yes
Group descriptor 0 checksum is 0x20a2, should be 0x8d20. FIXED.
Group descriptor 1 checksum is 0x1342, should be 0xdec3. FIXED.
Group descriptor 2 checksum is 0x1038, should be 0xddb9. FIXED.
Group descriptor 3 checksum is 0xa34e, should be 0x6ecf. FIXED.
Group descriptor 4 checksum is 0x1db9, should be 0xd038. FIXED.
Group descriptor 5 checksum is 0xa2de, should be 0x6f5f. FIXED.
Group descriptor 6 checksum is 0xf83c, should be 0x35bd. FIXED.
Group descriptor 7 checksum is 0x4b4a, should be 0x86cb. FIXED.
Group descriptor 8 checksum is 0x973c, should be 0x5abd. FIXED.
Group descriptor 9 checksum is 0xe044, should be 0x2dc5. FIXED.
Group descriptor 10 checksum is 0xe33e, should be 0x2ebf. FIXED.
Group descriptor 11 checksum is 0xcf59, should be 0x02d8. FIXED.
Group descriptor 12 checksum is 0xeebf, should be 0x233e. FIXED.
Group descriptor 13 checksum is 0x9e92, should be 0x5313. FIXED.
Group descriptor 14 checksum is 0xe851, should be 0x25d0. FIXED.
Group descriptor 15 checksum is 0xc436, should be 0x09b7. FIXED.
Group descriptor 16 checksum is 0x516a, should be 0x9ceb. FIXED.
Group descriptor 17 checksum is 0xe962, should be 0x24e3. FIXED.
Group descriptor 18 checksum is 0x3bc2, should be 0xf643. FIXED.
Group descriptor 19 checksum is 0x75a2, should be 0xb823. FIXED.
Group descriptor 20 checksum is 0xde81, should be 0x1300. FIXED.
修复完成直接进⾏挂载即可。
1. 2. 不确定⽂件系统
在不知道⽂件系统的情况下,可以使⽤fsck -r /dev/sdb1 命令进⾏修复(注意提⽰内容),这种修复可能会导致⽂件正常恢复,但是⽂件系统发⽣改变,⽐如原本是ext4,修复后变成了ext3或ext2,需要⼿动升级⼀下。
(⼀般不建议此⽅法)
命令:Fsck -r /dev/sdb1
wyc:~ # fsck -r /dev/sdb1
fsck from util-linux 2.29.2
e2fsck 1.43.8 (1-Jan-2018)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
/dev/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
Block bitmap differences: -(2138112--2162687)
Fix? yes
Free blocks count wrong for group #16 (24544, counted=24543).
Fix? yes
Free blocks count wrong for group #48 (24544, counted=24542).
Fix? yes
Free blocks count wrong for group #64 (24544, counted=24543).
Fix? yes
Free blocks count wrong (2554687, counted=2554683).
Fix? yes
Free inodes count wrong for group #0 (8181, counted=8177).
Fix? yes
Free inodes count wrong for group #16 (8192, counted=8191).
Fix? yes
Directories count wrong for group #16 (0, counted=1).
Fix? yes
Free inodes count wrong for group #48 (8192, counted=8190).
Fix? yes
修复后正常挂载即可。