Advanced
Searching inHow-to guides
How to search
  • Type the task in your own words (find port, open firewall, disk full) or paste an error message in quotes.
  • Choose "Quick answer" to see only the commands, or an area to stay in one field.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

How-to 216System · Storage

How to repair a file system after a crash

After a power cut the server stops at boot with "Give root password for maintenance", or the kernel log shows EXT4-fs error / XFS … metadata I/O error, or a file system turned read-only. The repair tools — e2fsck for ext4, xfs_repair for XFS — fix the metadata, but they must run on an unmounted file system, and first you should know whether the disk itself is dying. This how-to does the checks in a safe order.

  • 5 Lessons
  • 13 Commands

$ run as a normal user# run as root (or with sudo)

216.1

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 /data

216.2

Step by step

  1. Read the errors (line 1) — I/O error on the device usually means a hardware or storage problem, not only a file system problem. Check the disk first (smartctl -a, cloud storage status).
  2. 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.
  3. Unmount (line 2) — never repair a mounted file system. "target is busy" → find the users with lsof +f -- /data or fuser -vm /data and stop them.
  4. XFS — first a dry run (-n, changes nothing), then the repair. If xfs_repair says the log must be replayed, mount and unmount once; use xfs_repair -L (throws away the log, can lose recent changes) only as the last step.
  5. ext4 — -f forces a full check, -n answers "no" to everything (dry run), -y repairs. Lost pieces end up in lost+found on that file system.
  6. 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=force to the kernel line once (ext4 is then checked at boot; XFS is not checked at boot, use xfs_repair from rescue).
  7. Remount and verify (last line) — check the app data, look into lost+found, and watch the kernel log for new errors.
  8. Find the cause — power, a failing disk, a full thin-provisioned storage, an unclean shutdown. Fix that, or it happens again.

216.3

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.

216.4

Common problems

ProblemCauseFix
contains a mounted filesystemStill mounted.umount; for / use rescue mode.
xfs_repair wants the log replayedDirty log after the crash.Mount and unmount once; -L only as the last step.
Errors come back after repairFailing disk or storage problem.smartctl, storage logs; move data to a new disk.
File system mounted read-only by itselfKernel found errors (errors=remount-ro).Stop the app, unmount, repair; check the disk.
Files missing after repairDamaged files moved or removed.Look in lost+found; restore from backup.
e2fsck on XFS does nothing usefulWrong tool.Check the type with lsblk -f; use xfs_repair for XFS.

216.5

Go further

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.

All commands in this chapter