![Fsck 在操作系统中发现错误,但不使用 LiveCD](https://linux22.com/image/667451/Fsck%20%E5%9C%A8%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E4%B8%AD%E5%8F%91%E7%8E%B0%E9%94%99%E8%AF%AF%EF%BC%8C%E4%BD%86%E4%B8%8D%E4%BD%BF%E7%94%A8%20LiveCD.png)
在已启动的机器上运行 fsck 会导致根文件系统出现错误。为了修复这个问题,我从 LiveCD 启动 - 但 LiveCD 实例上的 fsck 根本没有发现任何错误。我还尝试运行已启动系统会运行的相同二进制文件 - 结果同样为 0 个错误。
这是怎么回事?如何修复报告的错误?(见下文)
该机器是无头式 Ubuntu 14.04,LiveCD 来自 Ubuntu 14.04 桌面版。
当我跑步时:
fsck -v -n /dev/mapper/lvm-root -f
响应是:
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
Warning! /dev/mapper/lvm-root is mounted.
Warning: skipping journal recovery because doing a read-only filesystem check.
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: -(24598720--24598781) +(42616517--42616542) -(47432723--47432748) +(49925184--49925211) +(49925312--49925373)
Fix? no
Free blocks count wrong for group #750 (22700, counted=22638).
Fix? no
Free blocks count wrong for group #1300 (13150, counted=13176).
Fix? no
Free blocks count wrong for group #1447 (24124, counted=24098).
Fix? no
Free blocks count wrong for group #1523 (32016, counted=32106).
Fix? no
Free blocks count wrong (30301182, counted=30319341).
Fix? no
Inode bitmap differences: -11927698 +11927700
Fix? no
Free inodes count wrong (15762199, counted=15762204).
Fix? no
/dev/mapper/lvm-root: ********** WARNING: Filesystem still has errors **********
130281 inodes used (0.82%, out of 15892480)
1113 non-contiguous files (0.9%)
112 non-contiguous directories (0.1%)
# of inodes with ind/dind/tind blocks: 0/0/0
Extent depth histogram: 121424/640
33268738 blocks used (52.33%, out of 63569920)
0 bad blocks
3 large files
101907 regular files
19700 directories
2 character device files
0 block device files
2 fifos
22 links
8624 symbolic links (8166 fast symbolic links)
32 sockets
------------
130289 files
为了尝试修复此问题,我从 Ubuntu 14.04 LiveCD 启动并运行相同的命令:
root@ubuntu:~# fsck -n -v /dev/mapper/lvm-root -f
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
Warning! /dev/mapper/lvm-root is mounted.
Warning: skipping journal recovery because doing a read-only filesystem check.
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
130281 inodes used (0.82%, out of 15892480)
1114 non-contiguous files (0.9%)
112 non-contiguous directories (0.1%)
# of inodes with ind/dind/tind blocks: 0/0/0
Extent depth histogram: 121429/640
33268738 blocks used (52.33%, out of 63569920)
0 bad blocks
3 large files
101908 regular files
19704 directories
2 character device files
0 block device files
2 fifos
22 links
8625 symbolic links (8167 fast symbolic links)
31 sockets
------------
130294 files
没有错误,我觉得很奇怪。所以我尝试挂载根分区,并手动运行位于 /sbin/fsck 下的 fsck:
root@ubuntu:~# /mnt/sbin/fsck -n -v /dev/mapper/lvm-root -f
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
Warning! /dev/mapper/lvm-root is mounted.
Warning: skipping journal recovery because doing a read-only filesystem check.
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
130281 inodes used (0.82%, out of 15892480)
1114 non-contiguous files (0.9%)
112 non-contiguous directories (0.1%)
# of inodes with ind/dind/tind blocks: 0/0/0
Extent depth histogram: 121429/640
33268738 blocks used (52.33%, out of 63569920)
0 bad blocks
3 large files
101908 regular files
19704 directories
2 character device files
0 block device files
2 fifos
22 links
8625 symbolic links (8167 fast symbolic links)
31 sockets
------------
130294 files
答案1
在已挂载的文件系统上运行 fsck 将显示与此时关闭系统时相同的错误;磁盘上的状态不一致,因为更新已缓冲在内存中,尚未写入磁盘。因此不要这样做!
仅在未挂载的文件系统上运行 fsck。即使在只读挂载的文件系统上,如果 fsck 修复了问题而内核不知道,也会出现问题。