In this lesson, you will learn how to use Btrfs snapshots to create instant, space-efficient recovery points before making risky system changes.
The Concept: Copy-on-Write Snapshots
Btrfs is a Copy-on-Write (CoW) filesystem, which allows it to handle data differently than traditional filesystems like ext4. When you create a "snapshot" of a subvolume, Btrfs doesn't actually copy any files. Instead, it creates a new metadata entry that points to the exact same data blocks as the original.
Because the data is shared, snapshots take up zero extra space initially. Only when you modify a file in either the original or the snapshot does Btrfs write new data blocks, keeping the original version intact. This makes snapshots nearly instantaneous.
Creating and Using Snapshots
Imagine you have a subvolume named root and you want to update your system. You can create a safety net in seconds:
# Create a read-only snapshot named 'pre-update'
sudo btrfs subvolume snapshot -r /mnt/btrfs_pool/root /mnt/btrfs_pool/root-pre-update
If the update causes your system to crash or behave erratically, you don't need to manually undo changes. You can perform a rollback by setting the system to boot from the previous state. While you can simply copy the files back, the cleanest way to rollback is to swap the subvolumes or use the snapshot as your new primary subvolume.
To revert, you would typically delete the corrupted subvolume and move or snapshot the backup back into its place:
# Remove the broken state
sudo btrfs subvolume delete /mnt/btrfs_pool/root
# Restore from the snapshot
sudo btrfs subvolume snapshot /mnt/btrfs_pool/root-pre-update /mnt/btrfs_pool/root
When to Use This
This workflow is perfect for system updates, installing new drivers, or testing configuration changes. Because these snapshots are "live" representations of your data, they provide a surgical way to undo changes without needing a full-disk restore from an external backup, provided the storage pool itself remains healthy.
Key Takeaway: Btrfs snapshots leverage Copy-on-Write metadata to provide near-instant, space-efficient backups of subvolumes, allowing you to rollback system changes in seconds if something goes wrong.