Skip to main content
RunBook Academy

LinuxXIV · Filesystemsbtrfs

btrfs where it fits - snapshots, subvolumes, and operations

Intermediate⏱ ~10 minbashmkfs.btrfsbtrfsmount

What you'll learn

  • Identify when btrfs is the right choice over ext4/xfs
  • Create and use btrfs snapshots and subvolumes
  • Use btrfs send/receive for incremental backup
  • Run btrfs scrub and balance

Prerequisites

Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09

Not yet marked complete on this device.

btrfs is a modern copy-on-write filesystem with features that make it ideal for specific workloads. Choosing btrfs is a deliberate choice based on the workload and the team’s operational readiness.

When to use btrfs

Use btrfs when you need:

  • Snapshots for atomic rollback (after a deployment or a database migration).
  • Subvolumes for separate logical filesystems sharing a storage pool.
  • Send/receive for incremental backup or replication to another host.
  • Built-in compression (zstd, lzo) for space-efficient storage of compressible data.

Do not use btrfs for:

  • Production databases that need proven, mature storage (use ext4 or xfs).
  • Boot disks on legacy hardware (btrfs boot support has improved but is still tricky).
  • Workloads where the operations team has no btrfs experience.

Creating a btrfs filesystem

Read-only / Safemkfs.btrfs
$ mkfs.btrfs -L data /dev/sda1
btrfs-progs v6.6
See http://btrfs.wiki.kernel.org for more information.

Label:           data
UUID:            abc12345-...

Subvolumes

Configuration changebtrfs subvolume
$ btrfs subvolume create /data/projects
Create subvolume '/data/projects'

Snapshots

Configuration changebtrfs snapshot
$ btrfs subvolume snapshot -r /data/projects /data/projects-snap-2026-01-01
Create a readonly snapshot of '/data/projects' in '/data/projects-snap-2026-01-01'

Send/receive for backup

Configuration changebtrfs send/receive
$ btrfs send /data/projects-snap | btrfs receive /backup/projects
At subvol /data/projects-snap
At subvol /backup/projects

A bare btrfs send sends the whole snapshot. To send only what changed, keep the previous read-only snapshot on both sides and name it as the parent:

Configuration changebtrfs incremental send
$ btrfs send -p /data/projects-snap-2026-01-01 /data/projects-snap-2026-01-02 | btrfs receive /backup/projects
At subvol /data/projects-snap-2026-01-02
At snapshot /data/projects-snap-2026-01-02

Scrub and balance

Configuration changebtrfs scrub
$ btrfs scrub start /data
scrub: started on /data, generation 42
Configuration changebtrfs balance
$ btrfs balance start /data
Done, had to relocate 5 out of 12345 chunks

Knowledge check

Knowledge check · 5 questions

  1. Q1. What is the primary advantage of btrfs over ext4 for production deployment workloads?

  2. Q2. btrfs snapshots are instant and do not copy data at creation time.

  3. Q3. Which of the following are correct uses of btrfs? Select all that apply.

  4. Q4. A nightly cron takes a snapshot and pipes it to btrfs send over SSH. It has reported nothing for six weeks and the destination has no new subvolumes. The snapshot command is btrfs subvolume snapshot /data/projects /data/snap-$(date +%F). What is the fault?

  5. Q5. An incremental btrfs send needs the parent snapshot to still exist on the source and the destination, so the two sides must be pruned together.

Passing score: 75%. Answers are checked in this browser.