fsck
Overview
fsck checks and repairs filesystems. It is a front-end that runs type-specific tools (fsck.ext4, fsck.xfs is limited, etc.). Never run a destructive check on a mounted read-write filesystem.
Syntax
fsck [options] [-t type] [device|mountpoint...]
fsck.ext4 [options] deviceCommon Options
| Option | Description |
|---|---|
-t type |
Filesystem type |
-A |
All filesystems from fstab |
-R |
Skip root (with -A) |
-M |
Skip mounted |
-N |
Dry-run (show what would run) |
-y |
Assume yes to repairs |
-n |
Assume no (report only; ext*) |
-f |
Force check even if clean |
-C |
Progress (ext*) |
-V |
Verbose |
Safety
- Identify device with
lsblk -f/blkid.
- Unmount:
sudo umount /dev/sdXN(or boot rescue/maintenance mode for root).
- Prefer read-only report before
-y.
- XFS: use
xfs_repairon unmounted devices;fsck.xfsis mostly a no-op.
- Backups matter — repair can discard corrupt data.
Examples with Explanations
Report-only on unmounted ext4
sudo umount /mnt/data
sudo fsck -n /dev/sdb1
# or
sudo e2fsck -n /dev/sdb1Repair with prompts
sudo fsck -f /dev/sdb1Auto-yes (careful)
sudo fsck -y /dev/sdb1Force ext4 check
sudo e2fsck -f -y /dev/sdb1Dry-run which helpers would run
sudo fsck -N -ARoot filesystem
Boot into recovery/single-user or live USB; root must not be RW-mounted. Systemd may offer fsck on boot when unclean shutdown bits are set.
Exit codes (bitmask)
| Bit | Meaning |
|---|---|
| 0 | Clean |
| 1 | Errors corrected |
| 2 | Reboot required |
| 4 | Uncorrected errors |
| 8 | Operational error |
| 16 | Usage error |