Ext4文件系统修复

Ext4文件系统修复 目录 一、 super block................................................................................................................................................. 二、查看...
Ext4文件系统修复
目录
一、super block.................................................................................................................................................
二、查看分区设备信息.....................................................................................................................................
三、查看备份块................................................................................................................................................
四、尝试修复超级块.........................................................................................................................................
1.已知文件系统格式...................................................................................................................................
2.不确定文件系统.......................................................................................................................................
一、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 dumpe2fs1.43.8 (1-Jan-2018) Filesystem volume name:#文件系统的名称 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 Defaultmount 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 mke2fs1.43.8 (1-Jan-2018) /dev/sdb1 contains a ext4file systemlast mounted on /a on Wed Jun1211:03:202019 Proceed anyway? (y,N) y Creating filesystem with2621440 4k blocks and655360 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. 在已知文件系统的情况下可以直接使用:
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 -b32768 /dev/sdb1 e2fsck1.43.8 (1-Jan-2018) /dev/sdb1 was not cleanly unmounted, check forced. Pass1: Checking inodes, blocks, and sizes Pass2: Checking directory structure Pass3: Checking directory connectivity Pass4: Checking reference counts Pass5: Checking group summary information Free blocks count wrongfor group #6 (32254, counted=32253). Fix? yes Free blocks count wrongfor group #42 (32254, counted=32252). Fix? yes Free blocks count wrongfor group #50 (32254, counted=32253). Fix? yes Free blocks count wrongfor group #58 (32254, counted=32253). Fix? yes Free blocks count wrong (2558144, counted=2558139). Fix? yes Free inodes count wrongfor group #0 (8181, counted=8180). Fix? yes Free inodes count wrongfor group #6 (8192, counted=8191). Fix? yes Directories count wrongfor group #6 (0, counted=1). Fix? yes Free inodes count wrongfor group #42 (8192, counted=8189). Fix? yes Directories count wrongfor group #42 (0, counted=1). Fix ('a' enables'yes' to all)? yes Free inodes count wrongfor group #50 (8192, counted=8191). Fix ('a' enables'yes' to all)? yes Directories count wrongfor group #50 (0, counted=1). Fix ('a' enables'yes' to all)? yes Free inodes count wrongfor group #58 (8192, counted=8191). Fix ('a' enables'yes' to all)? yes Directories count wrongfor group #58 (0, counted=1). Fix? yes Free inodes count wrong (655349, counted=655342). Fix? 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 mke2fs1.43.8 (1-Jan-2018) Creating filesystem with2621440 4k blocks and655360 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 creationin super-only mode Writing superblocks and filesystem accounting information:done
重建完成后进行修复:fsck.ext4 -y /dev/sdb1
wyc:~ # fsck.ext4 -y /dev/sdb1 e2fsck1.43.8 (1-Jan-2018) One ormore block group descriptor checksums are invalid. Fix? yes Group descriptor0 checksum is0x20a2, should be0x8d20. FIXED. Group descriptor1 checksum is0x1342, should be0xdec3. FIXED. Group descriptor2 checksum is0x1038, should be0xddb9. FIXED. Group descriptor3 checksum is0xa34e, should be0x6ecf. FIXED. Group descriptor4 checksum is0x1db9, should be0xd038. FIXED. Group descriptor5 checksum is0xa2de, should be0x6f5f. FIXED. Group descriptor6 checksum is0xf83c, should be0x35bd. FIXED. Group descriptor7 checksum is0x4b4a, should be0x86cb. FIXED. Group descriptor8 checksum is0x973c, should be0x5abd. FIXED. Group descriptor9 checksum is0xe044, should be0x2dc5. FIXED. Group descriptor10 checksum is0xe33e, should be0x2ebf. FIXED. Group descriptor11 checksum is0xcf59, should be0x02d8. FIXED. Group descriptor12 checksum is0xeebf, should be0x233e. FIXED. Group descriptor13 checksum is0x9e92, should be0x5313. FIXED. Group descriptor14 checksum is0xe851, should be0x25d0. FIXED. Group descriptor15 checksum is0xc436, should be0x09b7. FIXED. Group descriptor16 checksum is0x516a, should be0x9ceb. FIXED. Group descriptor17 checksum is0xe962, should be0x24e3. FIXED. Group descriptor18 checksum is0x3bc2, should be0xf643. FIXED. Group descriptor19 checksum is0x75a2, should be0xb823. FIXED. Group descriptor20 checksum is0xde81, should be0x1300. FIXED.