我的 Raspberry Pi 在 /var/log/syslog 中抱怨“内核:[ 19.931374] EXT4-fs (sda2):警告:已达到检查时间,建议运行 e2fsck”。因此,fsck 应该在启动时运行,但实际上并没有运行。
操作系统:Linux blueberry 5.10.63-v7+(“Raspbian GNU/Linux 10 (buster)”)
根据该论坛和其他论坛上的各种建议,我检查了以下内容:
- 检查时间确实已过期:
$ sudo tune2fs -l /dev/sda2 | grep 'Next check after'
Next check after: Tue Nov 23 13:22:15 2021
- /boot/cmdline 包括 fsck.mode=force 和 fsck.repair=yes:
$ cat /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=2ac02a4b-399a-4bae-88a5-f63f1f743ed9 rootfstype=ext4 elevator=deadline fsck.mode=force fsck.repair=yes ipv6.disable=1 rootwait
- fstab 中的传递参数不为 0
$ ls -l /dev/disk/by-partuuid/2ac02a4b-399a-4bae-88a5-f63f1f743ed9
lrwxrwxrwx 1 root root 10 Nov 26 12:35 /dev/disk/by-partuuid/2ac02a4b-399a-4bae-88a5-f63f1f743ed9 -> ../../sda2
$ grep '2ac02a4b-399a-4bae-88a5-f63f1f743ed9' /etc/fstab
PARTUUID=2ac02a4b-399a-4bae-88a5-f63f1f743ed9 / etc4 defaults 0 1
- 两个 conf 文件中均未设置“broken_system_clock”(一个不存在)
$ grep 'broken' /etc/mke2fs.conf
$ ls /etc/e2fsck.conf
ls: cannot access '/etc/e2fsck.conf': No such file or directory
我还应该调整什么才能在启动时运行 fsck 来检查根分区?
################################## 更新:
使用基于计数的 fsck 时也存在同样的问题:超出了最大挂载计数,但 fsck 不会在启动时运行。所以这与已发布的系统时钟错误无关?
此外,systemd-fsck-root.service 似乎从未运行过(在另一个 RPi 上,此服务的状态报告为“Active:active(exited)”,这与具有 RemainAfterExit 的一次性服务预期一致):
$ sudo systemctl status systemd-fsck-root.service
Warning: The unit file, source configuration file or drop-ins of systemd-fsck-root.service changed on disk. Run 'systemctl daemon-reload' to reload units.
● systemd-fsck-root.service - File System Check on Root Device
Loaded: loaded (/lib/systemd/system/systemd-fsck-root.service; static; vendor preset: enabled)
Drop-In: /etc/systemd/system/systemd-fsck-root.service.d
└─override.conf
Active: inactive (dead)
Docs: man:systemd-fsck-root.service(8)
这个警告很令人惊讶,因为自上次重启以来没有任何变化。这可能是一个提示,出了什么问题? 服务文件的内容:
$ sudo systemctl daemon-reload
pi@blueberry ~ $ sudo systemctl cat systemd-fsck-root.service
# /lib/systemd/system/systemd-fsck-root.service
# SPDX-License-Identifier: LGPL-2.1+
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=File System Check on Root Device
Documentation=man:systemd-fsck-root.service(8)
DefaultDependencies=no
Conflicts=shutdown.target
Before=local-fs.target shutdown.target
Wants=systemd-fsckd.socket
After=systemd-fsckd.socket
ConditionPathIsReadWrite=!/
ConditionPathExists=!/run/initramfs/fsck-root
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/lib/systemd/systemd-fsck
TimeoutSec=0
建议在启动参数中添加“ro”(见评论):我知道 sda2(根分区)最初安装为“ro”,这是默认设置。请参阅 dmesg 输出(已缩短)。尽管如此,我还是尝试将“ro”添加到 /boot/cmdline.txt;fsck 仍未在根分区上运行,并且 systemd-fsck-root.service 的状态仍为“不活动(已停止)”。
$ dmesg
...
[ 8.859189] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 9.743724] sda: sda1 sda2
[ 9.756744] sd 0:0:0:0: [sda] Attached SCSI disk
[ 10.860996] sdb: sdb1 sdb2
[ 10.873495] sd 1:0:0:0: [sdb] Attached SCSI disk
[ 11.041224] EXT4-fs (sda2): mounted filesystem with ordered data mode. Opts: (null)
[ 11.054685] VFS: Mounted root (ext4 filesystem) readonly on device 8:2.
...
[ 20.406869] systemd[1]: Listening on fsck to fsckd communication Socket.
[ 20.427245] systemd[1]: Listening on udev Kernel Socket.
[ 20.446837] systemd[1]: Listening on Journal Audit Socket.
[ 20.465100] systemd[1]: Reached target Swap.
[ 21.008905] i2c /dev entries driver
[ 21.725644] EXT4-fs (sda2): warning: maximal mount count reached, running e2fsck is recommended
[ 21.783533] EXT4-fs (sda2): re-mounted. Opts: (null)
...
答案1
解决方法(避免拔掉埋在柜子后面的硬盘)
我复制了整个根分区,这样我现在可以从两个分区中的任意一个启动,并 fsck 未使用的分区。详细信息:
- 在同一硬盘上使用 ext4 文件系统创建一个新分区
- 挂载新的文件系统
- rsync -a -X -A -H -x --noatime -u --人类可读 /
- 修改 /boot/cmdline.txt 和 /etc/fstab 以引用新分区而不是当前根分区
- 重启
- 手动 fsck 前一个根分区(现在未使用且未挂载)
- 对 /boot/cmdline.txt 和 /etc/fstab 进行逆转更改
- 重启