Force checking the file system

When the system starts throwing errors about the main filesystem, it’s time for a check. fsck handles the file system check.

While a file system check shouldn’t loose any data, if done improperly, or if there’s more to the issue, you can loose ALL of your data. Make sure you have a backup.

Systemd

To force check the system in systemd, add the below to your kernel options. This is the linux line in grub which can be edited by pressing e (for ‘edit’) on the selected system when the system shows the selection of operation systems in grub.

fsck.mode=force

So it looks something like:

  linux   /vmlinuz-linux root=.....  quiet fsck.mode=force
  initrd  /initramfs-linux.img

This will run the fsck automatically. If there is anything that the system needs you attention for, it will drop you to a shell where you can run it manually.

Traditional SysVinit

With the traditional SysVinit system, you would create a file in the root (/) of the system named forcefsck.

touch /forcefsck

By hand

It’s also possible to boot into Single User Mode by adding the below to the kernel line:

systemd.unit=rescue

(On traditional systems, add init 1)

This will give you a prompt. Typically, we will want to run something like this, where /dev/sdX is the path to our hard drive.

fsck -C0 /dev/sdX