Linux fsck Command: Check and Repair Filesystems

fsck runs filesystem-specific check tools to verify the consistency of a file system and repair it if necessary. You must first check whether the target is in use, as modifying a mounted file system may corrupt data.

What is the fsck command?

fsck is a frontend for filesystem-specific checkers like fsck.ext4. The actual check and repair options vary for each file system. XFS does not recover through the standard fsck path and requires a separate xfs_repair procedure. After confirming the file system type, read the documentation for the corresponding tool.

Basic syntax

sudo fsck [options] [file system]

The installed implementation and options may vary depending on the distribution. Use man fsck to check the description on the current system.

Examples

Check the target and format

First, check the partition to be checked and its mount status.

lsblk -f

Check if it is mounted

If the target is in use, first plan to stop or detach it.

findmnt /dev/sdb1

Read-Only Check Example

This is an example of checking an ext-family file system after unmounting it without making changes.

sudo e2fsck -n /dev/sdb1

Differences Between Check and Automatic Recovery

fsck calls the checker suitable for the file system type. First, it is standard practice to confirm the actual partition and file system type, and to run it on an unmounted target.

lsblk -f
sudo fsck -n /dev/sdb1

-n is a read-only check mode that answers 'no' to prompts, but do not assume it behaves the same on all file systems. For example, checkers in the ext series may output file system status and error counts over multiple lines, and the detailed results may vary depending on the target.

Do not immediately apply automatic recovery options just because errors appear in the check results. Verify the disk status and backups, and follow the recovery procedures specific to each file system. In particular, performing recovery checks on mounted read-write file systems carries a risk of data corruption.

The exit status of fsck may encode more than a simple success or failure: corrected errors, required reboot, and operational failures can use distinct bits. In automation, consult the installed implementation's manual for status codes and filesystem-specific checker options. After any repair, verify the mount and application state.

Main Options and Format

Options/Format Description
-t format Specify the type of file system to check.
-A Checks the file systems specified in the configuration file. The scope is broad.
-N Displays only the commands to be executed and does not perform the check.
-M Skips mounted file systems.
-V Displays detailed execution process.

Precautions when using

Before actual repairs, check recent backups and recovery options, and work in an unmounted state as much as possible. Automatic approval options like fsck -y can modify damaged files differently than expected. Since it is difficult to detach the root file system during normal operation, recovery mode or a live environment may be required. SSD, RAID, and LVM layers also affect the selection of targets.

Frequently Asked Questions

Is it okay to run fsck on a mounted file system?

Running a repair check on a mounted filesystem can corrupt data. Generally, unmount the target filesystem or check it in a recovery environment, and follow the instructions specific to the filesystem type.

Official Documentation

The exact behavior of the options and implementation-specific differences can be found in the official fsck documentation.

More in This Category
Linux Tutorial / Understand Users, Groups, and File Ownership

Linux Tutorial / Understand Users, Groups, and File Ownership

Understand UIDs, GIDs, primary and supplementary groups, and file ownership, then inspect them safely with id, groups, getent, ls, and stat.

Linux mktemp Command: Create Secure Temporary Files and Directories

Linux mktemp Command: Create Secure Temporary Files and Directories

Learn how to create unpredictable temporary files and directories with Linux mktemp, use templates and TMPDIR, clean up with trap, and avoid unsafe dry runs.

Linux sort Command: Sort Text Lines

Linux sort Command: Sort Text Lines

Learn how to sort text lines with the Linux sort command, including practical examples, key options, and important precautions.

Linux du Command: Check File and Directory Disk Usage

Linux du Command: Check File and Directory Disk Usage

Learn how to use the Linux du command to measure and summarize disk space used by files and directories, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux screen Command: Create and Manage Detachable Terminal Sessions

Linux screen Command: Create and Manage Detachable Terminal Sessions

Learn how to use the Linux screen command to keep terminal sessions running and reconnect to them later, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux unzip Command: List and Extract ZIP Archives

Linux unzip Command: List and Extract ZIP Archives

Learn how to list and Extract ZIP Archives with the Linux unzip command, including practical examples, key options, and important precautions.

Linux gunzip Command: Decompress gzip Files

Linux gunzip Command: Decompress gzip Files

Learn how to decompress gzip Files with the Linux gunzip command, including practical examples, key options, and important precautions.

Linux killall Command: Signal Processes by Name

Linux killall Command: Signal Processes by Name

Learn how to signal Processes by Name with the Linux killall command, including practical examples, key options, and important precautions.

Linux paste Command: Join Corresponding Lines Side by Side

Linux paste Command: Join Corresponding Lines Side by Side

Learn how to join Corresponding Lines Side by Side with the Linux paste command, including practical examples, key options, and important precautions.

Linux basename Command: Extract the Final Component of a Path

Linux basename Command: Extract the Final Component of a Path

Learn how to use the Linux basename command to remove directory prefixes and optional suffixes from path strings, with essential options, practical examples, output interpretation, and common troubleshooting tips.