How To Force fsck (Filesystem Consistency Check) After Reboot

fsck is a tool for checking and repairing a filesystem on Linux, macOS, and FreeBSD, similar to the CHKDSK Windows tool.

With old sysvinit and Upstart, users could force a disk check on next reboot using a simple command (sudo touch /forcefsck), but that's no longer the case nowadays, with most Linux distributions using systemd. This article explains how to force fsck to run at boot time in two ways, which work with systemd. You'll also find a command that shows when a partition was last checked by fsck, at the end of the article.

Using the steps below you'll force a filesystem consistency check each time your computer boots. There are also instructions for undoing this.

Option 1 (for ext2/ext3/ext4 filesystems only): force fsck on reboot using tune2fs


tune2fs can force a fsck on each reboot for EXT4, EXT3 and EXT2 filesystems only. Most Linux distributions use EXT3/4 by default, so unless you explicitly specified a different filesystem type, that's what you're using in most cases.

tune2fs can trigger a forced fsck on every reboot using the -c (max-mount-counts) option. This option sets the number of mounts after which the filesystem will be checked, so setting it to 1 will run fsck each time the computer boots. Setting it to -1 or 0 resets this (the number of times the filesystem is mounted will be disregarded by e2fsck and the kernel).

For this to work you'll need to make sure the partition you want to check and repair using fsck has the pass number greater than 0 set in /etc/fstab (last column in /etc/fstab). The root partition should be set to 1 (first to be checked), while other partitions you want to be checked should be set to 2. Example:

# /etc/fstab: static file system information.

/dev/sda1  /      ext4  errors=remount-ro  0  1
/dev/sda5  /home  ext4  defaults           0  2

After doing this, force a fsck on each boot for an EXT4, EXT3 or EXT2 filesystem using:

sudo tune2fs -c 1 /dev/sdXY

You'll need to replace sdXY with the partition you want to check and repair. You can find this using a graphical application like Gparted, which displays all available partitions for each disk, or using a command line tool, like lsblk or fdisk (sudo fdisk -l).

Now you can reboot your system, and fsck should be forced to run a filesystem consistency check.

When you no longer want to force fsck to run on each boot, run the same command but with -1 instead of 1:

sudo tune2fs -c -1 /dev/sdXY

You can also use this command to run fsck periodically. For example you could set fsck to run a filesystem check every 30 boots, by using -c 30 (e.g.: sudo tune2fs -c 30 /dev/sdXY).

Option 2: force fsck on reboot using fsck.mode=force as a kernel parameter, and optionally fsck.repair=yes


This should work with many filesystem types, including ext4/ext3/ext2, xfs, ntfs, fat32, exfat, and more.  It should also be noted that systemd-fsck does not know any details about specific filesystems, and simply executes file system checkers specific to each filesystem type (/sbin/fsck.*; e.g.: /sbin/fsck.ext4).

systemd runs fsck for each filesystem that has a fsck pass number greater than 0 set in /etc/fstab (last column in /etc/fstab), so make sure you edit your /etc/fstab if that's not the case. The root partition should be set to 1 (first to be checked), while other partitions you want to be checked should be set to 2. Example:

# /etc/fstab: static file system information.

/dev/sda1  /      ext4  errors=remount-ro  0  1
/dev/sda5  /home  ext4  defaults           0  2

All partitions that appear in /etc/fstab and have the pass (last column in fstab) number greater than 0 will be checked if you boot with the fsck.mode=force kernel parameter.

Now that we got that out of the way, this how how to force a fsck on boot with systemd. You need to add fsck.mode=force as a kernel parameter to your grub configuration file.

This command uses Nano command line text editor to open /etc/default/grub so you can edit it:

sudo nano /etc/default/grub

To force a fsck each time the computer boots, you'll need to add fsck.mode=force to GRUB_CMDLINE_LINUX_DEFAULT, at the end of the line but before the last quote (").

Example:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash fsck.mode=force"

Make sure you don't edit anything else, and that the edits you've made are correct, or else your computer may fail to boot!

After you're done making the changes, save the file and exit (to save the file and exit Nano use: Ctrl + O, Enter, then Ctrl + X).

There is a second kernel parameter that you can add, called fsck.repair. This has the default option preen, which automatically repairs problems that can safely be fixed. You can use fsck.repair=yes to answer "yes" to all questions by fsck, or "no" to answer no to all questions.

Example (force fsck on each reboot and answer "yes" to all fsck questions):

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash fsck.mode=force fsck.repair=yes"

Add this to /etc/default/grub in the same way as explain before.

After you've finished editing /etc/default/grub, update your Grub2 configuration:

  • Debian / Ubuntu / Linux Mint:
sudo update-grub

  • Fedora or openSUSE
sudo grub2-mkconfig -o /boot/grub2/grub.cfg

  • Arch Linux:
sudo grub-mkconfig -o /boot/grub/grub.cfg

On other Linux distributions you can try the commands mentioned above. If they don't work, search for how to update the Grub2 configuration for your Linux distribution.

When you're done, reboot the system and fsck should run a filesystem consistency check on boot.

To stop force-checking your filesystem on each boot, remove fsck.mode=force (and fsck.repair=yes if you added it) from your /etc/default/grub configuration file, and update grub, as already explained.

How to find out when a filesystem was last checked by fsck


You can find out when a filesystem was last checked by fsck using tune2fs:

sudo tune2fs -l /dev/sdXY | grep checked

Replace sdXY with the partition you want to see when it was last checked. Example:

$ sudo tune2fs -l /dev/sda1 | grep checked
Last checked:             Thu May 23 15:16:23 2019