How to force fsck on reboot for Ubuntu 20.04

The old convenient trick of creating a file /forcefsck to force a file check on reboot does not work anymore since systemd took over initialisation.

Change "Maximum number of mounts" (only ext file systems)

The quickest way, probably, is to temporarily change your Maximum mount count to 1. That will cause the kernel and e2fsck to check the file system on the next reboot. However, this only works with ext file systems.

First check your current setting in case you want to restore to default later:

sudo tune2fs -l /dev/nvme0n1p2 | grep 'Maximum mount'

Substitute /dev/nvme0n1p2 by the device name of your system partition. Chances are this is set to -1 nowadays, disabling check based on the number of times the volume has been mounted.

Adjust the setting to 1 with the command:

sudo tune2fs -c 1 /dev/nvme0n1p2

Now reboot - the volume should be checked. After reboot, you should reset the value to what it was before in order to avoid the partition being checked everytime.

Change kernel parameter

Another way is to pass kernel parameters during boot that control the systemd services for file system check. fsck.mode=force will force a file check.

To add a kernel parameter for a single time, boot to the Grub menu, highlight the entry and hit e. Move to the line starting with linux, hit End to move to the last line, add a space and the kernel parameter. Hit Ctrl+x to close and continue booting.


If you want to force fsck with each reboot, there are few steps you need to follow.

  1. use blkid to identify the uuid for the partition.
amarcus@amarcus-desktop:~$ blkid
/dev/mapper/vgubuntu-swap_1: UUID="d24b0766-c9be-49ef-9022-8ccae4f79801" TYPE="swap"
/dev/mapper/vgubuntu-root: UUID="d414c4f9-da0d-42bf-8290-4bcb55b8d984" BLOCK_SIZE="4096" TYPE="ext4"
amarcus@amarcus-desktop:~$ 

  1. Use uuid or mount point to locate the partition in /etc/fstab
amarcus@amarcus-desktop:~$ cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/vgubuntu-root /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=0AE0-795B  /boot/efi       vfat    umask=0077      0       1
/dev/mapper/vgubuntu-swap_1 none            swap    sw              0       0

UUID=D41C-2F17 /mnt/WDElements auto umask=0022,gid=1000,uid=1000,x-gvfs-show 0 0

The last column that is a column 6, aka fsck PASS column is used by fsck to determine whether fsck should check filesystem before it is mounted and in which order given partitions in /etc/fstab should be checked

For root partitions, make sure that entry is set to 1

  1. Finally, set the mount counter for that partition to 1.
root@amarcus-desktop:~# tune2fs -c 1 /dev/mapper/vgubuntu-root

Explanation:

Basically, in step 1 you are identifying which partition you want to check at boot.

In step 2, you are making sure that it takes higher priory. It's useful if you are checking more than one partitions. It decide which should be taken up first, then second and so on.

In step 3, you are saying after how many mounts the partition should be checked. The argument 1 specifies that after one mount the partition should be checked. So basically it checks after each mount, i.e. after every restart.