11

How to run fsck at boot when using Pi 3 and Raspberry Jessie? I have read some tutorial but they differ.

I have run sudo touch /forcefsck but what else I have to do? I know that I should set FSCKFIX=yes but what is the correct file? Some say /lib/init/vars.sh others /etc/default/rcS.

How can I verify that my settings are working? I have no visibility to screen. There is power outages so there is a high risk that file system gets corrupted.

Edit:

I tried two solution mentioned below.

1) By using sudo shutdown -rF now /var/log/boot.log says: [^[[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) By using fsck.mode=force and fsck.repair=yes in /boot/cmdline.txt bootlog says: [^[[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.

Why the log file is totally different in these two cases?

21

I have run sudo touch /forcefsck but what else I have to do?

That's stuff that applies more to wheezy; jessie may (or may not) be backward compatible with it, but you might as well do it the new way:

Add the following to /boot/cmdline.txt:

fsck.mode=force

Make sure that file remains all one line. Parameters should be separated with spaces.

You'll probably notice fsck.repair=yes is already there; these are not the same thing. From man systemd-fsck (these are actually parameters that are passed on by the kernel to init, i.e., systemd):

fsck.mode=

One of "auto", "force", "skip". Controls the mode of operation. The default is "auto", and ensures that file system checks are done when the file system checker deems them necessary. "force" unconditionally results in full file system checks. "skip" skips any file system checks.

fsck.repair=

One of "preen", "yes", "no". Controls the mode of operation. The default is "preen", and will automatically repair problems that can be safely fixed. "yes " will answer yes to all questions by fsck and "no" will answer no to all questions.

  • How this is different compared to sudo shutdown -rF now? Boot.log looks totally different. – JPX Feb 13 '17 at 12:58
3

This what I am using on a Jessie old-stable release, at the end of the line in cmdline.txt: forcefsck

I also have the following in fstab: /dev/mmcblk0p1 /boot vfat defaults,noatime 0 2 /dev/mmcblk0p2 / ext4 defaults,noatime 0 1 Note the 1 and 2 at the end of the line

It checks and repairs the root partition (/dev/mmcblk0p2) on every boot (@JulianKnight not /dev/sda2).

What is described in the original OP still works for Wheezy on RPi: sudo touch /forcefsck

@WillianPaixao after Wheezy the -F option of shutdown is no longer supported

How to force a filesystem check is (mostly) bound to the kernel version, at some point after Debian 8.0 (in 8.2?), it was changed as described in @goldilocks answer.

2

You should also be able to do the following which should work for any Linux not just the Pi (obviously the device will change for different platforms, sda2 should be right for a default Pi SD card):

sudo tune2fs -c 1 /dev/sda2

That should set a check every reboot. You can change the number to whatever you like. Use -i instead of -c if you want time-based checking. See the man page for more info.

1

I use shutdown with -F parameter. [1]

sudo shutdown -rF now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.