Home > Package & System Management > fsck

fsck: File System Consistency Check and Repair

The `fsck` command is used to check the consistency of a file system and repair damaged parts. It can also run automatically to prevent file system corruption when a system shuts down abnormally. It is primarily used for troubleshooting boot issues or checking for disk errors.

Overview

fsck (file system check) is a tool used to check the structural integrity of file systems stored on disk partitions and attempt repairs if necessary. If a system shuts down unexpectedly due to a power failure or hardware error, file system metadata (inodes, superblocks, etc.) can become corrupted. fsck detects and repairs such damage, restoring the file system to a normal state. If `mkfs` is a tool for creating file systems, `fsck` can be considered a tool for maintaining them.

Key Features

The main features of the `fsck` command are as follows:

  • Checks the integrity of file systems.
  • Can repair damaged file systems in interactive or automatic mode.
  • Acts as a frontend that calls specific file system tools like `fsck.ext4`, `fsck.xfs`.
  • Automatically runs at system boot to check for file system corruption.

fsck and fsck.<filesystem>

fsck is a wrapper that calls the appropriate checking tool for a specific file system. For example, `fsck -t ext4 /dev/sda1` is equivalent to running `fsck.ext4 /dev/sda1` internally.

  • fsck.ext4: A tool for checking and repairing ext2/3/4 file systems. Also known as `e2fsck`.
  • fsck.xfs: A tool for checking XFS file systems. Also known as `xfs_repair`.
  • fsck.vfat: A tool for checking FAT file systems.

Key Options

fsck provides the `-t` option to specify the file system type, and various options to control the repair method.

1) Execution Options

Generated command:

Try combining the commands.

Description:

`fsck` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Learn fsck's functionality through various usage examples. **Checking/repairing is only possible when the file system is unmounted.**

Check File System

sudo fsck /dev/sda1

Checks the file system on the `/dev/sda1` partition. It must be unmounted.

Automatic File System Repair

sudo fsck -y /dev/sdb1

Automatically repairs file system errors on the `/dev/sdb1` partition without user confirmation.

Check After Specifying File System Type

sudo fsck -t ext4 /dev/sdc1

Explicitly specifies the `ext4` file system type to check `/dev/sdc1`. This is equivalent to directly calling `fsck.ext4`.

Check All File Systems

sudo fsck -A

Automatically checks all file systems defined in `/etc/fstab`. Performs similar actions to what happens during boot.

Installation

fsck is part of the `util-linux` package and is included by default in most Linux distributions. No separate installation is usually required. However, specific tools for certain file systems might require separate package installations.

Install XFS Tools (Debian/Ubuntu)

sudo apt update
sudo apt install -y xfsprogs

Install ext4 Tools (Debian/Ubuntu)

sudo apt update
sudo apt install -y e2fsprogs

Tips & Cautions

Important points to consider when using the `fsck` command.

Tips

  • fsck **must always be run on an unmounted file system**. Running it on a mounted partition can lead to data corruption or loss. To check the root file system (`/`) of your system, you must boot into single-user mode or use a live CD/USB.
  • While the automatic repair option (`-y`) is convenient, it can delete important data if the damage is severe. Therefore, if you have critical data, it is safer to first check with the `-n` option.
  • Before running `fsck`, you should unmount the target partition using the `umount` command (e.g., `sudo umount /dev/sdb1`).

Related commands

These are commands that are functionally similar or are commonly used together.


Same category commands