Published November 9, 2023

This article describes how to perform a file system check.

Under Linux, the fsck command is used to check file system consistency, and may be prompted to correct them if it detects inconsistencies.

File system check

Read-only file system check

The -n option opens the file system in read-only mode, and answers no questions.

Check at next startup

  • If you don't want to restart the server immediately but want to run a test on the next startup, you need to create the forcefsck file in the server root.:~# touch /forcefsck
  • Run the shutdown command with the -F option (to force fsck to be used at startup).:~# shutdown -r -F now

File system repair

We strongly advise you not to run a repair on a mounted partition.

Start-up repair

You can have fsck automatically repair all errors at startup by answering yes to the questions.

To activate this option, edit the /etc/default/rcS file and set the FSCKFIX value to yes (the default value is no). The server then executes the command fsck -y (fsck yes...).


Then run the shutdown command with the -F option (to force fsck to be used at startup):

:~# shutdown -r -F now

Repair in Maintenance mode

Once in maintenance mode (single-user mode), use the mount command to ensure that the partition is not mounted before repairing it. Example:

:~#fsck -cyf /dev/sda2

  • y: Answers "yes" to all questions, allowing non-interactive use of e2fsck.
  • f: Forces verification even if the file system looks clean.
  • c: This option forces e2fsck to run the program badblocks program to find bad sectors on the media hosting the file system. They will then be marked as bad and added to the badblocks inode.

Don't forget to reboot the server with the reboot command after the repair.


Once the repair is complete, you can (re)check the file system.