BTRFS

Here we should also have the following:

Installation notes

enable scrubbing of root

systemctl --now enable btrfs-scrub@-.time

Useful commands

  • Get readonly properties for a subvolume
    • btrfs property get -ts /path/to/subvolume
  • Change a subvol to rw without making a new clone
    • btrfs property set -ts /path/to/subvolume ro false

Recovery

  • look at btrfs detected errors in systemd-journald
  • determine if zero-log is needed, otherwise proceed with recovering data
  • mount -o ro,recovery to mount a filesystem with issues
    • if it’s mountable, you can copy data off the drive now
  • btrfs restore will help you copy data off a broken btrfs filesystem
    • Haven’t had the pleasure of needing this tool yet

Mount Options

  • rescue - Modes allowing mount with damaged filesystem structures, all requires the filesystem to be mounted read-only and doesn’t allow remount to read-write. This is supposed to provide unified and more fine grained tuning of errors that affect filesystem operation.
    • usebackuproot - Try to use backup root slots inside super block. Replaces standalone option usebackuproot
    • nologreplay - Do not replay any dirty logs. Replaces standalone option nologreplay
    • ignorebadroots, ibadroots - Ignore bad tree roots, greatly improve the chance for data salvage. DANGER
    • ignoredatacsums, idatacsums - Ignore data checksum verification. DANGER
    • ignoremetacsums, imetacsums - Ignore metadata checksum verification, useful for interrupted checksum conversion.
    • all - Enable all supported rescue options.

Dirty logs

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]
  • btrfs rescue zero-log <device> - clear the filesystem log tree, This command will clear the filesystem log tree. This may fix a specific set of problem when the filesystem mount fails due to the log replay. See below for sample stack traces that may show up in system log.
  • btrfs rescue super-recovery <device> - Recover bad superblocks from good copies.

Last Resort

btrfsck

  • -b|--backup
    • use the first valid set of backup roots stored in the superblock
  • -p|--progress
    • indicate progress at various checking phases
  • --readonly
    • (default) run in read-only mode, this option exists to calm potential panic when users are going to run the checker
  • -s|--super <N>
    • use Nth superblock copy, valid values are 0, 1 or 2 if the respective superblock offset is within the device size
    • This can be used to use a different starting point if some of the primary superblock is damaged.
  • --repair
    • try to repair the filesystem (dangerous, see warnings)

Last modified: Sun Jun 29 20:59:42 2025