xfs_repair(8)
โจ xfs_repair(8) โจ
xfs_repair(8) ๐ from the System Manager's Manual, bestie, this is your official guide ๐
๐ธ NAME ๐ธ
xfs_repair - repair an XFS filesystem ๐งโจ
๐ฆ SYNOPSIS ๐ฆ
xfs_repair [ -dfLPv ] [ -n | -e ] [ -m maxmem ] [ -c subopt=value ] [ -o
subopt[=value] ] [ -t interval ] [ -l logdev ] [ -r rtdev ] device
xfs_repair -V
๐ DESCRIPTION ๐
okay so xfs_repair is the tool that fixes up corrupt or damaged XFS filesystems (go peek at xfs(5) if you want the deep lore) ๐ซถ You point it at the filesystem with the device argument, which should be the device name of the disk partition or volume holding the filesystem. If you hand it a block device, xfs_repair will try to find the raw device behind it and use that one instead ๐ง
Now, the big rule, periodt: the filesystem you're repairing must be unmounted ๐ญ If it isn't, the result could be inconsistent or corrupt, and nobody wants that bestie ๐
๐ OPTIONS ๐
-fโ Tellsxfs_repairthat the filesystem image lives in a regular file at device instead of on a real disk ๐ (see themkfs.xfs -d fileoption). This happens when someone made an image copy of a filesystem or wrote it into an ordinary file. It also means any external log or realtime section is in an ordinary file too ๐-Lโ Force Log Zeroing ๐ This makesxfs_repairzero the log even if it's dirty (aka it has metadata changes waiting to be written). Be warned, the filesystem will probably look corrupt afterwards, and you can lose user files and/or data ๐ญ Check the DIRTY LOGS section for the full tea.-l logdevโ Points to the device special file where the filesystem's external log lives ๐ This only matters for filesystems that use an external log. See themkfs.xfs -loption, and check xfs(5) for the full scoop on the XFS log โจ-r rtdevโ Points to the device special file where the filesystem's realtime section lives ๐ This is only for filesystems that actually use a realtime section. See themkfs.xfs -roption, and peep xfs(5) for a detailed description of the XFS realtime section ๐-nโ No modify mode ๐xfs_repairscans the filesystem and tells you what repairs would have been made, but it won't touch a single thing. Can't be used together with-e๐ โโ๏ธ-Pโ Disables prefetching of inode and directory blocks ๐งธ Use this ifxfs_repairseems stuck and stops making progress. The good news is that interrupting a stuckxfs_repairis safe ๐ซถ-m maxmemโ Sets the approximate maximum amount of memory, in megabytes, thatxfs_repaircan use ๐ง By default,xfs_repairhas its own internal block cache that scales out up to the lesser of the process's virtual address limit or about 75% of the system's physical RAM. This option overrides those limits ๐
NOTE: These memory limits are only approximate, so xfs_repair may end up using more than the number you gave it ๐
-c subopt=valueโ Changes filesystem parameters โ๏ธ For info on changing those, check out xfs_admin(8) ๐ฆ-o subopt[=value]โ Overrides what the program might conclude about the filesystem if it were left to its own devices ๐ The suboptions you can use are:bhash=bhashsizeโ Overrides the default buffer cache hash size ๐ซง The total number of buffer cache entries is capped at 8 times this amount. By default, the size is set to use up the remainder of 75% of the system's physical RAM size ๐ag_stride=ags_per_concat_unitโ Creates extra processing threads so AGs that span multiple concat units can be processed in parallel ๐งต This can seriously cut down repair times on concat based filesystems ๐ฅforce_geometryโ Checks the filesystem even if its geometry information couldn't be validated ๐ Geometry info can't be validated if only a single allocation group exists (so there's no backup superblock available), or if there are two allocation groups and the two superblocks don't agree on the geometry. Only use this if you validated the geometry yourself and know exactly what you're doing ๐ค If in doubt, run in no modify mode (-n) first.noquotaโ Doesn't validate quota counters at all ๐งพ Quotacheck will run during the next mount to recalculate all the values ๐ธ
-t intervalโ Changes the reporting interval, specified in seconds โฑ๏ธ On long runs,xfs_repairoutputs its progress every 15 minutes. Reporting is only activated whenag_strideis enabled ๐ฃ-vโ Verbose output ๐ข You can repeat it to crank the verbosity even higher ๐-dโ Repair dangerously ๐ This letsxfs_repairrepair an XFS filesystem that's mounted read only. It's typically done on a root filesystem from single user mode, and then you reboot immediately after ๐
This one is risky business, bestie. Only do it the way described above ๐
-eโ If any metadata corruption got repaired, the exit status is 4 instead of the usual 0 ๐ฆ This can't be used together with-n๐ โโ๏ธ-Vโ Prints the version number and exits ๐ท๏ธ
๐ Checks Performed ๐
slay, before it even looks at the filesystem, xfs_repair tests whether the crc32c checksum implementation is correct ๐งช If that test fails, the program aborts, so you'll know something's sus right away ๐จ
Here's the list of inconsistencies it can fix:
- Inode and inode blockmap (addressing) checks ๐ฆ Bad magic number in an inode, bad magic numbers in inode blockmap blocks, extents out of order, the wrong number of records in inode blockmap blocks, blocks claimed that aren't in a legal data area of the filesystem, and blocks claimed by more than one inode ๐ญ
- Inode allocation map checks ๐บ๏ธ Bad magic number in inode map blocks, inode state (free or in-use) in the map not matching the state in the inode, inodes referenced by the filesystem that don't show up in the inode allocation map, and an inode allocation map referencing blocks that don't seem to contain inodes ๐
- Size checks ๐ Number of blocks claimed by an inode not matching its size, directory size not being block aligned, and inode size not being consistent with the inode format ๐งธ
- Directory checks ๐ Bad magic numbers in directory blocks, the wrong number of entries in a directory block, bad freespace info in a directory leaf block, an entry pointing to an unallocated (free) or out of range inode, overlapping entries, missing or incorrect dot and dotdot entries, entries out of hashvalue order, incorrect internal directory pointers, and a directory type that doesn't match the inode format and size ๐
- Pathname checks ๐ค๏ธ Files or directories not referenced by a pathname starting from the filesystem root, and illegal pathname components ๐ โโ๏ธ
- Link count checks ๐ Link counts that don't agree with the number of directory references to the inode ๐งฎ
- Freemap checks ๐งบ Blocks claimed free by the freemap but also claimed by an inode, and blocks unclaimed by any inode that don't show up in the freemap ๐ซ
- Super Block checks ๐ Total free block and/or free i-node count being incorrect, filesystem geometry being inconsistent, and secondary and primary superblocks contradicting each other ๐
Orphaned files and directories (allocated and in-use, but unreferenced) get reconnected by being placed in the lost+found directory ๐ง The name they're given is the inode number ๐ข
๐งฏ Disk Errors ๐งฏ
xfs_repair aborts on most disk I/O errors ๐ฑ So if you're trying to repair a filesystem that got damaged by a disk drive failure, make sure every block in the filesystem is readable and writable before you run xfs_repair ๐ซถ One method is using dd(8) to copy the data onto a good disk ๐พ
๐ lost+found ๐
The lost+found directory doesn't have to exist already ๐ฅฐ If it's missing and needed, it gets created automatically โจ If it's already there, it gets checked for consistency, and if it's valid it'll be used for additional orphaned files ๐ธ Invalid lost+found directories get removed and recreated ๐ โโ๏ธ Existing files in a valid lost+found are never removed or renamed, so your stuff stays safe ๐ซถ
๐ Corrupted Superblocks ๐
XFS has both primary and secondary superblocks ๐ง xfs_repair uses the info in the primary superblock to automatically find the secondary superblocks and validate the primary against them before moving on ๐ If the primary is too corrupted to be useful for finding the secondary superblocks, the program scans the filesystem until it finds and validates some secondary superblocks ๐ต๏ธโโ๏ธ At that point, it generates a primary superblock ๐ฆธโโ๏ธ
๐งพ Quotas ๐งพ
If quotas are in use, xfs_repair might clear some or all of the filesystem quota information ๐ฌ If that happens, the program issues a warning just before it terminates ๐จ If all the quota information gets lost, quotas are disabled and the program issues a warning to that effect ๐
Also, xfs_repair doesn't check the validity of quota limits ๐ So it's recommended that you check the quota limit information manually after running xfs_repair ๐ Space usage info is automatically regenerated the next time the filesystem is mounted with quotas turned on, so that next quota mount may take some time โณ
๐ DIAGNOSTICS ๐
okay so xfs_repair talks to you the whole time it's working โจ it tells you what's looking sus, or what it fixed. Most messages only make sense if you already know the filesystem's insides, so I'm highlighting the common ones ๐
Also, the wording changes a little in no-modify mode (-n) because nothing gets touched on disk ๐ In that mode it tells you what it would do if you ran it without -n.
disconnected inode ino, moving to lost+found
Inode ino wasn't hooked up to the directory tree anymore, so xfs_repair reconnected it inside lost+found ๐ง It gets named after its inode number (ino). If there's no lost+found directory yet, it makes one for you automatically ๐ซถ
disconnected dir inode ino, moving to lost+found
Same drama, but this time it's a directory inode ๐ Any children it has stay attached to it, so they get reconnected automatically when the directory does โจ
imap claims in-use inode ino is free, correcting imap
The inode allocation map says inode ino is free, but when xfs_repair checks the inode it looks like it might be in use (even if it's disconnected). So it fixes the allocation map ๐ ๏ธ
imap claims free inode ino is in use, correcting imap
Flip side: the allocation map says inode ino is in use, but the inode itself says it's free. It updates the allocation map to match ๐
resetting inode ino nlinks from x to y
xfs_repair noticed the number of valid directory entries pointing at inode ino doesn't match the link count stored in the inode, so it corrected the count ๐
fork-type fork in ino ino claims used block bno
Inode ino is trying to claim block bno, but that block is already claimed by another inode or by the filesystem's own metadata ๐ The fork-type will be either data or attr, which tells you whether the problem is in the regular data part of the inode or the XFS attributes part. If it's a real-time (rt) inode, the message says so. Any inode claiming blocks the filesystem already uses gets deleted, and if two or more inodes claim the same block, they all get deleted ๐
fork-type fork in ino ino claims dup extent ...
Inode ino has a block sitting in an extent that's known to be claimed more than once ๐ The message gives you the offset in the inode, plus the start and length of the extent. It reads a little differently if the inode is a real-time (rt) inode, since the extent is then a real-time (rt) extent ๐ธ
inode ino - bad extent ...
An extent record in inode ino's blockmap is claiming blocks outside the legal range of the filesystem ๐ญ The message tells you the start, end, and file offset of that extent. It's worded a bit differently if the extent is a real-time (rt) extent โจ
bad fork-type fork in inode ino
Something is structurally wrong or inconsistent in the data structures that map offsets to filesystem blocks ๐ฅฒ
cleared inode ino
Something was wrong with inode ino that couldn't be fixed, so xfs_repair freed it ๐๏ธ This usually happens when the inode claims blocks someone else is using, or when the inode itself is badly corrupted. Usually a few messages about why show up right before this one.
bad attribute fork in inode ino, clearing attr fork
The attribute fork of inode ino (the part that stores XFS attributes) had a problem, so xfs_repair reset it ๐ That means all attributes on that inode are lost.
correcting nextents for inode ino, was x - counted y
xfs_repair found that the number of extents used to store the inode's data was wrong, so it fixed the number ๐ง If the miscount is about attribute storage, the message says nextents anyway, which is a little confusing but that's the vibe ๐
entry name in dir dir_ino not consistent with .. value (xxxx) in dir ino ino, junking entry name in directory inode dir_ino
Directory inode dir_ino has an entry name pointing at directory inode ino. But the .. entry inside directory ino doesn't point back at dir_ino, so the entry name in dir_ino gets deleted ๐๏ธ If directory ino ends up disconnected because of this, it gets moved to lost+found later on.
entry name in dir dir_ino references already connected dir ino ino, junking entry name in directory inode dir_ino
The entry name in dir_ino points at directory inode ino, which is already a child of some other directory. So the entry is invalid and gets deleted ๐
โโ๏ธ This message is for a small directory. If it were a large directory, the ending would say will clear entry instead.
entry references free inode ino in directory dir_ino, will clear entry
An entry in directory inode dir_ino points at inode ino, which is known to be free. The entry is invalid, so it gets deleted ๐งน This message is for a large directory. In a small directory it would say junking entry ... instead.
๐ฆ EXIT STATUS ๐ฆ
Here's the status code breakdown, bestie ๐ซถ
xfs_repair -n (no-modify mode) returns 1 if it detected filesystem corruption, and 0 if it didn't.
Without -n, xfs_repair returns 0 if it finishes without problems, unless you used the -e flag. With -e, it returns 4 when it found an issue with the filesystem that it could fix โจ
If xfs_repair hits a runtime error while it's working, it returns 1. In that case, you should restart xfs_repair ๐
If xfs_repair can't continue because of a dirty log, it returns 2. See below for the dirty log tea โ
๐ DIRTY LOGS ๐
Because of how the XFS log is designed, a dirty log can only be replayed by the kernel, on a machine with the same CPU architecture as the one that wrote to the log ๐ง xfs_repair can't replay a dirty log, so it exits with status code 2 when it spots one.
In that situation, you can replay the log by mounting and then immediately unmounting the filesystem on the same class of machine that crashed ๐ Make sure that machine's hardware is reliable before you replay anything so you don't make the problems worse ๐ซ
If mounting fails, you can erase the log by running xfs_repair with the -L option.
Big warning, bestie: every metadata update that was in progress when the crash happened will be lost, and that can cause serious filesystem damage ๐ This is a last-resort move only. Please don't reach for it first.
๐ BUGS ๐
The filesystem you're checking and repairing has to have been unmounted cleanly with normal system admin procedures (the umount(8) command or a system shutdown), not because of a crash or system reset ๐
โโ๏ธ If it wasn't unmounted cleanly, mount it and unmount it cleanly before you run xfs_repair.
xfs_repair doesn't do a thorough job on XFS extended attributes ๐ฌ The attribute fork's structure will be consistent, but only attribute forks small enough to fit inside an inode actually get checked. This limitation will be fixed in the future ๐ฎ
The no-modify mode (-n option) isn't completely accurate either. It doesn't catch inconsistencies in the freespace and inode maps, especially lost blocks or subtly corrupted maps (trees) ๐ณ
No-modify mode can also spit out repeated warnings about the same problems, because it can't fix anything as it goes ๐
If a filesystem won't repair, you can generate a metadump image with xfs_metadump(8) and send it to an XFS maintainer, so they can analyse it and improve and/or fix xfs_repair ๐
๐ SEE ALSO ๐
That's the whole xfs_repair(8) page, bestie ๐โจ Go be a filesystem hero ๐ฆ๐
๐ฆ where this page comes from
- alpine 3.22: xfsprogs-doc 6.14.0-r0 ยท LGPL-2.1-or-later
- alpine 3.23: xfsprogs-doc 6.17.0-r0 ยท LGPL-2.1-or-later
- alpine 3.24: xfsprogs-doc 7.0.1-r0 ยท LGPL-2.1-or-later
- arch rolling: xfsprogs 7.2.0-1
- arch rolling: xfsprogs 7.2.1-1 ยท GPL-2.0-only AND LGPL-2.1-only
- centos-stream 10: xfsprogs 6.16.0-1.el10 ยท GPL-1.0-or-later AND LGPL-2.1-or-later
- centos-stream 9: xfsprogs 6.4.0-9.el9 ยท GPL+ and LGPLv2+
- centos-stream 9: xfsprogs 6.4.0-9.el9 ยท GPL+ and LGPLv2+
- debian bookworm: xfsprogs 6.1.0-1 ยท GPL-2.0-only
- debian trixie: xfsprogs 6.13.0-2+deb13u1 ยท GPL-2.0-only
- fedora 43: xfsprogs 6.15.0-3.fc43 ยท GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 43: xfsprogs 6.15.0-3.fc43 ยท GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs 6.18.0-2.fc44 ยท GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs 6.18.0-2.fc44 ยท GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs 7.1.1-1.fc44 ยท GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs 7.1.1-1.fc44 ยท GPL-1.0-or-later AND LGPL-2.1-or-later
- nixos 26.05: xfsprogs 6.19.0
- nixpkgs unstable: xfsprogs 7.2.1
- opensuse-leap 16.0: xfsprogs 6.19.0-160000.3.1 ยท GPL-2.0-or-later
- opensuse-leap 16.0: xfsprogs 6.19.0-160000.3.1 ยท GPL-2.0-or-later
- opensuse-leap 16.0: xfsprogs 6.19.0-160000.3.1 ยท GPL-2.0-or-later
- opensuse-leap 16.0: xfsprogs 6.19.0-160000.3.1 ยท GPL-2.0-or-later
- ubuntu noble: xfsprogs 6.6.0-1ubuntu2 ยท GPL-2.0-only
- ubuntu noble: xfsprogs 6.6.0-1ubuntu2.1 ยท GPL-2.0-only
- ubuntu questing: xfsprogs 6.13.0-2ubuntu2 ยท GPL-2.0-only
- ubuntu resolute: xfsprogs 6.18.0-3 ยท GPL-2.0-only
- ubuntu stonking: xfsprogs 6.19.0-1 ยท GPL-2.0-only
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms