How to force fsck at every boot - all (relevant) filesystems?

In /etc/init.d/checkfs.sh is the line if [ -f /forcefsck ] || grep -s -w -i "forcefsck" /proc/cmdline, so providing forcefsck on the kernel command line or generating a /forcefsck file on shutdown should cause an fsck on the next reboot.

To prevent manual fsck runs, ask fsck to try to automatically fix errors with the -y option by uncommenting and changing no to yes in the following /etc/default/rcS entry, after the edit it should look like:

# automatically repair filesystems with inconsistencies during boot
FSCKFIX=yes

One option (forcefsck or FSCKFIX) does not imply the other.


I am editing my answer:

The command is:

sudo tune2fs -c 1 /dev/sdX

according to manpages -c argument for tune2fs counts number of instances of mounts for a partition. Hence, 1 forces to check the fs after every mounting instance.

(http://man7.org/linux/man-pages/man8/tune2fs.8.html)


Add the fsck.mode=force Kernel parameter on your bootloader. Append this option to the GRUB_CMDLINE_LINUX_DEFAULT= variable inside /etc/default/grub. As root, generate a new grub configuration file:

[root@host]# grub-mkconfig -o /boot/grub/grub.cfg

This parameter have the same effect as creating the forcefsck file inside the root of the mount point.

The solution of using the checkfs.sh script will better fit on Debian, but should not work on other distros

Tags:

Debian

Fsck