$ run as a normal user# run as root (or with sudo)
The quick answer
journalctl -k -b | grep -iE 'ext4-fs error|xfs.*(error|corrupt)|i/o error'
umount /data
xfs_repair -n /dev/sdb1
xfs_repair /dev/sdb1
e2fsck -f -n /dev/sdc1
e2fsck -f -y /dev/sdc1
mount /dataStep by step
- Read the errors (line 1) —
I/O erroron the device usually means a hardware or storage problem, not only a file system problem. Check the disk first (smartctl -a, cloud storage status). - Back up first if the data matters and you can still read it (
rsync, or a disk snapshot in the cloud). A repair can delete damaged files. - Unmount (line 2) — never repair a mounted file system. "target is busy" → find the users with
lsof +f -- /dataorfuser -vm /dataand stop them. - XFS — first a dry run (
-n, changes nothing), then the repair. Ifxfs_repairsays the log must be replayed, mount and unmount once; usexfs_repair -L(throws away the log, can lose recent changes) only as the last step. - ext4 —
-fforces a full check,-nanswers "no" to everything (dry run),-yrepairs. Lost pieces end up inlost+foundon that file system. - The root file system — it cannot be unmounted while running. Boot into the rescue/emergency target or a rescue ISO and repair from there; or add
fsck.mode=forceto the kernel line once (ext4 is then checked at boot; XFS is not checked at boot, usexfs_repairfrom rescue). - Remount and verify (last line) — check the app data, look into
lost+found, and watch the kernel log for new errors. - Find the cause — power, a failing disk, a full thin-provisioned storage, an unclean shutdown. Fix that, or it happens again.
Check that it worked
The second run of xfs_repair -n / e2fsck -f -n reports no problems; /data mounts read-write (findmnt -o TARGET,OPTIONS /data shows rw); no new errors in journalctl -k -f while the app works.
Common problems
| Problem | Cause | Fix |
|---|---|---|
contains a mounted filesystem | Still mounted. | umount; for / use rescue mode. |
xfs_repair wants the log replayed | Dirty log after the crash. | Mount and unmount once; -L only as the last step. |
| Errors come back after repair | Failing disk or storage problem. | smartctl, storage logs; move data to a new disk. |
| File system mounted read-only by itself | Kernel found errors (errors=remount-ro). | Stop the app, unmount, repair; check the disk. |
| Files missing after repair | Damaged files moved or removed. | Look in lost+found; restore from backup. |
e2fsck on XFS does nothing useful | Wrong tool. | Check the type with lsblk -f; use xfs_repair for XFS. |
Go further
- Command pages: fsck, xfs_repair, tune2fs, dmesg.
- Next how-tos: Check the health of a disk, See which files a process has open, Back up a server with restic, Reset a lost root password on RHEL.
- Learn it: RHCSA — File system problems, RHCSA — Rescue target, RH134 — Repair at boot.
1Why must a file system be unmounted before repair?
The repair tool changes metadata directly; if the system writes at the same time, the damage gets worse.
2What does the -n option of xfs_repair and e2fsck do?
It only checks and reports; nothing is changed on the disk.