Coming from a Windows (Server) background one would expect that file system errors are corrected automatically on boot. Not so the case on Linux machines. On one of my boxes with a nightly reboot, I have recently observed that the machine is not coming back up due to file system inconsistencies. Why this is happening I am not sure – also I do not particularly care and no data loss is occurring (to my knowledge) when manually running fsck through the forced recovery console. Assuming a drive is at some point of failure. So in this scenario a suitable workaround is the following:
Running this command prior to reboot will force file system checking when the machine boots:
1 | touch /forcefsck |
And as a script, the following is being used via chron:
1 2 3 4 5 6 | #!/bin/bash env PATH=/scripts:/scripts:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/var/lib/snapd/snap/bin:/snap/bin:/var/lib/snapd/snap/bin export path touch /forcefsck /sbin/reboot |
If you wish to run FSCK intermittently you can use the tune2fs utility to schedule a check every X# of bootups:
1 | tune2fs -c 30 /dev/sdaX |
This will yield a file system check every 30 bootups.