Raspberry Pi 3和Raspbian Jessie-如何在启动时运行fsck?


13

使用Pi 3和Raspberry Jessie时如何在启动时运行fsck?我已经阅读了一些教程,但是它们有所不同。

我已经跑步了,sudo touch /forcefsck但是我还要做些什么?我知道我应该设置FSCKFIX = yes,但是正确的文件是什么?有人说/lib/init/vars.sh别人/etc/default/rcS

如何验证我的设置正常工作?我看不到屏幕。断电,因此文件系统损坏的风险很高。

编辑:

我尝试了下面提到的两种解决方案。

1)通过使用sudo shutdown -rF now/var/log/boot.log说: [^[[32m OK ^[[0m] Started Load/Save Random Seed. [^[[32m OK ^[[0m] Started Show Plymouth Boot Screen. [ 3.679250] systemd-fsck[219]: fsck.fat 3.0.27 (2014-11-12) [ 3.681320] systemd-fsck[219]: /dev/mmcblk0p1: 124 files, 2666/8057 clusters [^[[32m OK ^[[0m] Started File System Check on /dev/mmcblk0p1. Mounting /boot... [^[[32m OK ^[[0m] Reached target Paths. [^[[32m OK ^[[0m] Created slice system-systemd\x2drfkill.slice. Starting Load/Save RF Kill Switch Status of rfkill0... [^[[32m OK ^[[0m] Started Load/Save RF Kill Switch Status of rfkill0. [^[[32m OK ^[[0m] Created slice system-ifup.slice. [^[[32m OK ^[[0m] Mounted /boot. [^[[32m OK ^[[0m] Reached target Local File Systems. Starting Tell Plymouth To Write Out Runtime Data... Starting Create Volatile Files and Directories... Starting LSB: Raise network interfaces.... [^[[32m OK ^[[0m] Reached target Remote File Systems. Starting Trigger Flushing of Journal to Persistent Storage... Starting LSB: Prepare console... Starting LSB: Switch to ondemand cpu governor (unless shift key is pressed)... [^[[32m OK ^[[0m] Started Tell Plymouth To Write Out Runtime Data.

2)通过使用fsck.mode=forcefsck.repair=yes/boot/cmdline.txtbootlog中说: [^[[32m OK ^[[0m] Started Show Plymouth Boot Screen. [^[[32m OK ^[[0m] Reached target Paths. [^[[32m OK ^[[0m] Created slice system-systemd\x2drfkill.slice. [^[[32m OK ^[[0m] Created slice system-ifup.slice. [ 5.749367] systemd-fsck[112]: Pass 2: Checking directory structure [ 8.673500] systemd-fsck[112]: Pass 3: Checking directory connectivity [ 8.683831] systemd-fsck[112]: Pass 4: Checking reference counts [ 9.318835] systemd-fsck[112]: Pass 5: Checking group summary information [ 9.518754] systemd-fsck[112]: /dev/mmcblk0p2: 131321/956160 files (0.2% non-contiguous$ [^[[32m OK ^[[0m] Started File System Check on Root Device. Starting File System Check on /dev/mmcblk0p1... Starting Remount Root and Kernel File Systems... [^[[32m OK ^[[0m] Started Remount Root and Kernel File Systems. Starting Load/Save RF Kill Switch Status of rfkill0... Starting Load/Save Random Seed... [^[[32m OK ^[[0m] Reached target Local File Systems (Pre). [ 9.639259] systemd-fsck[239]: fsck.fat 3.0.27 (2014-11-12) [^[[32m OK ^[[0m] Started Load/Save RF Kill Switch Status of rfkill0. [ 9.644216] systemd-fsck[239]: /dev/mmcblk0p1: 124 files, 2666/8057 clusters [^[[32m OK ^[[0m] Started File System Check on /dev/mmcblk0p1. [^[[32m OK ^[[0m] Started Load/Save Random Seed. Mounting /boot... [^[[32m OK ^[[0m] Mounted /boot.

为什么在这两种情况下日志文件完全不同?

Answers:


23

我已经运行了sudo touch / forcefsck,但是我还需要做什么?

这些东西更适用于喘息;jessie可能(或可能不)向后兼容,但您也可以采用新方法:

将以下内容添加到/boot/cmdline.txt

fsck.mode=force

确保该文件保持全行。 参数应以空格分隔。

您可能会注意到fsck.repair=yes已经存在;这些不是一回事。From man systemd-fsck(实际上是内核传递给init的参数,即systemd):

fsck.mode =

“自动”,“力”,“跳过”之一。控制操作模式。默认值为“自动”,并确保在文件系统检查器认为必要时对文件系统进行检查。“强制”无条件导致完整文件系统检查。“跳过”跳过所有文件系统检查。

fsck.repair =

“修饰”,“是”,“否”之一。控制操作模式。默认值为“ preen”,它将自动修复可以安全修复的问题。fsck对所有问题回答“是”,对所有问题回答“否”。


与之相比sudo shutdown -rF now有何不同?Boot.log看起来完全不同。
JPX

3

这是我在Jessie旧稳定版中使用的内容,在以下行的末尾cmdline.txtforcefsck

我在以下内容中也有以下内容fstab /dev/mmcblk0p1 /boot vfat defaults,noatime 0 2 /dev/mmcblk0p2 / ext4 defaults,noatime 0 1 请注意12在行末

它会在每次引导时检查并修复根分区(/ dev / mmcblk0p2)(@ JulianKnight而不是/ dev / sda2)。

原始OP中描述的内容仍适用于RPi上的Wheezy: sudo touch /forcefsck

@WillianPaixao喘息后-F的选项shutdown不再支持

如何强制文件系统检查(主要)绑定到内核版本,在Debian 8.0(在8.2中)之后的某个时候,它已按照@goldilocks答案中的描述进行了更改。


2

您还应该能够执行以下操作,该操作不仅适用于Pi,而且还适用于任何Linux(显然,该设备将针对不同的平台进行更改,sda2应该适用于默认的Pi SD卡):

sudo tune2fs -c 1 /dev/sda2

那应该在每次重启时进行一次检查。您可以将号码更改为任意号码。如果要基于时间的检查,请使用-i而不是-c。有关更多信息,请参见手册页。


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.