LinuxCommandLibrary

fsck

Check and repair filesystem integrity

TLDR

Check filesystem /dev/sdXN, reporting any damaged blocks

$ sudo fsck [/dev/sdXN]
copy

Check filesystem /dev/sdXN, reporting any damaged blocks and interactively letting the user choose to repair each one
$ sudo fsck -r [/dev/sdXN]
copy

Check filesystem /dev/sdXN, reporting any damaged blocks and [a]utomatically repairing them
$ sudo fsck -a [/dev/sdXN]
copy

SYNOPSIS

fsck [-AacnPrsvVy] [-b superblock] [-C [fd]] [-E exttype[,options]] [-f] [-l] [-M] [-N] [-P] [-R] [-T fstype] [-t fstype[,...]] device

PARAMETERS

-a
    Automatically repair filesystem (preen mode).

-A
    Check all filesystems listed in /etc/fstab.

-c
    Check bad blocks (not all fsck backends).

-C [fd]
    Display progress bar to descriptor fd (default stderr).

-f
    Force check even if filesystem clean.

-l
    List filesystems and exit.

-M
    Skip already-mounted filesystems.

-N
    Dry run: show actions without executing.

-n
    Read-only check, no modifications.

-P
    Check parallel on multi-core systems.

-p
    Same as -a (preen).

-r
    Interactive repair with prompts.

-R
    Skip / filesystem with -A.

-s
    Serialize checks (single-threaded).

-T fstype
    Assume filesystem type fstype.

-t fstype[,...]
    Limit checks to listed types or exclude with 'no'.

-V
    Verbose mode.

-y
    Answer yes to all prompts automatically.

-b superblock
    Use alternate superblock location.

-E exttype[,options]
    Extended options for fsck.fstype.

DESCRIPTION

fsck (file system check) is a standard Linux utility that verifies the consistency of filesystems and repairs detected inconsistencies. It serves as a frontend, dispatching to filesystem-specific checkers like e2fsck for ext2/3/4, fsck.xfs for XFS, or btrfs check for BTRFS based on the detected or specified type.

fsck examines critical metadata structures including superblocks, inode tables, block allocation bitmaps, directory contents, and symbolic links. It is automatically invoked during boot by the init system (e.g., systemd) if a filesystem is marked 'dirty' after an unclean unmount, power failure, or crash.

Manual use requires unmounting the target filesystem to prevent corruption. Options control behavior: automatic repairs (-a, -y), read-only checks (-n), interactive prompts (-r), or dry runs (-N). Journaled filesystems (ext4, XFS) reduce fsck needs but not eliminate them entirely.

For multi-device setups, -A processes all fstab entries. Parallel checks (-P) speed up operations on multi-core systems. Always back up data before repairs, as fsck may reclaim lost blocks or delete orphaned inodes, potentially causing data loss.

CAVEATS

Critical: Never run on mounted read-write filesystems—use -n for read-only or unmount first. Repairs can delete files, reclaim blocks, or cause data loss. Backup data before using. Journaled FS may refuse checks if mounted. Root FS requires boot media for repairs.

EXIT CODES

0: No errors.
1: Corrected errors.
2: Uncorrected errors.
4: fstab/mtab issues.
8: Runtime error.
16: Syntax error.
32+: Backend-specific codes.

PREEN MODE

-a or -p: Automatic, non-interactive repairs for boot-time use. Safe for minor issues; serious problems need manual intervention.

INVOCATION

Run as root. For root FS: boot from live media. Check with blkid or file -s for type.

HISTORY

Originated in AT&T Unix Version 7 (1979) for Berkeley Fast Filesystem (FFS). Ported to Linux in early 1990s via util-linux package. Evolved with filesystem support: ext (1992), ext3 journaling (2001), supporting modern FS like BTRFS/XFS via modular fsck.fstype tools.

SEE ALSO

e2fsck(8), fsck.ext4(8), fsck.xfs(8), btrfs(8), mkfs(8), tune2fs(8), mount(8)

Copied to clipboard