Automatically force fsck -fy when encountering "UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY."

Solution 1:

Let me preface this with a disclaimer that if you have regular issues with unclean filesystems, even though you shutdown your system cleanly, you have grave underlying problems and its possible fsck can do more harm than good !

AFAIK there is no mechanism for an automatic fsck only if inconsistencies are found.

However, you do an fsck at every boot with some kernel parameters.

sudo nano /etc/default/grub

find the line that says

GRUB_CMDLINE_LINUX_DEFAULT

and add

fsck.mode=force  fsck.repair=yes

to the existing things there.

yes here should do the same as your FSCKFIX=yes in /etc/default/rcS or a manual fsck -fy. Personally I think preen would be safer, but then again it would hang on startup if the disk needs some more fixes that fsck does not deem "safe " and wants user interaction.

run

sudo update-grub

to update grup and verify it with

grep fsck /boot/grub/grub.cfg 

or have a look with an editor in /boot/grub/grub.cfg

If you then reboot, the filesystem should be checked, you can verify the last time it was checked (should be your boot time) with

sudo dumpe2fs -h /dev/your/device | grep checked
dumpe2fs 1.43.5 (04-Aug-2017)
Last checked:             Sun Feb 18 08:53:31 2018