Forcing an ext4 filesystem check on the next reboot
Forcing an ext4 Filesystem Check on the Next Reboot with tune2fs
Sometimes you need to verify an ext4 filesystem, but the filesystem is mounted and cannot safely be repaired online. This is especially common when the filesystem is the root filesystem, such as /dev/md0 mounted as /.
Running fsck directly on a mounted filesystem is not a safe way to repair it:
|
|
The -n option makes it read-only, so it will not fix anything. Also, because the filesystem is mounted, the result may be noisy or misleading. For a real repair check, fsck must run before the filesystem is mounted, usually during boot.
In practice, this can look like a false positive: a full check during early boot or single-user/rescue mode may report the filesystem as clean, while fsck -n on the same filesystem after it is mounted may still show apparent errors. That does not necessarily mean the boot-time check failed. It usually means the mounted filesystem is changing while fsck is looking at it, and read-only fsck -n also skips journal recovery.
Force fsck on the Next Boot
For ext2/ext3/ext4 filesystems, you can use tune2fs to change the mount counters:
|
|
This sets two ext4 metadata values:
-c 30sets the maximum mount count to30-C 31sets the current mount count to31
Since 31 is greater than 30, the system should consider the filesystem due for checking on the next mount.
After running the command, reboot:
|
|
Check the Current ext4 fsck Counters
You can inspect the relevant ext4 metadata with:
|
|
Example output after a successful boot-time check:
|
|
The important lines are:
|
|
This means the filesystem was checked, is currently clean, and the mount counter was reset.
What Do 30 and 31 Mean?
The numbers are not magic.
ext4 stores a mount counter inside the filesystem metadata:
|
|
Mount count is the number of times the filesystem has been mounted since the last successful check.
Maximum mount count is the threshold after which the filesystem should be checked again.
So this command:
|
|
means:
|
|
Because the current count is already above the maximum, the next boot should trigger fsck.
After a successful check, the mount count is normally reset. Then, after about 30 future mounts, the filesystem will be checked again.
Forcing fsck with Kernel Parameters
On systemd-based systems, especially for the root filesystem, you may also see boot parameters like this:
|
|
You can confirm the active kernel command line with:
|
|
Example:
|
|
These options tell systemd/initramfs to force filesystem checks and automatically repair safe issues.
Checking the Boot Logs
For non-root filesystems, this may show useful output:
|
|
However, for the root filesystem, the check often happens inside the initramfs before the normal system journal is fully available. In that case, this command may show:
|
|
That does not necessarily mean fsck did not run.
A broader journal search may still show related boot activity:
|
|
Example output:
|
|
For root filesystem checks, the most useful log is often:
|
|
Example:
|
|
This confirms that fsck actually ran on /dev/md0 during early boot.
Do Not Trust fsck -n on a Mounted Root Filesystem Too Much
If you run:
|
|
while /dev/md0 is mounted as /, you may see warnings like:
|
|
That mode is useful for a rough diagnostic, but it is not a reliable final verdict. The real check should happen before the filesystem is mounted.
The better confirmation is:
|
|
And optionally:
|
|
Disabling Periodic Mount-Count Checks Again
If you only wanted a one-time check and do not want ext4 to keep checking every 30 mounts, you can disable the mount-count and interval-based checks again:
|
|
This restores behavior like:
|
|
Notes and Caution
Only use this method for ext2/ext3/ext4 filesystems. It does not apply to filesystems like XFS, Btrfs, ZFS, or FAT.
If the filesystem is the root filesystem and the server is remote, make sure you have some kind of recovery access before forcing repairs. If fsck encounters a problem that cannot be fixed automatically, the system may stop in rescue or emergency mode, and SSH may not come up.
For a clean result, the target state should look like this:
|
|