Further investigation and updates on the existing answer
I now just wanted to check, whether the above still works on Ubuntu 20.04/22.04-LTS-based systems (directly tested on Linux Mint 20/21 Cinnamon amd64 desktop and Ubuntu MATE 20.04/22.04 amd64 desktop), and I found out a few things, let's start with the file system check interval (I ran all commands as root (as you might notice ~# in front of commands):
File system check interval
~# LC_ALL=C tune2fs -l /dev/nvme0n1p2 | grep 'Check interval' Check interval: 0 (<none>)
Well, this was unexpected. I thought we took care of it, but can be fixed very easily. Take note, the number it takes as an argument is by default in days, so be sure to use 1s (1 seconds) instead of just 1 which would mean 1 day (86400 seconds):
~# LC_ALL=C tune2fs -i 1s /dev/nvme0n1p2 tune2fs 1.45.5 (07-Jan-2020) Setting interval between checks to 1 seconds
Now, if we repeat the above check, we get:
Check interval: 1 (0:00:01)
This does not mean the file system will be checked every second, of course. Rather, in effect it will force the file system check on every file system mount. (As there is no way of booting any system twice in one second 😀.)
File system maximum number of mounts before check
Default setting:
~# LC_ALL=C tune2fs -l /dev/nvme0n1p2 | grep 'Maximum mount count' Maximum mount count: -1
This setting adjusts how many mounts it takes till the file system gets checked. It's ok what is written in the original answer:
~# LC_ALL=C tune2fs -c 1 /dev/nvme0n1p2 tune2fs 1.45.5 (07-Jan-2020) Setting maximal mount count to 1
Just make sure you do not use 0 or -1 as it would become disregarded.
---
Combination of both - The recommended way
Here you only change your disk name (e.g. sda, vda, nvme0n1, etc.), and partition number:
First, we find out the current status with:
partition=/dev/nvme0n1p2; LC_ALL=C tune2fs -l $partition | grep -E 'Check\ interval|Maximum\ mount\ count'
=
Maximum mount count: -1 Check interval: 0 (<none>)
Afterward, we set these values so that the file system is checked on every boot with:
partition=/dev/nvme0n1p2; LC_ALL=C tune2fs -i 1s -c 1 $partition 2>&1 | grep Setting
=
Setting maximal mount count to 1 Setting interval between checks to 1 seconds
Finally, let's review the new status with the same first command:
partition=/dev/nvme0n1p2; LC_ALL=C tune2fs -l $partition | grep -E 'Check\ interval|Maximum\ mount\ count'
=
Maximum mount count: 1 Check interval: 1 (0:00:01)
Information sources:
Keep checking (pun intended)! 😎