Btrfs Explained
Btrfs (B-tree File System) is a copy-on-write (CoW) file system with built-in features that were impossible to add to ext4: snapshots, subvolumes, built-in RAID, checksumming, and online deduplication. It is the default file system on openSUSE and Fedora. On Ubuntu, it is available and stable for desktop and NAS use cases, but is less commonly used for critical production servers than ext4 or XFS.
Btrfs key features
| Feature | What it means |
|---|---|
| Copy-on-write | Writes go to new blocks; old blocks remain until all references are gone |
| Snapshots | Instant, space-efficient point-in-time copies of subvolumes |
| Subvolumes | Independent directory trees within one Btrfs volume, mountable separately |
| Built-in checksums | Every data and metadata block is checksummed; silent corruption is detected |
| Online resize | Grow or shrink a Btrfs file system while mounted |
| Built-in RAID | Span multiple devices with RAID 0, 1, 10, 5, 6 within the file system |
| Compression | Transparent compression with zlib, lzo, or zstd |
Creating a Btrfs file system
# Install Btrfs tools
sudo apt install -y btrfs-progs
# Create a Btrfs file system on a single device
sudo mkfs.btrfs /dev/sdb1
# Create with a label
sudo mkfs.btrfs -L data /dev/sdb1
# Create spanning multiple devices (RAID 1 — mirrored)
sudo mkfs.btrfs -d raid1 -m raid1 /dev/sdb1 /dev/sdc1
# Mount Btrfs
sudo mount -t btrfs /dev/sdb1 /data
# Mount with compression (recommended for general data)
sudo mount -t btrfs -o compress=zstd /dev/sdb1 /data
# Show file system info
sudo btrfs filesystem show /data
sudo btrfs filesystem usage /data
Btrfs subvolumes
Subvolumes are independent directory trees within a Btrfs file system. They are the building blocks for snapshots and can be mounted separately.
# Create subvolumes (common layout for Ubuntu)
sudo btrfs subvolume create /data/@ # Root subvolume
sudo btrfs subvolume create /data/@home # Home subvolume
sudo btrfs subvolume create /data/@snapshots # Snapshots subvolume
# List subvolumes
sudo btrfs subvolume list /data
# Mount a specific subvolume
sudo mount -t btrfs -o subvol=@home /dev/sdb1 /home
sudo mount -t btrfs -o subvol=@ /dev/sdb1 /
# Delete a subvolume
sudo btrfs subvolume delete /data/old-subvol
Btrfs snapshots
Btrfs snapshots are instant because they use copy-on-write — no data is copied at snapshot time. Space is only used as data changes after the snapshot is taken.
# Create a read-only snapshot (safest for backups)
sudo btrfs subvolume snapshot -r /data/@home /data/@snapshots/home-$(date +%Y%m%d)
# Create a read-write snapshot
sudo btrfs subvolume snapshot /data/@ /data/@snapshots/root-$(date +%Y%m%d)
# List all snapshots
sudo btrfs subvolume list /data | grep snapshot
# Mount a snapshot to browse or restore from it
sudo mount -t btrfs -o subvol=@snapshots/home-20240601 /dev/sdb1 /mnt/snapshot
# Restore from snapshot (replace current subvolume with snapshot)
# 1. Delete the current subvolume
sudo btrfs subvolume delete /data/@home
# 2. Create a new writable snapshot from the read-only backup
sudo btrfs subvolume snapshot /data/@snapshots/home-20240601 /data/@home
# Delete an old snapshot
sudo btrfs subvolume delete /data/@snapshots/home-20231201
Btrfs maintenance
# Check file system for errors (can run on mounted volume)
sudo btrfs check --readonly /dev/sdb1
# Scrub: verify all data and metadata checksums, repair silent corruption
# This reads all data and verifies checksums — schedule monthly
sudo btrfs scrub start /data
sudo btrfs scrub status /data
# Balance: redistribute data across devices (after adding/removing a device)
sudo btrfs balance start /data
# Defragment a file or directory
sudo btrfs filesystem defragment -r /data/large-files/
# Show disk usage accurately (CoW makes du less accurate for Btrfs)
sudo btrfs filesystem usage /data
📝 NOTE: RAID 5 and RAID 6 in Btrfs have had known data loss bugs for years and are still not considered production-ready as of 2024. Use Btrfs RAID 1 or RAID 10, or use mdadm/LVM for RAID 5/6 with ext4 or XFS on top. The other Btrfs features (snapshots, checksums, compression) are production-stable.
Conclusion
Btrfs is excellent for desktop systems, home NAS, and workstations where snapshots provide an easy rollback before system updates. The snapshot feature alone can save hours of recovery time. Avoid Btrfs RAID 5/6 — use RAID 1 or RAID 10 instead. Run btrfs scrub monthly to detect and repair silent data corruption. For production server storage, ext4 and XFS are more battle-tested, but Btrfs is a reasonable choice if you specifically need its snapshot or checksumming capabilities.
FAQ
Why should administrators understand BTRFS Explained?+
Because this topic affects planning decisions, server lifecycle, compatibility, support expectations, or how you reason about Ubuntu systems before making operational changes.
Do I need a lab for this topic?+
A lab is useful for checking commands and seeing the concept on a real Ubuntu machine, but the main value is understanding the decision, tradeoff, or system behavior clearly.
How should I use this knowledge in production?+
Use it to make better choices, document why those choices were made, and avoid rushed changes that ignore support windows, compatibility, stability, or operational risk.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Hire Me for Support