fsck
Check and repair filesystem integrity
TLDR
Check filesystem /dev/sdXN, reporting any damaged blocks
Check filesystem /dev/sdXN, reporting any damaged blocks and interactively letting the user choose to repair each one
Check filesystem /dev/sdXN, reporting any damaged blocks and automatically repairing them
SYNOPSIS
fsck [-ANRpTV] [-C [fd]] [-t fstype] [filesystem...]
PARAMETERS
-A
Check all filesystems listed in /etc/fstab.
-N
Don't execute, just show what would be done.
-R
Skip the root filesystem when using -A (only for mountall).
-p
Automatically repair filesystems without user intervention (preen mode).
-y
Assume 'yes' to all questions; dangerous, use with caution.
-n
Assume 'no' to all questions; read-only mode.
-t fstype
Specify the filesystem type to check. Examples: ext4, xfs, btrfs, vfat.
-V
Show the version of fsck.
-C [fd]
Display completion/progress bars. Requires -t and only works for some filesystem types.
filesystem...
The filesystem(s) to check, specified by device name (e.g., /dev/sda1) or mount point (e.g., /).
DESCRIPTION
The fsck command (file system consistency check) is a crucial utility in Linux and other Unix-like operating systems.
It's designed to examine and repair inconsistencies or errors within a filesystem. Filesystems can become corrupted due to various reasons, including improper shutdowns, hardware failures, software bugs, or power outages. When a filesystem is inconsistent, it can lead to data loss, system instability, or even prevent the system from booting. fsck analyzes the filesystem's metadata and data structures, looking for anomalies such as orphaned inodes, cross-linked files, directory corruption, and incorrect block counts. If errors are found, fsck attempts to repair them, often requiring user intervention to make critical decisions. It is typically run automatically at boot time if the system detects a potentially corrupted filesystem or if the filesystem's 'needs check' flag is set. While fsck is a powerful tool, it's essential to back up your data before running it, as incorrect repairs can potentially lead to further data loss. The command's behavior and options can vary slightly depending on the specific filesystem type (e.g., ext4, XFS, Btrfs) being checked.
CAVEATS
Running fsck on a mounted filesystem can lead to severe data corruption. Always unmount the filesystem before running fsck unless you are absolutely certain it is safe to do so. Use extreme caution when using -y flag, as it bypasses confirmation prompts and automatically attempts repairs, which could potentially lead to data loss if the repairs are not correct. Different filesystem types have different fsck implementations, and their behavior and error handling might vary.
EXIT CODES
fsck returns various exit codes indicating the status of the filesystem check. Common codes include 0 (no errors), 1 (errors corrected), 2 (system should be rebooted), 4 (filesystem errors left uncorrected), 8 (operational error), 16 (usage or syntax error), 32 (fsck canceled by user), 128 (shared library error).
FILESYSTEM SPECIFIC TOOLS
While fsck is a general front-end, specific filesystem types often have their own dedicated tools (e.g., e2fsck for ext2/3/4, xfs_repair for XFS, btrfs check for Btrfs). These tools often offer more specific and advanced options for checking and repairing their respective filesystems.
HISTORY
The fsck command has been a fundamental part of Unix-like operating systems since their inception. It evolved alongside filesystem development, adapting to new filesystems and error correction techniques. Early versions were simpler, while modern versions are more sophisticated and offer more features. The command is not developed by only one entity, but by many developers as part of different implementations.