After an unclean reboot an ext4 filesystem mounts in seconds, and a colleague insists that XFS 'has no fsck'. What actually happens at mount time on each of these filesystems, and how do you repair an XFS filesystem that refuses to mount?
answer
- replay at mount is not a check
- the stub that exits zero
- unmounted, always, for repair
- dry run before you change anything
- zeroing the log discards metadata
basics
~20 sBoth replay their journal at mount, which is why recovery is fast — that is not a full check. XFS really does ship a do-nothing fsck.xfs; genuine repair uses xfs_repair on an unmounted filesystem, with -n to inspect and -L as a data-losing last resort.
solid answer
~50 sAn unclean shutdown leaves a non-empty log on either filesystem, and the kernel replays it during `mount`, restoring metadata consistency in seconds. That replay is not a consistency check, and neither filesystem verifies your file data. The colleague is half right about XFS: `fsck.xfs` exists purely so generic boot scripts have something to call, and it does nothing and exits successfully. Real repair is `xfs_repair`, which must run on an unmounted filesystem — start with `xfs_repair -n` to report without changing anything. If the log cannot be replayed because it is damaged, `xfs_repair -L` zeroes it, discarding whatever metadata was in flight, which is a genuine last resort. On ext4 the equivalent tool is `e2fsck`, also unmounted, with `-n` to inspect and `-f` to force a full check the journal would otherwise let it skip.
code
bash · 3 linesxfs_repair -n /dev/sdb1
mount /dev/sdb1 /mnt && umount /mnt
xfs_repair /dev/sdb1go deeper
Know that a crashed filesystem replays its journal when it is mounted, that repair tools run only on unmounted filesystems, and that XFS uses xfs_repair while ext4 uses e2fsck.
Explain why replay is fast and bounded by the log while a repair pass scales with the filesystem, and describe the fsck.xfs stub, the -n dry run and the ordering rule that the log must be replayed before repair.
Show the incident judgment: replay first, dry run before writing, and treat zeroing the log as a decision with real metadata loss that you record. Say plainly that a clean repair says nothing about your file contents.
Own what happens when repair is not the answer — recovery-time objectives, whether restoring from backup beats a long repair on a large volume, and whether the storage stack's cache-flush behaviour is trustworthy enough for the journal to mean anything.
## Two different operations that people conflate There are two distinct things that can happen to a filesystem after a crash, and the whole question turns on keeping them apart. **Log replay** happens automatically at mount. The filesystem finds its journal non-empty, applies the committed transactions recorded there, and is structurally consistent again. It is fast and its duration is bounded by the size of the log, not the size of the filesystem, which is exactly why a multi-terabyte volume can come back in seconds. **A repair pass** is a full traversal that validates every structure against every other one — do the allocation bitmaps agree with what the inodes claim, does every inode have a directory entry, is every directory entry pointing at a live inode. Its cost scales with the filesystem's contents, and it is only needed when something has gone wrong that the log cannot express: bad hardware, a firmware that lied about flushing its cache, a kernel bug, a volume snapshotted mid-write. After a normal unclean reboot you get the first. The second is an incident. ## What XFS actually does XFS replays its log at mount, and the tool for everything beyond that is `xfs_repair`, which requires the filesystem to be unmounted. The workflow: ``` xfs_repair -n /dev/sdb1 # report only, change nothing umount /srv/data # repair never runs on a mounted filesystem xfs_repair /dev/sdb1 ``` The confusing part — and the origin of "XFS has no fsck" — is `fsck.xfs`. It exists, it is installed, and its documented behaviour is to do nothing and exit with success. That is deliberate: boot-time machinery expects to be able to call `fsck.<type>` for any filesystem listed in fstab, and XFS's answer is "there is nothing useful to do here at boot; mount will replay the log, and if that fails an operator needs to make a decision." A candidate who says "XFS can't be checked" has misread a compatibility stub as an absence of tooling. There is one important ordering rule. `xfs_repair` refuses to work on a filesystem with a dirty log, because the log holds committed metadata it must not discard. The correct move is to mount the filesystem once so the kernel replays the log, unmount it, and then repair. Only if the log itself is damaged and cannot be replayed do you reach for `xfs_repair -L`, which zeroes the log — throwing away every transaction it held. That means real, unrecoverable metadata loss, potentially files or whole directories. It is the option you use when the alternative is restoring from backup anyway, and you note in the incident record that you used it. ## What ext4 does ext4 replays its jbd2 journal at mount in the same way. Its repair tool is `e2fsck`, and the same rule applies: never on a mounted read-write filesystem, because the on-disk state is changing underneath it. ``` e2fsck -n /dev/sdb1 # report only e2fsck -f /dev/sdb1 # force a full check even if the fs looks clean ``` The `-f` matters because `e2fsck` skips the full pass when the superblock says the filesystem is clean, which after a successful journal replay it does. If you actually want the exhaustive traversal — because you suspect the hardware, not the shutdown — you have to ask for it. ext4 also carries the legacy of periodic checking: the maximum mount count and check interval, viewable and adjustable with `tune2fs -l`, `-c` and `-i`, would force a check at boot after so many mounts or so many days. Most distributions disable these now, because an unexpected multi-hour check at boot is worse than the risk it hedges. When `e2fsck` cannot read the primary superblock, ext4's backup superblocks are the recovery path; `mke2fs -n` reports where they are on an existing filesystem without writing anything. ## What neither of them does Neither tool validates your file contents. XFS's v5 on-disk format checksums its *metadata*, so corruption in the filesystem's own structures is detected rather than silently propagated, and ext4 has metadata checksums too — but file data is unchecked on both. A block that flipped a bit under your database's table will be handed back to the application exactly as stored, and no repair pass will notice. That is precisely the guarantee copy-on-write filesystems with data checksums are selling, and it is worth saying so, because it frames what a repair tool is and is not for. It also means a successful `xfs_repair` is not a statement that your data is fine. It is a statement that the filesystem's structure is now self-consistent — which sometimes it achieves by moving orphaned inodes into `lost+found` and letting you work out what they were. ## How to answer Lead with the replay-versus-repair distinction, because that is the actual content of the question. Then explain `fsck.xfs` as the compatibility stub it is, name `xfs_repair` and `e2fsck` as the real tools, insist on unmounted in both cases, and flag `-n` first and `-L` last. Finishing with "and neither of them checks my file data" is what makes the answer sound like it came from someone who has done it at three in the morning.
- Why does fsck.xfs exist at all if it does nothing?So that generic boot-time and fstab machinery, which expects to call a `fsck.<type>` helper for each filesystem it is asked to check, has something to call for XFS and gets a success. XFS's position is that boot is the wrong time to attempt repair: mounting replays the log, and anything beyond that is an operator decision made deliberately with the filesystem unmounted.
- When is xfs_repair -L justified, and what exactly does it cost?Only when the log is damaged badly enough that mounting cannot replay it, so xfs_repair has no other way to proceed. It zeroes the log, discarding every transaction it held — that is real metadata loss, and files or directories can disappear or land in lost+found. Treat it as the step you take when the honest alternative is restoring from backup, and record that you used it.
- Why does e2fsck sometimes finish instantly after a crash, and how do you force the real check?Because journal replay marked the filesystem clean, and e2fsck skips the full traversal on a clean filesystem. Pass `-f` to force all passes regardless of the clean flag. Use `-n` first if you want a read-only report — and in either case make sure the filesystem is unmounted, because checking a mounted read-write filesystem gives meaningless results and can damage it.
- If xfs_repair completes successfully, is my data guaranteed intact?No. It guarantees the filesystem's structures are self-consistent, sometimes by relocating inodes it could not attach to a directory into lost+found. Neither XFS nor ext4 checksums file data, so a corrupted block inside a file is returned to the application unchanged and no repair pass will flag it. Data integrity at that level needs checksumming in the filesystem or in the application.
saying these in an interview costs you the question
- Believes XFS genuinely has no repair tooling
- Runs e2fsck or xfs_repair on a mounted filesystem
- Treats journal replay at mount as a full consistency check
- Reaches for xfs_repair -L before trying to replay the log
- Assumes a clean repair means the file contents are correct