# How to Use ‘fsck’ to Repair Linux File System Errors

[Linux Filesystems](https://www.tecmint.com/linux-directory-structure-and-important-files-paths-explained/ "Linux Filesystem Structure") are responsible for organizing how data is stored and recovered. One way or another, with time, the filesystem may become corrupted and certain parts of it may not be accessible. If your filesystem develops such inconsistency it is recommended to verify its integrity.

This can be completed via a system utility called **fsck** (**file system consistency check**), which checks the root file system automatically during boot time or ran manually.

In this article, we are going to review the **fsck command** and its usage to help you repair Linux disk errors.

Table of Contents

<div class="ez-toc-v2_0_46 counter-hierarchy ez-toc-counter ez-toc-container-direction" id="bkmrk-when-to-use-fsck-com"><label class="cssicon" for="ez-toc-cssicon-toggle-item-643256fe8d14a"><svg class="list-377408" fill="none" height="20px" viewbox="0 0 24 24" width="20px" xmlns="http://www.w3.org/2000/svg"></svg><svg baseprofile="tiny" class="arrow-unsorted-368013" height="10px" version="1.2" viewbox="0 0 24 24" width="10px" xmlns="http://www.w3.org/2000/svg"></svg></label> [ ] <nav>- [When to Use fsck Command in Linux](https://www.tecmint.com/fsck-repair-file-system-errors-in-linux/#When_to_Use_fsck_Command_in_Linux "When to Use fsck Command in Linux")
    - [fsck Command Options](https://www.tecmint.com/fsck-repair-file-system-errors-in-linux/#fsck_Command_Options "fsck Command Options")
- [Run fsck Command to Repair Linux File System Errors](https://www.tecmint.com/fsck-repair-file-system-errors-in-linux/#Run_fsck_Command_to_Repair_Linux_File_System_Errors "Run fsck Command to Repair Linux File System Errors")
    - [Understanding fsck Exit Codes](https://www.tecmint.com/fsck-repair-file-system-errors-in-linux/#Understanding_fsck_Exit_Codes "Understanding fsck Exit Codes")
    - [Fsck Repair Linux Filesystem](https://www.tecmint.com/fsck-repair-file-system-errors-in-linux/#Fsck_Repair_Linux_Filesystem "Fsck Repair Linux Filesystem")
- [How to Run fsck on Linux Root Partition](https://www.tecmint.com/fsck-repair-file-system-errors-in-linux/#How_to_Run_fsck_on_Linux_Root_Partition "How to Run fsck on Linux Root Partition")
    - [Force fsck Upon System Boot](https://www.tecmint.com/fsck-repair-file-system-errors-in-linux/#Force_fsck_Upon_System_Boot "Force fsck Upon System Boot")
    - [Run fsck in Rescue Mode](https://www.tecmint.com/fsck-repair-file-system-errors-in-linux/#Run_fsck_in_Rescue_Mode "Run fsck in Rescue Mode")
        - [Conclusion](https://www.tecmint.com/fsck-repair-file-system-errors-in-linux/#Conclusion "Conclusion")

</nav></div>### <span class="ez-toc-section" id="bkmrk--2"></span>When to Use fsck Command in Linux

There are different scenarios when you will want to run **fsck**. Here are a few examples:

- The system fails to boot.
- Files on the system become corrupt (often you may see input/output error).
- The attached drive (including flash drives/SD cards) is not working as expected.

#### <span class="ez-toc-section" id="bkmrk--3"></span>fsck Command Options

The **fsck command** needs to be run with superuser privileges or **root**. You can use it with different arguments. Their usage depends on your specific case. Below you will see some of the more important 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 the 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 [Linux filesystem types](https://www.tecmint.com/find-file-types-in-linux/ "Find Out File Types in Linux") to be checked. Types can be comma-separated lists.
- `-V` – Provide a description of what is being done.

### <span class="ez-toc-section" id="bkmrk--4"></span>Run fsck Command to Repair Linux File System Errors

<center id="bkmrk--0"><div align="center" id="bkmrk--5"></div></center>In order to run **fsck**, you will need to ensure that the partition you are going to check is not mounted. For the purpose of this article, I will use my second drive `/dev/sdb` mounted in `/mnt`.

Here is what happens if I try to run **fsck** when the partition is mounted.

```
# fsck /dev/sdb
```

<figure aria-describedby="caption-attachment-30684" class="wp-caption aligncenter" id="bkmrk-run-fsck-on-mounted-">[![Run fsck on Mounted Partition](https://www.tecmint.com/wp-content/uploads/2018/09/Run-fsck-on-Mounted-Partition.png)](https://www.tecmint.com/wp-content/uploads/2018/09/Run-fsck-on-Mounted-Partition.png)<figcaption class="wp-caption-text" id="bkmrk-run-fsck-on-mounted--0">Run fsck on Mounted Partition</figcaption></figure>To avoid this unmount the partition using.

```
# umount /dev/sdb
```

Then **fsck** can be safely run with.

```
# fsck /dev/sdb
```

<figure aria-describedby="caption-attachment-30685" class="wp-caption aligncenter" id="bkmrk-run-fsck-on-linux-pa">[![Run fsck on Linux Partition](https://www.tecmint.com/wp-content/uploads/2018/09/Run-fsck-on-Linux-Partition.png)](https://www.tecmint.com/wp-content/uploads/2018/09/Run-fsck-on-Linux-Partition.png)<figcaption class="wp-caption-text" id="bkmrk-run-fsck-on-linux-pa-0">Run fsck on Linux Partition</figcaption></figure>#### <span class="ez-toc-section" id="bkmrk--6"></span>Understanding fsck Exit Codes

After running **fsck**, it will return an exit code. These codes can be seen in fsck’s manual by running:

```
<strong># man fsck</strong>

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

#### <span class="ez-toc-section" id="bkmrk--7"></span>Fsck Repair Linux Filesystem

Sometimes more than one error can be found on a filesystem. In such cases, you may want **fsck** to automatically attempt to correct the errors. This can be done with:

```
# fsck -y /dev/sdb
```

The `-y` flag, automatically `“yes”` to any prompts from fsck to correct an error.

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

```
$ fsck -AR -y 
```

### <span class="ez-toc-section" id="bkmrk--8"></span>How to Run fsck on Linux Root Partition

In some cases, you may need to run **fsck** on the **root** partition of your system. Since you cannot run **fsck** while the partition is mounted, you can try one of these options:

- Force fsck upon system boot
- Run fsck in rescue mode

We will review both situations.

#### <span class="ez-toc-section" id="bkmrk--9"></span>Force fsck Upon System Boot

This is relatively easy to complete, the only thing you need to do is create a file called **forcefsck** in the root partition of your system. Use the following command:

```
# touch /forcefsck
```

Then you can simply force or schedule a [reboot of your system](https://www.tecmint.com/disable-shutdown-and-reboot-commands-in-linux/ "Reboot Commands in Linux"). During the next bootup, the **fsck** will be performed. If downtime is critical, it is recommended to plan this carefully, since if there are many used inodes on your system, **fsck** may take some extra time.

After your system boots, check if the file still exists:

```
# ls /forcefsck
```

If it does, you may want to remove it in order to avoid **fsck** on every system boot.

#### <span class="ez-toc-section" id="bkmrk--10"></span>Run fsck in Rescue Mode

Running **fsck** in **rescue mode** requires a few more steps. First, prepare your system for **reboot**. Stop any critical services like **MySQL/MariaDB** etc and then type.

```
# reboot
```

During the boot, hold down the `shift` key so that the grub menu is shown. Select “**Advanced options**”.

<figure aria-describedby="caption-attachment-30686" class="wp-caption aligncenter" id="bkmrk-grub-advanced-option">[![Grub Advance Options](https://www.tecmint.com/wp-content/uploads/2018/09/Grub-Advance-Options.png)](https://www.tecmint.com/wp-content/uploads/2018/09/Grub-Advance-Options.png)<figcaption class="wp-caption-text" id="bkmrk-grub-advanced-option-0">Grub Advanced Options</figcaption></figure>Then choose “**Recovery mode**”.

<figure aria-describedby="caption-attachment-30687" class="wp-caption aligncenter" id="bkmrk-select-linux-recover">[![Select Linux Recovery Mode](https://www.tecmint.com/wp-content/uploads/2018/09/Select-Linux-Recovery-Mode.png)](https://www.tecmint.com/wp-content/uploads/2018/09/Select-Linux-Recovery-Mode.png)<figcaption class="wp-caption-text" id="bkmrk-select-linux-recover-0">Select Linux Recovery Mode</figcaption></figure>In the next menu select “**fsck**”.

<figure aria-describedby="caption-attachment-30688" class="wp-caption aligncenter" id="bkmrk-select-fsck-utility">[![Select fsck Utility](https://www.tecmint.com/wp-content/uploads/2018/09/Select-fsck-Utility.png)](https://www.tecmint.com/wp-content/uploads/2018/09/Select-fsck-Utility.png)<figcaption class="wp-caption-text" id="bkmrk-select-fsck-utility-0">Select fsck Utility</figcaption></figure>You will be asked if you wish to have your `/` filesystem remounted. Select `“yes”`.

<figure aria-describedby="caption-attachment-30689" class="wp-caption aligncenter" id="bkmrk-confirm-root-filesys">[![Confirm Root Filesystem](https://www.tecmint.com/wp-content/uploads/2018/09/Confirm-Root-Filesystem.png)](https://www.tecmint.com/wp-content/uploads/2018/09/Confirm-Root-Filesystem.png)<figcaption class="wp-caption-text" id="bkmrk-confirm-root-filesys-0">Confirm Root Filesystem</figcaption></figure>You should see something similar to this.

<figure aria-describedby="caption-attachment-30690" class="wp-caption aligncenter" id="bkmrk-running-fsck-filesys">[![Running fsck Filesystem Check](https://www.tecmint.com/wp-content/uploads/2018/09/Running-fsck-Filesystem-Check.png)](https://www.tecmint.com/wp-content/uploads/2018/09/Running-fsck-Filesystem-Check.png)<figcaption class="wp-caption-text" id="bkmrk-running-fsck-filesys-0">Running fsck Filesystem Check</figcaption></figure>You can then resume normal boot, by selecting **“Resume”**.

<figure aria-describedby="caption-attachment-30691" class="wp-caption aligncenter" id="bkmrk-select-normal-boot">[![Select Normal Boot](https://www.tecmint.com/wp-content/uploads/2018/09/Select-Normal-Boot.png)](https://www.tecmint.com/wp-content/uploads/2018/09/Select-Normal-Boot.png)<figcaption class="wp-caption-text" id="bkmrk-select-normal-boot-0">Select Normal Boot</figcaption></figure>##### <span class="ez-toc-section" id="bkmrk--11"></span>Conclusion

In this tutorial, you learned how to use fsck and run consistency checks on different Linux filesystems. If you have any questions about **fsck**, please do not hesitate to submit them in the comment section below.