Manual Fsck

Linux fsck utility is used to check and repair Linux filesystems (ext2, ext3, ext4, etc.).

Depending on when was the last time a file system was checked, the system runs the fsck during boot time to check whether the filesystem is in consistent state. System administrator could also run it manually when there is a problem with the filesystems.

To prevent fsck from checking root, use –R flag. This will only work with the flag –A. Perform automatic repair. FTo perform an automatic repair after fsck errors check, use the following command: fsck -p /dev/sdxy. Keep in mind to replace x with the drive number and y with the partition number. Running fsck from Single User Mode. Fsck is a powerful utility, but macOS won’t let you run it from inside the operating system. You might think you can run fsck on a non-booting disk, but you’d be wrong: fsck is basically non-functional while in macOS’s userland. Performing fsck on non-root filesystem is fairly straight forward. But, for root filesytem, you cannot perform fsck when it is mounted. This quick tutorial explains how to force filesytem check for a root filesystem. In this example, /dev/sda1 partition is the root filesystem that is mounted as / # df -h Filesystem Siz.

Make sure to execute the fsck on an unmounted file systems to avoid any data corruption issues.
This article explains 10 practical examples on how to execute fsck command to troubleshoot and fix any filesystem errors.

The root file system requires a manual fsck

Manual Fsck Ubuntu

1. Filesystem Check on a Disk Partition

First, view all the available partitions on your system using parted command as shown below.

Manual Fsck Linux Mint

You can check a specific filesystem (for example: /dev/sda6) as shown below.

The following are the possible exit codes for fsck command.

  • 0 – No errors
  • 1 – Filesystem errors corrected
  • 2 – System should be rebooted
  • 4 – Filesystem errors left uncorrected
  • 8 – Operational error
  • 16 – Usage or syntax error
  • 32 – Fsck canceled by user request
  • 128 – Shared-library error

2. Fsck Command Specific to a Filesystem Type

fsck internally uses the respective filesystem checker command for a filesystem check operation. These fsck checker commands are typically located under /sbin.

The following example show the various possible fsck checker commands (for example: fsck.ext2, fsck.ext3, fsck.ext4, etc.)

fsck command will give you an error when it doesn’t find a filesystem checker for the filesystem that is being checked.

For example, if you execute fsck over a ntfs partition, you’ll get the following error message. There is no fsck.ntfs under /sbin. So, this gives the following error message.

3. Check All Filesystems in One Run using Option -A

You can check all the filesystems in a single run of fsck using this option. This checks the file system in the order given by the fs_passno mentioned for each filesystem in /etc/fstab.

Please note that the filesystem with a fs_passno value of 0 are skipped, and greater than 0 are checked in the order.

The /etc/fstab contains the entries as listed below,

Here, the filesystem with the same fs_passno are checked in parallel in your system.

It is recommended that you exclude the root filesystem during this global check by adding -R option as shown below.

Note: Option -y is explained in one of the examples below.

Fsck

4. Check Only a Specific Filesystem Type using Option -t

Using fsck -t option, you can specify the list of filesystem to be checked. When you are using with option -A, the fsck will check only the filesystem mentioned with this option -t. Note that fslist is a comma separated values.

Now, pass ext2 as the fslist value to -t option as shown below:

In this example, /dev/sda6 is the only partition created with the filesystem ext2, thus it get checked accordingly.

Using the keyword ‘no’ in front of filesystem, you can check all other filesystem types except a particular filesystem.

In the following example, ext2 filesystem is excluded from the check.

5. Don’t execute Fsck on Mounted Filesystem using Option -M

It is a good idea to use this option as default with all your fsck operation. This prevents you from running fsck accidentally on a filesystem that is mounted.

As shown above, /dev/sda7 is mounted. If you try to execute fsck on this /dev/sda7 mounted filesystem (along with the -M option), fsck will simply exit with the exit code 0 as shown below.

6. Skip the Display Title using Option -T

Using option -T, you can skip the title get displayed in the beginning of fsck command output.

Note that the title is something like “fsck from util-linux 2.20.1”.

7. Force a Filesystem Check Even if it’s Clean using Option -f

By default fsck tries to skip the clean file system to do a quicker job.

You can force it to check the file system using -f as shown below.

8. Attempt to Fix Detected Problems Automatically using Option -y

In the following example, /dev/sda6 partition is corrupted as shown below.

As seen above, the directory Movies and a file test attributes are invalid.

Manual fsck linux mint

In the following example, -y will pass “yes” to all the questions to fix the detected corruption automatically.

9. Avoid Repair, but Report Problems to Stdout using Option -n

It is possible to print such detected problems into stdout without repairing the filesystem using fsck -n option.

First, you could notice/see the problem in partition /dev/sda6 that the Movies directory (and fwh file) doesn’t have valid attribute details.

Manual

The above problem in the specific partition displayed in stdout without doing any fix on it as follows,

The following fsck example displays the problem in the stdout without fixing it. (partial output is shown below).

Manual Fsck

10. Automatically Repair the Damaged Portions using Option -a

In order to repair the damaged portion automatically ( without any user interaction ), use the option -a as shown below.

Root Requires A Manual Fsck

The option -a is same as -p in e2fsck utility. It cause e2fsck to fix any detected problems that has to be safely fixed without user interaction.

In case when fsck requires administrator’s attention, it simply exits with error code 4 before printing the description of the problem.

As you remember, fsck -y option can be used here to fix the above issue automatically.