Introduction to Btrfs: snapshots, subvolumes and system recovery

A practical guide to Btrfs fundamentals, with commands for subvolumes, read-only snapshots, cautious recovery, scrub and send/receive backups.

Introduction to Btrfs: snapshots, subvolumes and system recovery

Btrfs is a copy-on-write Linux filesystem designed for advanced features such as checksums, compression, subvolumes, snapshots and incremental replication. It can be useful on workstations and servers, but snapshot, recovery and backup are not synonyms.

This guide uses example paths. Check the mount point with findmnt and practise on non-critical data. A mistake involving the root subvolume can make a system unbootable.

1. Install tools and inspect the filesystem

sudo apt update
sudo apt install btrfs-progs
sudo btrfs version
findmnt -t btrfs
sudo btrfs filesystem show
sudo btrfs subvolume list /

btrfs-progs provides the administration commands. Do not convert an existing filesystem merely to test snapshots; start with a test volume and a verified backup.

2. What a subvolume is

A subvolume is an internal file tree with its own hierarchy. It shares free space with other subvolumes and can be mounted separately. It is not a partition or an LVM logical volume.

sudo btrfs subvolume create /data/projects
sudo btrfs subvolume list /data

Nested subvolumes need care: snapshots are not recursive. A nested subvolume acts as a barrier and its contents are not automatically included in the parent's snapshot.

3. Take a snapshot before an upgrade

A snapshot is nearly instantaneous because it initially shares extents with the source. A read-only snapshot is a sensible recovery point:

sudo mkdir -p /data/.snapshots
sudo btrfs subvolume snapshot -r /data/projects /data/.snapshots/projects-before-upgrade

Confirm it with sudo btrfs subvolume show /data/.snapshots/projects-before-upgrade. It can protect against later logical errors, but not against disk loss or damage to shared blocks.

4. Recover without immediately deleting the original

A cautious method creates a new writable subvolume from the snapshot, validates data and applications, and only then removes anything:

sudo btrfs subvolume snapshot /data/.snapshots/projects-before-upgrade /data/projects-restored

Root filesystem rollback depends on layout, bootloader and distribution rules. Logs, databases and virtual machines often belong in separate subvolumes so they are not rolled back with the system. Do not blindly change the default subvolume.

5. Space and maintenance

Snapshots do not duplicate all data immediately, but they retain old extents as files change. Many snapshots can therefore hold substantial space. Define retention and monitor real usage.

sudo btrfs filesystem usage /
sudo btrfs scrub start -Bd /
sudo btrfs device stats /

Scrub reads data and metadata and verifies checksums; with redundancy it can repair damaged copies. It is not a backup. Do not confuse it with btrfs check --repair, an invasive command that is not routine maintenance.

6. A real backup with send/receive

Replicate a read-only snapshot to another Btrfs filesystem with send and receive:

sudo btrfs send /data/.snapshots/projects-before-upgrade | sudo btrfs receive /mnt/backup

The destination must be a mounted Btrfs filesystem. Later transfers can be incremental when source and destination share parent snapshots. Keep at least one copy on a separate device or system and test recovery regularly.

Pre-upgrade checklist

  • verify filesystem, mount point and free space;
  • separate data that must not be rolled back;
  • create a clearly named read-only snapshot;
  • make an external backup too;
  • document boot and recovery steps;
  • delete expired snapshots only after checks.

Btrfs makes snapshots and replication efficient, but safety comes from a deliberate layout, independent copies and tested recovery.

Official sources

Share

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0