System and processes

The fsck command

Checks and repairs the integrity of a filesystem, using the checker for its type.

Syntax

fsck [-y] DISPOSITIVOTry it in the terminal →

Most useful options

-AWalks /etc/fstab and checks all filesystems in one run
-NExecutes nothing: shows what it would do. The safe way to start
-t <tipo>Limits the check to the given types, comma-separated. With a leading no or !, they are excluded
-MDoes not check mounted filesystems and returns 0 for them
-VVerbose output, including the checker commands that run
-yNot an fsck option: it is passed to e2fsck, which answers yes to everything. It can modify the disk
-nAlso not an fsck option: it goes to e2fsck, which opens the filesystem read-only and answers no to everything

Copy-ready examples

$ fsck /dev/sda1checks an unmounted partition. It needs root; if it finds errors, it asks before repairing.

Example output

/dev/sda1: clean, 12345/655360 files, 234567/2621440 blocks
$ sudo fsck -N /dev/sdb1shows the command that would run on the partition, without running it.
$ sudo fsck -A -Nsays what it would check from /etc/fstab, in pass order.
$ sudo fsck -n /dev/sdb1only checks: opens the partition read-only and changes nothing.
$ sudo umount /dev/sdb1 && sudo fsck /dev/sdb1unmounts the partition and checks it. Without -y, the checker asks before each repair.
$ sudo fsck -y /dev/sdb1warning: answers yes to every repair without asking. Do it only with a backup and the partition unmounted.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
/dev/sdb1 is mounted.The partition is mounted and e2fsck detects it. If the device is busy, it ends with Cannot continue, aborting. Otherwise, in a terminal it warns about damage and asks whether to continue, even with -y.Unmount it with sudo umount /dev/sdb1 and run fsck again.
fsck: cannot check /dev/sdb1: fsck.ext4 not foundfsck cannot find the fsck.ext4 program in PATH, so it cannot check that partition.Install the filesystem tools (e2fsprogs on Debian and Ubuntu) or check the type with lsblk -f.

Typical mistakes

  • Do not run it on a mounted partition: it can corrupt data. Unmount it first.
  • With -y it answers yes to everything: without a backup, a repair can delete files.
  • Use UUID=... or LABEL=... instead of /dev/sdX: the letters change when other disks are connected.
  • -N executes nothing, while -n does check, but read-only. Do not mix them up.

Differences from similar commands

  • e2fsck: is the checker for ext2, ext3 and ext4 that fsck calls underneath. If you already know the type, you can run it directly.
  • mount: mounts a filesystem for use. fsck should only touch it unmounted or read-only.

FAQ

How often should I use it?

Only when there are signs of corruption or after an abrupt shutdown.

What does exit code 4 mean?

Filesystem errors were left uncorrected. The exit status is a sum of bits: 1 corrected, 2 reboot, 4 uncorrected, 8 operational error.

What is the difference between fsck and e2fsck?

fsck is a front-end: it picks and runs the fsck.type checker. e2fsck is the real checker for ext2, ext3 and ext4.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course