其他
Linux硬盘与文件系统(8)
在实际生产环境中,各种问题都有可能发生,比如意料之外的宕机可能会导致文件系统的错乱。如果文件系统发生错乱,那该如何是好?当然是挽救,下面我们以xfs和ext4的挽救做讲解。
xfs_repair
[root@studyclub ~]# xfs_repair /dev/sdb1
Phase 1 - find and verify superblock...
Phase 2 - using internal log
- zero log...
- scan filesystem freespace and inode maps...
- found root inode chunk
Phase 3 - for each AG...
- scan and clear agi unlinked lists...
- process known inodes and perform inode discovery...
- agno = 0
- agno = 1
- agno = 2
- agno = 3
- process newly discovered inodes...
Phase 4 - check for duplicate blocks...
- setting up duplicate extent list...
- check for inodes claiming duplicate blocks...
- agno = 0
- agno = 1
- agno = 2
- agno = 3
Phase 5 - rebuild AG headers and trees...
- reset superblock...
Phase 6 - check inode connectivity...
- resetting contents of realtime bitmap and summary inodes
- traversing filesystem ...
- traversal finished ...
- moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
done
# 范例2:检查原来已有的/dev/sda3分区的文件系统
[root@studyclub ~]# xfs_repair /dev/sda3
xfs_repair: /dev/sda3 contains a mounted filesystem
xfs_repair: /dev/sda3 contains a mounted and writable filesystem
fatal error -- couldn't initialize XFS library
fsck.ext4
选项和参数:
-p 在文件系统修复过程中,如果有需要和用户互动的操作,系统会自动回复yes来继续修复
-f 强制进行细节检查
-D 针对文件系统下的目录进行优化配置
-b 后面接superblock的位置(基本用不上,了解即可)。如果你的superblock因故损坏,通过这个参数可以利用文件系统内备份的superblock来尝试修复。
[root@studyclub ~]# fsck.ext4 /dev/sdb2
e2fsck 1.42.9 (28-Dec-2013)
/dev/sdb2: clean, 11/131072 files, 26156/524288 blocks
# 强制细节检查
[root@studyclub ~]# fsck.ext4 -f /dev/sdb2
e2fsck 1.42.9 (28-Dec-2013)
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/sdb2: 11/131072 files (0.0% non-contiguous), 26156/524288 blocks
注意:无论是xfs_repair还是fsck.ext4都需要在检查之前保证设备是卸载状态
课后练习:
在你的虚拟机上新加1块硬盘50GB的硬盘,然后:
把这块盘分四个分区,每块盘的分区大小分别为:
10G,10G,10G,20G
把第一个分区格式化为xfs,block大小采用默认值
把第二个分区格式化为xfs,block大小这是为2k
查看以上两个分区的信息,需要包含:
UUID、文件系统类型、分区label
把第三个分区格式化为ext4,并查看该分区的信息,需要包含:
UUID、文件系统类型、分区label
检查第一个分区的文件系统健康情况(仅做检查,不做修复)
022 - Linux硬盘与文件系统(7)
微信号|bjdream-1
Cloud研习社 ·