BTRFS
Safely swap your filesystem to Btrfs
The Btrfs filing system is well-supported, reliable and packed with modern features, so Michael Reed will show you how to make good use of it.
OUR EXPERT
Michael Reed is so taken with Btrfs that he wishes he could install it into his life and snapshot and rollback every time he does something embarrassing.
QUICK TIP
Tab completion is your friend. Let’s say you want to list all of the subvolumes attached to the root partition. You could accomplish it by typing sudo btrfs subvolume list / or sudo btrfs sub [tab] l [tab] /. At each stage, pressing Tab lists all of the potential next commands.
Btrfs is a filing system (see Roundup LXF283) that can be used as an alternative to the more commonly known ext4. You might think it’s risky to entrust all of your data to a relatively unknown filesystem, but in fact the Btrfs project was started in 2007, and it’s the default filesystem in some of the major distributions such as Fedora and SUSE Linux. So, it’s regarded as stable, and in fact, Btrfs has a lot of features that are designed to increase the safety of file storage. Having said all that, for all of the potential advantages, there isn’t anything extra that you have to learn for normal, day-to-day use.
Butter my FS
Why switch over to Btrfs? Well, unlike the ext4 filesystem, it uses ‘copy on write’ file storage, which opens up a number of intriguing possibilities. For instance, you can make a snapshot of your root filesystem, make some changes, decide you don’t like the results and then roll everything back to how it was originally. You could even make a massive change such as adding a different desktop environment and then back out of it later on. This might sound like snapshotting within a VM, and that’s because it offers the same freedom to experiment. You can also make snapshots of other subvolumes, such as the one containing your home directory, or you could apply snapshotting and rollbacks to server-related files.
You can also work with individual files and directories. Think of all of the times that you’ve had to work on a copy of a file while preserving the original file. Under Btrfs, a clone acts just like a copy of a file, and that’s what it appears to be. However, initially, no matter how big the file is, the clone takes up practically no extra disk space. It’s also created almost instantly. The filesystem only begins to store extra information on the hard disk when you start making changes to that copy.
For example, on a Btrfs volume, you can type code
to create a copy of the file
example.txt. Notice that the code --reflink endcode option is an addition to the standard Linux copy command. However, unlike a regular copy of a file, this new file takes up practically no space until you start making changes to it. This applies to massive files such as virtual machines and video files. So, it’s possible to, almost instantly, make a copy of a large file such as a virtual machine file, make some changes and then swap everything back if you don’t like the outcome.