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

Filesystems are responsible for organizing how data is stored and recovered. One way or another, with time, filesystem may become corrupted and certain parts of it may not be accessible. If your filesystem develops such inconsistency it is recommend to verify its integrity.

This can be completed via system utility called fsck (file system consistency check). This check can be done automatically during boot time or ran manually.

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

When to Use fsck in Linux

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

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

fsck Available options

Fsck command needs to be run with superuser privileges or root. You can use it with different arguments. Their usage depend 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 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 Run fsck to Repair Linux File System Errors

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
Run fsck on Mounted Partition

Run fsck on Mounted Partition

To avoid this unmount the partition using.

# umount /dev/sdb

Then fsck can be safely ran with.

# fsck /dev/sdb
Run fsck on Linux Partition

Run fsck on Linux Partition

Understanding fsck exit codes

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

# man fsck

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     Checking canceled by user request
128    Shared-library error            

Repair Linux Filesystem Errors

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 ran the same on all filesystems (without root):

$ fsck -AR -y 

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.

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. 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.

Run fsck in Rescue Mode

Running fsck in rescue mode requires 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 the “Advanced options”.

Grub Advance Options

Grub Advance Options

Then choose “Recovery mode”.

Select Linux Recovery Mode

Select Linux Recovery Mode

In the next menu select “fsck”.

Select fsck Utility

Select fsck Utility

You will be asked if you wish to have your / filesystem remounted. Select “yes”.

Confirm Root Filesystem

Confirm Root Filesystem

You should see something similar to this.

Running fsck Filesystem Check

Running fsck Filesystem Check

You can then resume to normal boot, by selecting “Resume”.

Select Normal Boot

Select Normal Boot


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

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Marin Todorov

I am a bachelor in computer science and a Linux Foundation Certified System Administrator. Currently working as a Senior Technical support in the hosting industry. In my free time I like testing new software and inline skating.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

18 Responses

  1. Robert says:

    Lifesaver, short and accurate article..

  2. Domingo says:

    Thank a lot Sir, was very useful

  3. Michael Plemmons says:

    I tried it from the recovery mode and I get to the screen to switch to read/write and click yes, then it says dev/sda1 is mounted and takes me back to recovery menu.

    If I click fsck again, it says this operation requires me to be in read-only mode and the last operation requested switched me to read/write. To go back to read-only, reboot the system. I’ve done this over and over. I’m in Ubuntu 18.10. Any ideas? Thanks

  4. Hung says:

    I have a VPS CentOS 7, If following this tutorial, will i lose my data on vps ?

  5. Jim says:

    What version of Ubuntu does this article relate to? People like me are still using 16.04 because of all of 18.04’s problems and I don’t see the graphic just below the line, “You can then resume to normal boot, by selecting “Resume”. Is that GUI ONLY in 18.04?

  6. Rajan bhandari says:

    My PC is not showing 64 bit while I try to install it. What to do please help me..

  7. R. Owen Sterling says:

    Classic Ubuntu user arrogance, to equate Ubuntu with all of Linux in the headline, then list *Ubuntu-specific recovery-mode options as if they were universal. Just about every “recovery mode” I’ve ever seen, even under GRUB 2, is a command line prompt with very limited options. Well the first half of the article is universal, at least.

  8. Tswelelopele Tsele says:

    Still doesn’t work. I can’t access root, my command starts with (initramfs)

  9. Marin Todorov says:

    @Eric, if you have an issue with a windows partition, it would be better to use chkdsk windows utility. In Linux, there is fsck.ntfs which is a symlink to ntfsfix.

    ntfsfix is a utility that fixes some common NTFS problems. ntfsfix is NOT a Linux version of chkdsk. It only repairs some fundamental NTFS inconsistencies, resets the NTFS journal file and schedules an NTFS consistency check for the first boot into Windows.

  10. Eric D. says:

    Interesting, but what about an external drive that giving problems running Windows 10? will fsck “fix” that drive as well? And is the syntax the same? (Just point your Linux machine to it and run fsck??)

    • Ravi Saive says:


      I don’t think fsck recognize windows filesystem, never tried it. I think you should give a try and see..:)

    • R. Owen Sterling says:

      If you have the ntfs4g binaries installed, fsck can evaluate and even fix said partitions; that said, Windows specific tools, such as CHKDSK are (for once) less destructive and get better results if you’re trying to preserve as much data as possible.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.