fsck Command in Linux: Check and Repair Filesystems

By 

Updated on

7 min read

Linux Fsck Command

fsck (filesystem check) is a command-line utility for checking and repairing Linux filesystems. It uses filesystem-specific checkers, such as fsck.ext4, depending on the type of filesystem being checked.

You can use fsck when a partition cannot be mounted, a filesystem is marked dirty, or a system fails to boot because of filesystem errors.

Never run fsck on a mounted filesystem. Running repairs on a mounted partition can corrupt data because the filesystem may change while fsck is checking it.

How to Use fsck

The general syntax is:

txt
fsck [OPTIONS] [FILESYSTEM]

Only root or users with sudo privileges can run fsck.

When no FILESYSTEM is provided as an argument, fsck checks the devices listed in the fstab file.

Before attempting to check or repair filesystems, always unmount them first.

The fsck command is a wrapper for the various Linux filesystem checkers (fsck.*) and accepts different options depending on the filesystem’s type.

Check the manual pages for more information about a specific checker. For example, to view the options available for fsck.ext4, type:

Terminal
man fsck.ext4

Safe fsck Workflow

Before repairing a filesystem, identify the device and confirm that it is not mounted.

List block devices and filesystem types:

Terminal
lsblk -f

Check whether the target device is mounted:

Terminal
mount | grep /dev/sdc1

If the command returns a mount point, unmount the filesystem:

Terminal
sudo umount /dev/sdc1

Run a read-only check first:

Terminal
sudo fsck -n /dev/sdc1

The -n option tells fsck to report problems without writing changes. If the check shows repairable errors, run a safe automatic repair:

Terminal
sudo fsck -p /dev/sdc1

Use -p for safe automatic fixes. Use -y only when you are prepared to answer yes to every repair prompt.

Repair Corrupted Filesystem

The simplest use case of the fsck command is to repair a non-root corrupted ext3 or ext4 filesystem.

  1. If you do not know the device name, use lsblk -f, fdisk, df , or another disk utility to find it.

  2. Unmount the device:

    Terminal
    sudo umount /dev/sdc1
  3. Run fsck to repair the filesystem:

    Terminal
    sudo fsck -p /dev/sdc1

    The -p option tells fsck to automatically repair any problems that can be safely fixed without user intervention.

  4. Once the filesystem is repaired, mount the partition:

    Terminal
    sudo mount /dev/sdc1

Repair Root Filesystem

fsck cannot check the root filesystem on a running machine because it cannot be unmounted.

To check or repair the root filesystem, use recovery mode, boot from a live USB or live environment, or force a check during the next boot.

Run fsck in Recovery Mode

  1. Enter the boot menu and choose Advanced Options.
  2. Select Recovery mode and then choose the option to run a file system check.
  3. When prompted to remount the root filesystem, choose “Yes”.
  4. Once done, resume the normal boot.

Run fsck from a Live Environment

  1. Boot from a live USB or another live Linux environment.

  2. Use fdisk or parted to find the root partition name.

  3. Open the terminal and run:

    Terminal
    sudo fsck -p /dev/sda1
  4. Once done, reboot and start your system normally.

Check Filesystems on Boot

On most Linux distributions, fsck runs at boot time if a filesystem is marked as dirty or after a certain number of boots or time.

To see the current mount count, check frequency number, check interval, and the time of the last check for a specific partition, use the tune2fs tool:

Terminal
sudo tune2fs -l /dev/sdc1 | grep -i 'last checked\|mount count'
output
Mount count:              292
Maximum mount count:      -1
Last checked:             Tue Jul 24 11:10:07 2018
Check interval:           0 (<none>)
  • “Maximum mount count” is the number of mounts after which the filesystem will be checked. The value of 0 or -1 means that fsck will never run.
  • “Check interval” is the maximal time between two filesystem checks.

If, for example, you want to run fsck after every 25 boots (mounts), type:

Terminal
sudo tune2fs -c 25 /dev/sdc1

You can also set the maximal time between two checks. For example, to set it one month you would run:

Terminal
sudo tune2fs -i 1m /dev/sdc1

To force fsck to run at boot time on systemd distributions pass the following kernel boot parameters:

txt
fsck.mode=force
fsck.repair=yes

On older distributions fsck will run on boot if the /forcefsck file is present:

Terminal
sudo touch /forcefsck

fstab Options

fstab is a configuration file that tells the system how and where to mount the partitions.

The /etc/fstab file contains a list of entries in the following form:

/etc/fstabsh
# [File System] [Mount Point] [File System Type] [Options] [Dump] [PASS]
/dev/sda1       /             ext4               defaults  0      1
/dev/sda2       /home         ext4               defaults  0      2
server:/dir     /media/nfs    nfs                defaults  0      0

The last, 6th column ([PASS]) is the option that controls the order in which the filesystem checks are done at reboot time.

  • 0 - Do not check.
  • 1 - The filesystems to be checked first and one at a time.
  • 2 - All other filesystems which are checked later and possibly in parallel.

The root filesystem should have a value of 1, and all other filesystems you want to be checked should have a value of 2.

Common fsck Options

Here are the most commonly used fsck options:

  • -a - Automatically repair the filesystem without prompting.
  • -n - Do not make any changes to the filesystem (dry run).
  • -p - Automatically repair problems that can be safely fixed.
  • -y - Answer “yes” to all repair prompts.
  • -f - Force checking even if the filesystem seems clean.
  • -r - Interactively repair the filesystem (prompt for each fix).
  • -t type - Specify the filesystem type (e.g., ext4).
  • -A - Check all filesystems listed in /etc/fstab.

For most manual checks, start with -n, then use -p if repairs are needed. The -y option is more aggressive because it accepts every proposed repair.

Exit Codes

The fsck command returns exit codes that indicate the result of the check:

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

Other Filesystems

The fsck command works primarily with ext2, ext3, and ext4 filesystems. Other filesystems use different tools:

  • XFS - Use xfs_repair instead of fsck
  • Btrfs - Use btrfs check or btrfs scrub
  • NTFS - Use ntfsfix for basic repairs

Troubleshooting

The filesystem is mounted
Unmount the filesystem before running repairs. If it is busy, check which process is using it with lsof or fuser, stop that process, and unmount it again.

The device name is wrong
Use lsblk -f to list devices, filesystems, labels, UUIDs, and mount points. Make sure you are checking the correct partition, not the whole disk.

The root filesystem cannot be unmounted
Boot into recovery mode or use a live USB. The root filesystem cannot be repaired while it is mounted as the active system root.

fsck reports a bad superblock
For ext filesystems, list backup superblocks with sudo mke2fs -n /dev/sdX1, then run fsck with an alternate superblock using -b. Replace /dev/sdX1 with the correct device.

fsck does not repair XFS or Btrfs
Use the filesystem-specific tool. XFS uses xfs_repair, and Btrfs usually uses btrfs scrub or btrfs check.

Quick Reference

For a printable quick reference, see the fsck cheatsheet .

CommandDescription
lsblk -fList devices and filesystem types
sudo umount /dev/sda1Unmount a filesystem before repair
sudo fsck /dev/sda1Check filesystem
sudo fsck -n /dev/sda1Check only, no changes
sudo fsck -p /dev/sda1Auto-repair safe issues
sudo fsck -y /dev/sda1Auto-repair all issues
sudo fsck -f /dev/sda1Force check even if clean
sudo fsck -ARCheck all fstab filesystems except root
sudo tune2fs -c 25 /dev/sda1Check every 25 mounts
sudo tune2fs -i 1m /dev/sda1Check every month

Conclusion

The fsck command checks and repairs Linux filesystems, but it must be used carefully. Identify the correct device, unmount it, run a read-only check first, and use safe repair modes before trying more aggressive options.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page