Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

xfs_repair

Check and repair a damaged XFS file system (it must be unmounted).

Level
RHCSA exam
Group
Disks and file systems
Needs root
Yes
Package
xfsprogs

What it does

XFS repairs itself after a crash by replaying its log at mount time. When the file system is really damaged (mount fails, kernel shows XFS corruption), run xfs_repair on the unmounted device. -n only checks. -L throws away the log — a last resort that can lose recent changes.

fsck.xfs exists but does nothing; use xfs_repair.

How to write it

xfs_repair [OPTION]... DEVICE

Options 14

Most used

-n
No modify: only check and report.
-L
Zero the log (when it cannot be replayed; may lose data).
-v
Verbose (repeat for more).
-e
Exit with 4 if something was repaired.
-d
Repair a read-only mounted file system (dangerous; for the root FS in rescue).
-f
The device is an image file.
-l LOGDEV
External log device.
-r RTDEV
Realtime device.
-m MAXMEM
Memory limit in MiB.
-P
Do not prefetch (slower, for problems).
-c SUBOPT=VALUE
Change features during repair (like lazycount).
-o SUBOPT[=VALUE]
Advanced options (bhash, ag_stride …).
-t INTERVAL
Progress report interval.
-V
Show the version.

Examples 10

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

  1. 1Check only

    umount /data
    xfs_repair -n /dev/vgdata/lvdata

    Exit code 1 = problems found.

  2. 2Repair

    xfs_repair /dev/vgdata/lvdata

    Then mount again.

  3. 3Dirty log error

    xfs_repair /dev/vgdata/lvdata
    ERROR: The filesystem has valuable metadata changes in a log which needs to be replayed. Mount the filesystem to replay the log, and unmount it before re-running xfs_repair.

    Mount and unmount first.

  4. 4Log cannot be replayed

    xfs_repair -L /dev/vgdata/lvdata

    Last resort: recent changes in the log are lost.

  5. 5Root file system from a rescue disk

    xfs_repair /dev/mapper/rhel-root

    Do not mount it in the rescue environment first.

  6. 6Mounted? It refuses

    xfs_repair /dev/vdb1
    xfs_repair: /dev/vdb1 contains a mounted filesystem

    Unmount it.

  7. 7Find lost files after a repair

    ls /data/lost+found

    Files without a folder end up here, named by inode number.

  8. 8Repair an image file

    xfs_repair -f /var/tmp/disk.img

    For VM images or copies.

  9. 9Find kernel messages about corruption

    dmesg -T | grep -i xfs

    "Metadata corruption detected" means: plan a repair.

  10. 10Low memory

    xfs_repair -m 1024 /dev/vgdata/lvdata

    Limit memory use on small systems.

Watch out

  • Never repair a mounted file system.
  • Make an image copy (dd) of important damaged disks before repairing.

Exit codes

0No problems (or repaired).
1Problems found (with -n) or errors.
2Dirty log: mount first.
4Something was repaired (with -e).