Btrfs#

Tasks#

  • check free space: btrfs filesystem usage <path>

  • allocation of block group types: btrfs filesystem df <path> (supports --format json)

  • device stats (io errors): btrfs device stats <path> (supports --format json)

  • show subvolumes: btrfs sub list <path>

Check redundancy (after a replaced disk)#

  • use btrfs filesystem usage -T <path> to check if all data, metadata and system is not “single” stored

  • fix this with btrfs balance start -dconvert=raid1,soft -mconvert=raid1,soft /mnt/btrfs

  • see https://wiki.tnonline.net/w/Btrfs/Replacing_a_disk

Commands#

balance#

  • see https://btrfs.readthedocs.io/en/latest/btrfs-balance.html

  • filters

    • soft: when converting between profiles chunks that already have the target profile are left untouched

replace#

  • see https://btrfs.readthedocs.io/en/latest/btrfs-replace.html

  • start subcommand with -r: only read from srcdev if no other zero-defect mirror exists. (enable this if your drive has lots of read errors, the access would be very slow)

Other Commands#

# create raid1
mkfs.btrfs -m raid1 -d raid1 /dev/sda1 /dev/sdb1

# mount
mkdir /mnt/btrfs
mount -o compress=zstd /dev/sda1 /mnt/btrfs

# scrub
btrfs scrub start /mnt/btrfs
btrfs scrub status /mnt/btrfs

# show filesystem
btrfs filesystem show

# pull one drive and scrub + show

# replace disk 1
btrfs replace start 1 /dev/sdc1 /mnt/btrfs -f
btrfs replace status /mnt/btrfs

# device stats
btrfs device stats /mnt/btrfs