fsck Command in Linux: Check and Repair Filesystems

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:
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:
man fsck.ext4Safe fsck Workflow
Before repairing a filesystem, identify the device and confirm that it is not mounted.
List block devices and filesystem types:
lsblk -fCheck whether the target device is mounted:
mount | grep /dev/sdc1If the command returns a mount point, unmount the filesystem:
sudo umount /dev/sdc1Run a read-only check first:
sudo fsck -n /dev/sdc1The -n option tells fsck to report problems without writing changes. If the check shows repairable errors, run a safe automatic repair:
sudo fsck -p /dev/sdc1Use -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.
If you do not know the device name, use
lsblk -f,fdisk,df, or another disk utility to find it.Unmount the device:
Terminalsudo umount /dev/sdc1Run
fsckto repair the filesystem:Terminalsudo fsck -p /dev/sdc1The
-poption tellsfsckto automatically repair any problems that can be safely fixed without user intervention.Once the filesystem is repaired, mount the partition:
Terminalsudo 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
- Enter the boot menu and choose Advanced Options.
- Select Recovery mode and then choose the option to run a file system check.
- When prompted to remount the root filesystem, choose “Yes”.
- Once done, resume the normal boot.
Run fsck from a Live Environment
Boot from a live USB or another live Linux environment.
Use
fdiskorpartedto find the root partition name.Open the terminal and run:
Terminalsudo fsck -p /dev/sda1Once 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:
sudo tune2fs -l /dev/sdc1 | grep -i 'last checked\|mount count'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
0or-1means thatfsckwill 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:
sudo tune2fs -c 25 /dev/sdc1You can also set the maximal time between two checks. For example, to set it one month you would run:
sudo tune2fs -i 1m /dev/sdc1To force fsck to run at boot time on systemd distributions pass the following kernel boot parameters:
fsck.mode=force
fsck.repair=yesOn older distributions fsck will run on boot if the /forcefsck file is present:
sudo touch /forcefsckfstab 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:
# [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 0The 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:
| Code | Description |
|---|---|
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 |
128 | Shared-library error |
Other Filesystems
The fsck command works primarily with ext2, ext3, and ext4 filesystems. Other filesystems use different tools:
- XFS - Use
xfs_repairinstead offsck - Btrfs - Use
btrfs checkorbtrfs scrub - NTFS - Use
ntfsfixfor 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 .
| Command | Description |
|---|---|
lsblk -f | List devices and filesystem types |
sudo umount /dev/sda1 | Unmount a filesystem before repair |
sudo fsck /dev/sda1 | Check filesystem |
sudo fsck -n /dev/sda1 | Check only, no changes |
sudo fsck -p /dev/sda1 | Auto-repair safe issues |
sudo fsck -y /dev/sda1 | Auto-repair all issues |
sudo fsck -f /dev/sda1 | Force check even if clean |
sudo fsck -AR | Check all fstab filesystems except root |
sudo tune2fs -c 25 /dev/sda1 | Check every 25 mounts |
sudo tune2fs -i 1m /dev/sda1 | Check 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.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

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