How to use fsck - Quick Answer

Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

What is fsck?

fsck, short for file system consistency check, is a utility that examines the file system for errors and attempts to repair them if possible. It uses a combination of built-in tools to check the disk and generates a report of its findings.

On some systems, fsck runs automatically after an unclean shutdown or after a certain number of reboots.

When to Use fsck

Use fsck to check your file system if your system fails to boot, if files on a specific disk become corrupt, or if an attached drive does not act as expected.

Note
To run this utility you will want to boot into rescue mode. Please see our Troubleshooting Guide: Booting into Rescue Mode for guidance.

Verify Disks are Unmounted

  1. Verify that the disks you wish to check are unmounted. You risk corrupting your file system and losing data if you run fsck on an active disk. To do this, enter the following command:

    df -h
    
  2. You will see a similar output:

    root@ttyS0:~# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    tmpfs           739M 1016K  738M   1% /media/ramdisk
    /dev/sdh        160M  160M     0 100% /media/sdh
    /dev/loop0      146M  146M     0 100% /media/compressed_root
    unionfs         739M 1016K  738M   1% /
    devtmpfs         10M     0   10M   0% /dev

    Your primary disks should not appear in the list. As long as your device does not appear in the example output from the df -h command, you can run a filesystem check on it.

How to Check for Errors on a Disk

Caution
Never run fsck on a mounted disk. Do not continue unless you’re sure that the target disk is unmounted. You risk corrupting your file system and losing data if you run fsck on an active disk.

Run fsck on the target disk, using the desired options. This example checks all file systems (-A) on /dev/sdb:

fsck -A /dev/sdb

fsck Options and Arguments

OptionAction
-ACheck all disks listed in /etc/fstab.
-MSkip mounted file systems.
-NTest run. Describes what would happen without executing the check itself.
-PUse with the -A option to run multiple checks in parallel.
-RIf using the -A option, do not check the root filesystem.
-tCheck only a specific type of filesystem.
-yInteractive repair mode.

Understand fsck Error Codes

The error codes that fsck returns can be understood with the following table from man7.org:

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

Use fsck to Repair File System Errors

Use the -r option to use the interactive repair option.

This example uses fsck to check all file systems except the root, and will attempt repair using the interactive feature:

fsck -AR -y

To check and attempt to repair any errors on /dev/sdb, use this format:

fsck -y /dev/sdb

What if fsck Gets Interrupted?

If fsck gets interrupted, it will complete any checks in process, but will not attempt to repair any errors it finds.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.