See luks and btrfs for using encrypted devices with btrfs.

create btrfs pool and filesystem

TODO MAKE THIS BETTER, this is just scratch stuff, don’t follow blindly

losetup /dev/loop1 /tmp/empty
mkfs.btrfs -m raid1 -d raid1 -L btrfs-pool /dev/sdd /dev/loop1
losetup -d /dev/loop1
rm /tmp/empty
mkfs.btrfs -L arch /dev/sda
mount /dev/sda /mnt
cd /mnt
btrfs subvolume create root
btrfs subvolume create home
umount /mnt

btrfs filesystem show

Show the structure of a filesystem

# btrfs fi sh
Label: 'btrfs-pool'  uuid: 12345678-1234-1234-1234-123456789012
    Total devices 4 FS bytes used 8.01TiB
    devid    1 size 5.46TiB used 5.46TiB path /dev/mapper/luks1
    devid    2 size 2.73TiB used 2.73TiB path /dev/mapper/luks2
    devid    3 size 2.73TiB used 2.73TiB path /dev/mapper/luks3
    devid    5 size 5.46TiB used 5.46TiB path /dev/sdd

btrfs filesystem usage

Summarize disk usage of each file

# btrfs fi usage -h /mnt/btrfs-pool/
    Device size:          16.37TiB
    Device allocated:         16.37TiB
    Device unallocated:        6.00GiB
    Device missing:          0.00B
    Used:             16.02TiB
    Free (estimated):        180.76GiB  (min: 180.76GiB)
    Data ratio:               2.00
    Metadata ratio:           2.00
    Global reserve:      512.00MiB  (used: 0.00B)

Data,RAID1: Size:8.17TiB, Used:8.00TiB
   /dev/mapper/luks1       5.45TiB
   /dev/mapper/luks2       2.72TiB
   /dev/mapper/luks3       2.73TiB
   /dev/sdd    5.45TiB

Metadata,RAID1: Size:10.00GiB, Used:8.93GiB
   /dev/mapper/luks1       9.00GiB
   /dev/mapper/luks2       5.00GiB
   /dev/mapper/luks3       1.00GiB
   /dev/sdd    5.00GiB

System,RAID1: Size:32.00MiB, Used:1.30MiB
   /dev/mapper/luks1      32.00MiB
   /dev/sdd   32.00MiB

   /dev/mapper/luks1       2.00GiB
   /dev/mapper/luks2       1.02MiB
   /dev/mapper/luks3       1.00GiB
   /dev/sdd    3.00GiB

mount the pool as degraded

You can add in the real mirror device(s) later:

Change x to match the device.

mount -odegraded /dev/sdx /mnt/btrfs-pool

add devices to pool

Change x1 to match the device.

btrfs dev add /dev/sdx1 /mnt/btrfs-pool

Scan for btfrs filesystems

Scan devices for a btrfs filesystem and register them.

btrfs device scan

Create a subvolume

Change tmp to match the device.

btrfs subvolume create /mnt/btrfs-pool/tmp

then add to /etc/fstab similar to any normal mount, eg:

# <file system>     <mount point>   <type>  <options>                                            <dump> <pass>
LABEL=btrfs-pool    /mnt/tmp        btrfs   defaults,nodev,nosuid,noexec,compress=lzo,subvol=tmp 0      2


Balance quietly:

The balance command without filters will basically rewrite everything in the filesystem. The run time is potentially very long.

btrfs balance start /mnt/btrfs-pool

Balance and be verbose:

btrfs balance start -v /mnt/btrfs-pool

Check the status of a balance:

btrfs balance status -v /mnt/btrfs-pool

Only balance block groups with usage under the given percentage (in this example it’s 70%):

btrfs balance start -dusage=70 -musage=70


Resize to max

Resize the whole pool:

btrfs filesystem resize max /mnt/btrfs-pool

or just resize individual devices:

btrfs filesystem resize 1:max /mnt/btrfs-pool
btrfs filesystem resize 2:max /mnt/btrfs-pool
btrfs filesystem resize 3:max /mnt/btrfs-pool
btrfs filesystem resize 5:max /mnt/btrfs-pool

Reduce by a bit

Change to match the device.

btrfs filesystem resize <devid>:-xM /mnt/btrfs-pool


Delete an id

Change x to match the device.

sudo btrfs device delete /dev/mapper/luksx /mnt/btrfs-pool