How to force fsck at every boot in Linux
- In
/etc/init.d/checkfs.sh
is the lineif [ -f /forcefsck ] || grep -s -w -i "forcefsck" /proc/cmdline
, so providingforcefsck
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 toyes
in the following /etc/default/rcS entry, after the edit it should look like:
1 2 |
# automatically repair filesystems with inconsistencies during boot FSCKFIX=yes</code><code> |
- One option (forcefsck or FSCKFIX) does not imply the other.
- 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)
1 2 3 4 5 6 7 8 9 10 |
# sudo tune2fs -c 1 /dev/sdX sudo tune2fs -c 1 /dev/sda1 sudo tune2fs -c 1 /dev/sda2 sudo tune2fs -c 1 /dev/sda3 sudo tune2fs -c 1 /dev/sda4 sudo tune2fs -c 1 /dev/sda5 sudo tune2fs -c 1 /dev/sda6 sudo tune2fs -c 1 /dev/sda7 sudo tune2fs -c 1 /dev/sda8 sudo tune2fs -c 1 /dev/sdb1 |