Quick take: The fsck command checks and repairs filesystems. Run it only on an unmounted filesystem: sudo fsck /dev/sdX1. Add -y to auto-answer repair prompts. Never run fsck on a mounted filesystem, as it can cause corruption.

Introduction

The fsck command (filesystem check) inspects a filesystem for errors and repairs them — the tool you reach for after an unclean shutdown or when a disk behaves strangely. Its cardinal rule is that the filesystem must be unmounted first; checking a mounted, actively changing filesystem can make corruption worse.

This guide covers running fsck safely, auto-repairing errors, forcing checks, and scheduling a check at the next boot for the root filesystem.

Syntax

The basic syntax of the fsck command is:

fsck [OPTIONS] DEVICE

Common Options and Parameters

The most useful options and parameters for the fsck command:

OptionDescription
-yAssume yes to all repair prompts.
-nAssume no — check without making changes.
-fForce a check even if the filesystem looks clean.
-ACheck all filesystems listed in /etc/fstab.
-CShow a progress bar.
-t TYPESpecify the filesystem type.
-rInteractive repair (ask before fixing).

Practical Examples

Real fsck commands you can run today:

# Check an unmounted partition
sudo fsck /dev/sdb1
# Check and auto-repair
sudo fsck -y /dev/sdb1
# Force a check even if clean
sudo fsck -f /dev/sdb1
# Dry run without changes
sudo fsck -n /dev/sdb1
# Unmount before checking
sudo umount /dev/sdb1
# Schedule a check of root at next boot
sudo touch /forcefsck

Tips and Best Practices

  • Always unmount the filesystem first (umount); running fsck on a mounted filesystem risks serious corruption.
  • You cannot unmount the root filesystem while running — schedule a check at boot with sudo touch /forcefsck (or use a live USB).
  • Use -n for a safe, read-only check first to see what is wrong before letting fsck repair with -y.

Final Thoughts

fsck finds and fixes filesystem errors, but only safely on an unmounted filesystem. Unmount first, optionally do a read-only pass with -n, then repair with -y. For the root filesystem, schedule the check at boot rather than running it live. Used correctly after an unclean shutdown, fsck restores a damaged filesystem to health.

FAQ: fsck Command in Linux

How do I check a filesystem with fsck?+

Unmount the filesystem, then run sudo fsck /dev/sdX1. Add -y to automatically repair errors, or -n for a read-only check that reports problems without changing anything.

Why must the filesystem be unmounted for fsck?+

fsck modifies on-disk structures, and if the filesystem is mounted and changing at the same time, the repairs can conflict and cause further corruption. Always umount first.

How do I run fsck on the root filesystem?+

You cannot unmount root while running. Schedule a check at the next boot with sudo touch /forcefsck and reboot, or boot from a live USB and run fsck on the root partition from there.

What does fsck -y do?+

It answers yes to every repair prompt, fixing errors automatically without interaction. Use it when you want an unattended repair, but consider a read-only -n pass first to see the issues.

How do I force fsck to run on a clean filesystem?+

Use -f: sudo fsck -f /dev/sdX1 forces a full check even when the filesystem is marked clean, which is useful for verifying a suspect disk.

Need help with Linux servers or infrastructure?

Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.

Hire Me for Support