Two rules, and the rest of this page is detail. Never run a repair pass on a mounted read-write filesystem. Always run the read-only pass first:
findmnt /dev/sdXN # is it mounted? answer this before anything else
sudo fsck -n /dev/sdXN # read-only inspection
sudo umount /dev/sdXN # only if -n found something
sudo fsck /dev/sdXN # repair interactively -- see below before adding -y
e2fsck(8) puts the consequence bluntly: “If e2fsck asks whether or not you should check a file system which is mounted, the only correct answer is “no”. Only experts who really know what they are doing should consider answering this question in any other way.” If the volume in question is /, you cannot unmount it from a running system — that repair belongs on rescue media or in the initramfs, not in your shell. The full triage for the case that usually sends people here, a disk that suddenly cannot be written to, is on the No space left on device page; most of the time fsck is not the answer at all.
What was executed: there is no Linux machine here, so everything ext4-, xfs- and btrfs-specific below is quoted from its own documentation. The refusal and the detect/repair cycle were run on macOS 26.6 against a scratch disk image, using Apple’s HFS+ checker — a different program with the same job and the same flags. It is an illustration of the rule, not a substitute for e2fsck.
What a checker does when the volume is live
A well-behaved checker will not let you make the mistake. On a 32 MB scratch image, mounted read-write, both the read-only form and the repair form refused outright:
$ mount | grep HWFSCK
/dev/disk4s1 on /Volumes/HWFSCK (hfs, local, nodev, nosuid, noowners, nobrowse, mounted by [user])
$ fsck_hfs -n /dev/disk4s1
ERROR: volume /Volumes/HWFSCK is mounted with write access. Re-run with (-l) to freeze volume.
rc=8
$ fsck_hfs -y /dev/disk4s1
ERROR: volume /Volumes/HWFSCK is mounted with write access. Re-run with (-l) to freeze volume.
rc=8
Linux is more permissive: e2fsck will ask, and -y answers the question for you. That is the whole risk. Unmounted, the read-only pass prints its intent on the first line — (NO WRITE) — and after deliberately overwriting 20 KB of the volume it found the damage and refused to touch it:
$ fsck_hfs -n /dev/disk4s1
** /dev/rdisk4s1 (NO WRITE)
** Checking extents overflow file.
Unused node is not erased (node = 23)
...
** The volume HWFSCK was found corrupt and needs to be repaired.
rc=8
Only then is a repair a decision rather than a gamble. The same command without -n printed ** Repairing volume., then ** Rechecking volume., then ** The volume HWFSCK was repaired successfully., and a fresh read-only pass came back clean at rc=0.
-y, -p and -n are three different contracts
All three quotes are from e2fsck(8):
-n— “Open the file system read-only, and assume an answer of “no’ to all questions.” This is your first command, every time.-p— “Automatically repair (“preen”) the file system … automatically fix any file system problems that can be safely fixed without human intervention. If e2fsck discovers a problem which may require the system administrator to take additional corrective action, e2fsck will print a description of the problem and then exit with the value 4 logically or’ed into the exit code.” This is what your boot scripts run, and it is the conservative option: it stops rather than guesses.-y— “Assume an answer of “yes’ to all questions.” Not “fix it properly” — yes to everything, including “should I disconnect this inode from its directory and drop it inlost+found?” On a badly damaged filesystem-yis a faster route to data loss than sitting through the prompts, because every irreversible decision is taken for you at machine speed.
The exit code is a bitmask, not a boolean, which matters if you script this: 0 no errors, 1 errors corrected, 2 errors corrected and the system should be rebooted, 4 errors left uncorrected, 8 operational error, 16 usage error, 32 cancelled by the user, 128 shared library error. A cron job testing only for zero will treat “1 — I silently changed your filesystem” as a pass.
Three corrections to the earlier version of this page
e2fsck is not an alternative to fsck. The old page listed it under “Alternative Tools … for when fsck isn’t working”. fsck(8) says otherwise: “In actuality, fsck is simply a front-end for the various filesystem checkers (fsck.fstype) available under Linux.” Running fsck /dev/sdXN on ext4 is running e2fsck; it dispatches by filesystem type. Nothing is gained by switching, and options you pass to the wrapper are not all understood by the checker behind it.
btrfs check --repair was described as something to “use cautiously”. The btrfs documentation is stronger than that: “Do not use –repair unless you are advised to do so by a developer or an experienced user.” By default btrfs check does not modify the device. Leave it that way and take the output to the btrfs mailing list.
The step table was not a runnable procedure. It listed systemctl isolate rescue.target, then umount /dev/sdXN, then fsck -y. Rescue mode does not unmount the root filesystem, so step 2 fails on the volume people most often want to check, and step 3 skips the -n pass entirely. For root, boot external media or add fsck.mode=force to the kernel command line and let the boot-time -p pass run before the filesystem is mounted read-write.
And the premise underneath all of it: back up before the repair, not after. A checker’s job is to make the filesystem consistent, and it will do that by discarding whatever cannot be reconciled. If the data matters more than the filesystem, image the device first with ddrescue and run the repair against the copy.
Check this yourself. Every command and every block of output on this page is reproduced by /verify/fsck-filesystem-repair.sh. Download it and run it: it creates its own scratch files, prints one line per claim, cleans up after itself, and exits non-zero if any claim here turns out to be wrong. If it disagrees with this page, the page is wrong.