Context and Reasons for Btrfs Subvolumes
When working with Linux, especially on development systems or servers, disk management is always a top priority. Many are familiar with traditional filesystems like Ext4, known for its proven stability and performance. However, as the demand for flexibility, data integrity, and especially rapid recovery increases, we need to seek more modern solutions.
Btrfs (B-tree file system) is one of the notable names. It’s a “copy-on-write” (CoW) filesystem, developed to provide advanced features that Ext4 lacks. These include snapshots, checksumming, compression, and most importantly for this article, subvolumes.
I’ve been using Fedora as my primary development machine for two years. While very satisfied with the speed of package updates, large updates can sometimes still pose risks. Btrfs subvolumes and snapshots are truly a lifesaver, allowing me to experiment confidently without fear of breaking the system.
What are Subvolumes and How Do They Help?
You can imagine a subvolume as a special directory on a Btrfs filesystem. Unlike regular directories, a subvolume can function as an independent file system. It can be mounted, unmounted, and managed separately, offering many significant benefits:
- Data Isolation: You can create separate subvolumes for the operating system (
/) or user directories (/home). You can even dedicate them to critical applications like databases (/var/lib/mysql,/var/lib/postgresql) or logs (/var/log). This helps isolate data, preventing one part of the system filling up from affecting the entire system. - Flexible Space Management: Subvolumes share a common pool of physical disk space. This is completely different from traditional partitioning, where you have to pre-define sizes and changes are difficult. Btrfs subvolumes can automatically grow or shrink within that shared space, offering maximum flexibility.
- Powerful Snapshots: This is the most ‘valuable’ feature of subvolumes. You can create a snapshot (quick image) of a subvolume’s state at any time. Initially, snapshots don’t take up much additional disk space because they share data with the original subvolume. Only when data changes is new space used to store those new data blocks. This is extremely useful for restoring the system to a previous state in case of issues. For example, after a failed software update or incompatible application installation.
With Fedora, from version 33 onwards, Btrfs has become the default filesystem for new installations. This means that when you install Fedora, the system already has basic subvolumes like root (for /) and home (for /home) pre-configured. This provides a solid foundation for more efficient management.
Installing and Checking Btrfs on Fedora
If you installed Fedora 33 or later, Btrfs is already the default filesystem, so you don’t need to install anything extra. However, it’s important to ensure that the Btrfs management tools are available on your system.
Checking Btrfs Status
To begin, check if your system is using Btrfs, and also view existing Btrfs partitions:
df -h -t btrfs
The returned result will be similar to the following, showing Btrfs partitions along with their mount points:
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 475G 15G 459G 4% /var/home
/dev/sda3 475G 15G 459G 4% /
It’s important to note that both / and /var/home (or /home) are mounted from the same device /dev/sda3. However, they are separate subvolumes on the same Btrfs filesystem.
Installing Btrfs Tools
To manage Btrfs subvolumes and snapshots, you need the btrfs-progs package. Fedora usually has this package installed by default. However, if for some reason it’s missing, you can easily install it as follows:
sudo dnf install btrfs-progs
Once installed, you are fully ready to start working with subvolumes.
Detailed Btrfs Subvolume Configuration
Listing Existing Subvolumes
To view existing subvolumes on a Btrfs filesystem, use the btrfs subvolume list command. You need to specify the path of the root Btrfs filesystem. If you’re unsure, you can use / or the mount point of your Btrfs partition.
sudo btrfs subvolume list /
The result will display the ID, generation, and path of each subvolume:
ID 256 gen 2102 top level 5 path root
ID 257 gen 2102 top level 5 path home
In this example, root is the subvolume for the root system (/), and home is the subvolume for the user directory (/home or /var/home, depending on how Fedora was installed).
Creating New Subvolumes
You can create subvolumes for various purposes. For instance, you can create a separate subvolume for development projects, or for other important directories like /var/log. This helps with easy snapshot management and independent recovery.
The basic syntax is:
sudo btrfs subvolume create /path/to/parent/directory/new_subvolume_name
For example, to create a subvolume for logs:
sudo btrfs subvolume create /var/log_btrfs
After creating the subvolume, you can move existing content into it (if needed) and mount it at the desired location. For example, to move existing log files into the new subvolume and mount it at /var/log:
sudo mv /var/log/* /var/log_btrfs/
sudo rmdir /var/log # Ensure the directory is empty
# You might need to recreate an empty directory if rmdir reports an error due to hidden files or permissions
sudo mkdir /var/log
Then, update /etc/fstab to mount this subvolume:
# Add this line to /etc/fstab. Replace /dev/sda3 with your Btrfs device
UUID=<YOUR_UUID> /var/log btrfs subvol=log_btrfs,compress=zstd:3,defaults 0 0
To find the UUID of your Btrfs partition, use the command:
lsblk -f
After editing /etc/fstab, try mounting to test:
sudo mount -a
df -h /var/log
Creating and Managing Snapshots
Snapshots are one of the most powerful features of Btrfs subvolumes. They allow you to create a ‘quick image’ of the filesystem’s state at a specific point in time. Initially, snapshots don’t take up much additional disk space because they share data with the original subvolume. Only when data changes is new space used to store those new data blocks.
Creating a Snapshot
The syntax for creating a snapshot is:
sudo btrfs subvolume snapshot <source_subvolume_path> <destination_snapshot_path>
For example, to create a snapshot of the root subvolume before performing a major system update:
sudo btrfs subvolume snapshot / /.snapshots/root_before_update_$(date +%F_%H-%M)
In this example, .snapshots is a directory created to contain snapshots. You should name snapshots by date and time for easy management and identification.
By default, snapshots are writable. If you want to create a read-only snapshot, add the -r option:
sudo btrfs subvolume snapshot -r /home /.snapshots/home_ro_backup
Listing Snapshots
Since snapshots are also a type of subvolume, you can list them similarly to other subvolumes:
sudo btrfs subvolume list /
Recovering from a Snapshot
This is when snapshots truly demonstrate their power. If an update causes system instability, you can easily restore to the state of a previous snapshot.
The recovery process typically includes the following steps:
- Boot into a recovery environment (e.g., a Fedora live USB). Or, if you have configured GRUB to boot into an old, working snapshot, you can use that method.
- Find the ID of the current
rootsubvolume and the snapshot you want to restore. - Delete the current
rootsubvolume. - Create a writable snapshot from the snapshot you want to restore.
- Set this new snapshot as the default subvolume.
- Reboot the system.
For example, suppose you want to recover to the snapshot root_before_update_2026-03-11_10-00:
# 1. Mount your Btrfs partition (e.g., /dev/sda3) to a temporary mount point
sudo mount /dev/sda3 /mnt
# 2. List subvolumes to identify the name of the snapshot and the root subvolume
sudo btrfs subvolume list /mnt
# Assuming your snapshot is .snapshots/root_before_update_2026-03-11_10-00
# 3. Delete the current root subvolume (be very careful with this step!)
sudo btrfs subvolume delete /mnt/root
# 4. Create a writable snapshot from the snapshot you want to restore
sudo btrfs subvolume snapshot /mnt/.snapshots/root_before_update_2026-03-11_10-00 /mnt/root
# 5. Set this new snapshot as the default subvolume
sudo btrfs subvolume set-default $(btrfs subvolume show /mnt/root | awk '/Subvolume ID:/ {print $NF}') /mnt/
# 6. Unmount and reboot
sudo umount /mnt
sudo reboot
Note: This recovery should be performed carefully, and you should have experience with a recovery environment. Always back up important data before performing major operations.
Deleting Subvolumes/Snapshots
When a subvolume or snapshot is no longer needed, you can delete it to free up space:
sudo btrfs subvolume delete /path/to/subvolume_or_snapshot
For example:
sudo btrfs subvolume delete /.snapshots/root_old_snapshot
Checking and Monitoring
After configuration, checking and monitoring the status of your Btrfs filesystem and subvolumes is very important to ensure everything runs smoothly.
Checking Used Space
The df -h command provides an overview of disk space. However, to see more detailed space usage by each subvolume, you can use btrfs filesystem du:
sudo btrfs filesystem du -s /path/to/subvolume
Or to see the entire filesystem:
sudo btrfs filesystem du /
Checking Btrfs Filesystem Errors
Btrfs has data integrity checking features (checksumming). You can check the filesystem for potential errors:
sudo btrfs scrub start /
This command will scan the entire filesystem to check data and metadata for corruption. You can check the status of the scrub process with:
sudo btrfs scrub status /
Optimizing Space (Defragmentation and Data Compression)
Btrfs supports data compression to save storage space. You can enable compression at the subvolume level or file level. For example, to compress a subvolume:
# You need to remount with compression options, e.g., compress=zstd:3 in /etc/fstab
# Or manually compress a directory:
sudo btrfs filesystem defragment -r -v -c zstd /path/to/directory
Defragmentation can also be performed. Although with CoW filesystems, it’s less necessary than with Ext4. However, if you have large files that change frequently, defragmentation can help improve performance:
sudo btrfs filesystem defragment -r /path/to/directory
Conclusion
Btrfs subvolumes and related features like snapshots provide a powerful level of data management and protection that traditional filesystems struggle to match. With Fedora, this becomes even more accessible as Btrfs is now the default choice.
Understanding and mastering Btrfs subvolumes not only helps you optimize storage space but also provides a solid ‘safety net’ for system updates or experiments. For an IT engineer like myself, the ability to recover quickly is invaluable, allowing me to be more confident when exploring and applying new technologies on my development machine.
Take the time to experiment and integrate Btrfs subvolumes into your workflow. You will find it to be an extremely useful tool for maintaining a stable and efficient Linux system.
