fsck(8)
Check and repair a Linux filesystem.
Synopsis
fsck [OPTIONS] [DEVICE]Description
fsck is used to check and optionally repair one or more Linux filesystems. By default, fsck will run the appropriate filesystem-specific checker (fsck.ext4, fsck.xfs, etc.) based on the filesystem type. It can check filesystems on block devices, mount points, or labels.
fsck should only be run on unmounted filesystems or the root filesystem in read-only mode. Running fsck on a mounted filesystem can cause corruption. Most modern systems use automatic filesystem checking at boot time if the system crashed unexpectedly.
Common options
| Flag | What it does |
|---|---|
-t fstype | Specify the filesystem type (ext4, xfs, btrfs, etc.) instead of autodetecting |
-a | Automatically repair the filesystem without prompting (non-interactive mode) |
-n | Open filesystem read-only; do not attempt to repair anything |
-y | Answer yes to all prompts; useful for automated repair |
-c | Check for bad blocks before starting the repair |
-f | Force checking even if filesystem appears clean |
-v | Verbose mode; print details about what is being checked |
-p | Automatically repair problems that can be safely fixed (preen mode) |
-C | Display completion progress bar |
-l file | Add device name to a log file |
Examples
Check /dev/sda1 in read-only mode without making any changes; useful for inspection
sudo fsck -n /dev/sda1Automatically repair /dev/sda1; filesystem must be unmounted first
sudo fsck -a /dev/sda1Force check the ext4 filesystem on /dev/sdb1 and answer yes to all repair prompts
sudo fsck -t ext4 -y /dev/sdb1Check /dev/sda1 for bad blocks and repair any errors found
sudo fsck -c /dev/sda1Check the root filesystem (only safe if booted in single-user or rescue mode)
sudo fsck /Force a check on /dev/sdc1 even if it appears clean, with verbose output
sudo fsck -f -v /dev/sdc1Preen mode: safely fix common problems without prompting (used at boot time)
sudo fsck -p /dev/sda2