0
点赞
收藏
分享

微信扫一扫

Linux文件系统检测和修复

fsck

fsck,全称File System Consistency Check,主要用于检查和修复Linux文件系统的不一致和错误。该工具用于解决潜在的文件系统问题。fsck可以为你提供检查和修复一切文件系统中的问题的功能,包括一些潜在的磁盘错误等。

文件系统故障常发生于死机或者非正常关机之后,挂载为文件系统标记为“no clean”

注意:一定不要在挂载状态下执行下面命令修复

fsck [options] -- [fs-options] [<filesystem> ...]

#常用选项

-a #自动修复

-r #交互式修复错误

范例:

[root@ubuntu2204 ~]# fsck.ext4 /dev/sdc1 
e2fsck 1.46.5 (30-Dec-2021)
/dev/sdc1: clean, 11/131072 files, 26156/524288 blocks
[root@ubuntu2204 ~]# fsck -t ext4 /dev/sdc1 
fsck from util-linux 2.37.2
e2fsck 1.46.5 (30-Dec-2021)
/dev/sdc1: clean, 11/131072 files, 26156/524288 blocks

e2fsck

xfs_repair [options] device
#常用选项
-f #修复文件,而设备
-n #只检查
-d #允许修复只读的挂载设备,在单用户下修复 / 时使用,然后立即reboot

xfs_repair

xfs文件系统专用检测修复工具

xfs_repair [options] device

#常用选项
-f #修复文件,而设备
-n #只检查
-d #允许修复只读的挂载设备,在单用户下修复 / 时使用,然
后立即reboot

范例:修改破坏的ext文件系统

[root@ubuntu2204 ~]# mount /dev/sdc1 /mnt
[root@ubuntu2204 ~]# cp /etc/fstab /mnt/f1
[root@ubuntu2204 ~]# cp /etc/fstab /mnt/f2
[root@ubuntu2204 ~]# ls /mnt/
f1 f2 lost+found
[root@ubuntu2204 ~]# dd if=/dev/zero of=/dev/sdc1 bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00302592 s, 347 MB/s
[root@ubuntu2204 ~]# ls /mnt/
[root@ubuntu2204 ~]# tune2fs -l /dev/sdc1
tune2fs 1.46.5 (30-Dec-2021)
tune2fs: Bad magic number in super-block while trying to open /dev/sdc1
[root@ubuntu2204 ~]# df
Filesystem                                   1K-blocks                 Used 
Available Use% Mounted on
tmpfs                                           198824                 1340   
197484   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv            101590008              6261024
90122356   7% /
tmpfs                                           994116                    0   
994116   0% /dev/shm
tmpfs                                             5120                    0     
5120   0% /run/lock
/dev/sda2                                      1992552               255260   
1616052  14% /boot
tmpfs                                           198820                    4   
198816   1% /run/user/0
/dev/sdc1                         73786976294838101864 73786976294836109344   
1976136 100% /mnt
[root@ubuntu2204 ~]# umount /mnt
[root@ubuntu2204 ~]# e2fsck /dev/sdc1 
e2fsck 1.46.5 (30-Dec-2021)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
Superblock needs_recovery flag is clear, but journal has data.
Recovery flag not set in backup superblock, so running journal anyway.
/dev/sdc1: recovering journal
Resize inode not valid. Recreate<y>? yes
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:  +(98304--98560) +(163840--164096) +(229376--229632) +
(294912--295168)
Fix<y>? yes
Free blocks count wrong for group #0 (24280, counted=24281).
Fix<y>? yes
Free blocks count wrong for group #1 (32511, counted=32509).
Fix<y>? yes
Free blocks count wrong (498131, counted=498130).
Fix<y>? yes
Free inodes count wrong for group #0 (8181, counted=8179).
Fix<y>? yes
Free inodes count wrong (131061, counted=131059).
Fix<y>? yes
Padding at end of inode bitmap is not set. Fix<y>? yes
/dev/sdc1: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdc1: 13/131072 files (0.0% non-contiguous), 26158/524288 blocks
[root@ubuntu2204 ~]# tune2fs -l /dev/sdc1 
tune2fs 1.46.5 (30-Dec-2021)
Filesystem volume name:   <none>
Last mounted on:         <not available>
Filesystem UUID:         e55d9611-63c5-43dd-a6b3-fe6409778834
Filesystem magic number: 0xEF53
Filesystem revision #:   1 (dynamic)
[root@ubuntu2204 ~]# mount /dev/sdc1 /mnt 
[root@ubuntu2204 ~]# ls /mnt/
f1 f2 lost+found
[root@ubuntu2204 ~]# cat /mnt/f1
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type> <options>       <dump> <pass>
# / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation
/dev/disk/by-id/dm-uuid-LVM-
2DfhG2JAeOckxicJorCIykZWj5F57OAw1wUxIh2DKVkhusX3fhgEVlJJIPV3tnGn / ext4 defaults 
0 1
# /boot was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/195992f6-95be-4629-b331-8fb09cf99819 /boot ext4 defaults 0 1
/swap.img none swap sw 0 0

写在最后

Linux文件系统修复同样适用于救援模式,笔者曾负责某国企混合云主机运维,经历混合云分布式存储故障致云主机文件系统损坏,无法正常启动系统,可在救援模式进行文件系统修复。推荐参考:centos进入救援模式并修复文件系统(7、8)_怎么通过挂载的镜像文件修复centos-CSDN博客



举报

相关推荐

0 条评论