fsck is a command-line tool to perform compatibility tests on one or more Linux file systems, as well as interactive fixes on a single or a single file system. Its using the programs specific to the type of the file system it checks.

We used fsck command for repair corrupted file systems in the condition of where system unable to boot or in any partition mounted issue.

How to Use fsck?

Below are the syntax of Fsck command and you have required root user or root user privileged for run this command.

[[email protected] ~]# fsck [OPTIONS] [FILESYSTEM]

fsck have below options

  • -A – Used for checking all filesystems. The list is taken from /etc/fstab.
  • -C – Show progress bar.
  • -l – Locks the device to guarantee no other program will try to use the partition during the check.
  • -M – Do not check mounted filesystems.
  • -N – Only show what would be done – no actual changes are made.
  • -P – If you want to check filesystems in parallel, including root.
  • -R – Do not check root filesystem. This is useful only with ‘-A‘.
  • -r – Provide statistics for each device that is being checked.
  • -T – Does not show the title.
  • -t – Exclusively specify the filesystem types to be checked. Types can be comma separated list.
  • -V – Provide description what is being done.

How to execute fsck command for repair Linux Files System

Partition should be unmounted for run the below command. Here is what if I try to run fsck on mounted partition.

[[email protected] ~]# fsck /dev/hdb
fsck from util-linux 2.31.2
e2fsck 1.44.2 (10-May-2019)
/dev/hdb is mounted.
e2fsck: Cannot continue, aborting

Run the below command to unmount the server and avoid the issue.

[[email protected] ~]# umount /dev/hdb

Now you can run command safely.

[[email protected] ~]# fsck /dev/hdb
fsck from util-linux 2.31.2
e2fsck 1.44.2 (10-May-2019)
/dev/hdb is clean, 12/234567 files,445546/35423456 blocks
[[email protected] ~]#

Repair Linux Filesystem Errors

Often, on a filesystem there are more than one mistake. In such situations, fsck could try to correct the errors automatically. With this you can do:

[[email protected] ~]# fsck -y /dev/hdb

Where -y is for yes automatically for prompts from fsck to correct an error.

Exactly, you can run the same on all filesystems (without root):

[[email protected] ~]# fsck -AR -y 

Thankyou…