BTRFS-RESCUE(8)

โœจ NAME โœจ

btrfs-rescue โ€” recover a damaged btrfs filesystem ๐Ÿฉน๐Ÿ’–


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

btrfs rescue <subcommand> <args>

๐ŸŒธ DESCRIPTION ๐ŸŒธ

okay so bestie, this is a lil collection of commands whose whole personality is fixing one specific problem. They are not necessarily suited for btrfs-check, so don't go swapping them around like they're interchangeable, iykyk. ๐Ÿ™…โ€โ™€๏ธ

Note: every single one of these subcommands cannot handle an ongoing replace/balance. Finish it or cancel it before you run this command, no cap. Otherwise it's giving chaos. ๐Ÿ’€

๐Ÿ‘‘ SUBCOMMAND ๐Ÿ‘‘

๐Ÿงš chunk-recover [options] <device>

Recover the chunk tree by scanning the devices. It literally just goes and scans. Lowkey heroic, highkey slow.

โญ Options

  • -y โ€” assume an answer of yes to all questions. ๐Ÿ’…
  • -h โ€” help.
  • -v โ€” (deprecated) alias for global -v option. It's giving legacy, don't come for me.
Note: since chunk-recover will scan the whole device, it will be very slow, especially if you run it on a large device. Like, go make a snack. ๐Ÿ“

๐Ÿงš fix-device-size <device>

Fixes device size and super block total bytes values that do not match. The mismatch is not the vibe.

Kernel 4.11 started checking the device size more strictly, and this might mismatch the stored value of total bytes. See the exact error message below. Newer kernels will straight up refuse to mount the filesystem where the values don't match. Good news: this error is not fatal and it can be fixed. This command will fix the device size values if possible. ๐Ÿซถ

BTRFS error (device sdb): super_total_bytes 92017859088384 mismatch with fs_devices total_rw_bytes 92017859094528

The mismatch may also exhibit as a kernel warning:

WARNING: CPU: 3 PID: 439 at fs/btrfs/ctree.h:1559 btrfs_update_device+0x1c5/0x1d0 [btrfs]

๐Ÿงš fix-data-checksum <device>

Selectively fix data checksum mismatch. The selective girlie of the rescue lineup. โœจ

There is a long existing problem: if a user space program is doing direct IO and modifies the buffer before the write back finished, it can lead to data checksum mismatches. Smh.

This problem is known but was not fixed until upstream release v6.15 (backported to older kernels). So it is possible to hit false data checksum mismatch for any long running btrfs. ๐Ÿ˜ญ

In that case this program can be utilized to repair such problem. Slay.

โญ Options

  • -r|--readonly โ€” readonly mode, only scan for and report data checksum mismatches, do not repair. Just looking respectfully. ๐Ÿ‘€
  • -i|--interactive โ€” interactive mode, ask for how to repair, ignore the errors by default.
  • -m|--mirror <num> โ€” use specified mirror to update the checksum item for all corrupted blocks.

The value must be >= 1, and if the corrupted block has fewer mirrors than the value, the mirror number will be num % (num_mirrors + 1). Yes, that's the math, write it down. ๐Ÿ“


๐Ÿงš clear-ino-cache <device>

Remove leftover items pertaining to the deprecated inode number cache feature.

That feature, enabled by mount option inode_cache, has been completely removed in the 5.11 kernel. It's gone, bestie. RIP bozo. ๐Ÿชฆ


๐Ÿงš clear-space-cache <v1|v2> <device>

Completely remove the on-disk data of free space cache of the given version. You gotta tell it v1 or v2, it doesn't read minds. ๐Ÿ”ฎ

Especially for v1 free space cache: the clear_cache mount option would only remove the cache for updated block groups, and the remaining stuff would not be removed. So this command exists to manually clear the free space cache. Periodt. ๐Ÿ’…


๐Ÿงš clear-uuid-tree <device>

Clear the UUID tree so that the kernel can regenerate it at the next read-write mount. Iconic behaviour, honestly. ๐ŸŒˆ

Since kernel v4.16 there are more sanity checks performed, and sometimes non-critical trees like the UUID tree can cause problems and reject the mount. In such a case, clearing the UUID tree may make the filesystem mountable again without much risk, since it's built from other trees. See also mount option rescan_uuid_tree (in btrfs-man5).


๐Ÿงš super-recover [options] <device>

Recover bad superblocks from good copies. The good copies said "not on my watch". ๐Ÿซก

โญ Options

  • -y โ€” assume an answer of yes to all questions.
  • -v โ€” (deprecated) alias for global -v option.

๐Ÿงš zero-log <device>

Clear the filesystem log tree. ๐Ÿงน

This command will clear the filesystem log tree. This may fix a specific set of problems when the filesystem mount fails during log replay. See below for sample stack traces that may show up in the system log.

Note: clearing the log may lead to loss of changes that were made since the last transaction commit. This may be up to 30 seconds (the default commit period) or less if the commit was implied by other filesystem activity. So like, know what you're doing. ๐Ÿ™ˆ

One can determine whether zero-log is needed according to the kernel backtrace:

? replay_one_dir_item+0xb5/0xb5 [btrfs]
? walk_log_tree+0x9c/0x19d [btrfs]
? btrfs_read_fs_root_no_radix+0x169/0x1a1 [btrfs]
? btrfs_recover_log_trees+0x195/0x29c [btrfs]
? replay_one_dir_item+0xb5/0xb5 [btrfs]
? btree_read_extent_buffer_pages+0x76/0xbc [btrfs]
? open_ctree+0xff6/0x132c [btrfs]

If the errors are like the ones above, then zero-log should be used to clear the log and the filesystem may be mounted normally again. The keywords to look for are 'open_ctree', which says that it's during mount, and function names that contain replay, recover or log_tree. ๐Ÿ”โœจ


๐Ÿ’ซ EXIT STATUS ๐Ÿ’ซ

btrfs rescue returns a zero exit status if it succeeds. Non zero is returned in case of failure. It's giving pass/fail, no in-between. ๐Ÿ’ฏ


๐ŸŽ€ AVAILABILITY ๐ŸŽ€

btrfs is part of btrfs-progs. Please refer to the documentation at <https://btrfs.readthedocs.io>. Go read it, bestie, it's free. ๐Ÿ“š


๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ


and that's the whole page, you ate that fr fr ๐Ÿ’– this was btrfs-progs version 7.3, dated Oct 24, 2026 โ€” go forth and rescue those filesystems, main character. ๐Ÿ‘‘๐Ÿฆ‹โœจ

๐Ÿ“ฆ where this page comes from