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 Directory Structure Explained: Purpose of Major Directories

Linux Directory Structure Explained: Purpose of Major Directories

Understand the purpose of major Linux directories such as /etc, /var, /usr, /home, /proc, and /sys, and learn where common system files belong.

Linux dpkg Command: Inspect and Install Local DEB Packages

Linux dpkg Command: Inspect and Install Local DEB Packages

Learn how to inspect and Install Local DEB Packages with the Linux dpkg command, including practical examples, key options, and important precautions.

Linux tree Command: Display a Directory Tree

Linux tree Command: Display a Directory Tree

Learn how to use the Linux tree command to display directory contents as a readable hierarchy and control depth and filtering, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux Tutorial / Install and Update Packages with APT and DNF

Linux Tutorial / Install and Update Packages with APT and DNF

Compare APT on Debian or Ubuntu with DNF on Rocky Linux for searching, installing, updating, and removing packages, including repository and transaction checks.

Linux csplit Command: Split Files at Lines or Patterns

Linux csplit Command: Split Files at Lines or Patterns

Learn how to split Files at Lines or Patterns with the Linux csplit command, including practical examples, key options, and important precautions.

Linux bzip2 Command: Compress a File in bzip2 Format

Linux bzip2 Command: Compress a File in bzip2 Format

Learn how to compress a File in bzip2 Format with the Linux bzip2 command, including practical examples, key options, and important precautions.

Linux pacman Command: Manage Packages on Arch Linux

Linux pacman Command: Manage Packages on Arch Linux

Learn how to manage Packages on Arch Linux with the Linux pacman command, including practical examples, key options, and important precautions.

Linux top Command: Monitor Processes in Real Time

Linux top Command: Monitor Processes in Real Time

Learn how to monitor Processes in Real Time with the Linux top command, including practical examples, key options, and important precautions.

Linux passwd Command: Change a User Password

Linux passwd Command: Change a User Password

Learn how to change a User Password with the Linux passwd command, including practical examples, key options, and important precautions.

Linux mkdir Command: Create Directories and Parent Paths

Linux mkdir Command: Create Directories and Parent Paths

Learn how to create directories with Linux mkdir, build missing parent paths, set permissions, understand umask behavior, and verify results in scripts.