Pros and Cons of Using Btrfs Filesystem in Linux

Whenever you install Linux, you get to choose a file system, especially when you are manually partitioning your disk.

The most common option is Ext4, which is used as default in many desktop Linux distributions. But, after Fedora took the plunge to use Btrfs as its default file system, many desktop Linux users switched to Btrfs.

If you are one of them who want to switch to Btrfs, let me help you by listing the Pros and Cons of Btrfs as a file system. This will help you to decide whether to switch or not.

What is Btrfs?

For starters, Btrfs is a modern copy-on-write file system for Linux with advanced features for fault tolerance, repair and easy administration. Btrfs uses copy-on-write for all files, which means if a file is modified/written to the storage, the file is not replaced but a copy of the file is created. This mechanism helps to create snapshots with minimum size as the unmodified files need not be copied for creating the snapshot.

Btrfs is licensed under the GPL and is open source.

Advantages of Btrfs over Ext4

Let’s talk about the advantages Btrfs boasts over the traditional and more popular ext4 filesystem.

Snapshots

This is the most desired feature of Btrfs. As I have mentioned earlier, snapshots are created with minimal size due to the use of copy-on-write.

These snapshots can be used to restore the state of our system to a particular one without using more storage. Switching to a Btrfs snapshot is very quick.

This makes system recovery seamless which is desired by Linux users especially the ones using rolling release distros (which support newer packages making the system unstable).

Btrfs Assistant showing a list of snapshots
Btrfs Assistant showing a list of snapshots

As you see, whenever I remove or install a package, a snapshot is created. This way, I can restore the system to a previous state if something goes wrong. These snapshots are also available at boot time.

Btrfs Assistant can be used for the same. If I restore my system to the highlighted snapshot (in the image above), it will restore my system to the state before I installed VLC Media Player.

Alternatively, if you are not able to login into your system, then a project called grub-btrfs can be used to boot into snapshots directly from GRUB bootloader as you can see in the screenshot below.

GRUB menu with snapshots listed
GRUB menu with snapshots listed

Compression

Btrfs also supports data compression, reducing the file size so you can store more data in less space. This also increases the lifespan of flash-based media storage devices (e.g., SSD, eMMC) as less data is written to disk.

It also increases performance for a process which do not load many files from your HDD. However, if a process needs to access more files from the HDD it can cause some slow down as decompression is done to access files.

Subvolumes

Subvolumes behave like a partition but are not the real disk partition. They can be compared to something like Volumes used in LVM (Logical Volume Manager).

Subvolumes make resizing quick and flexible as compared to real partitions. Interestingly, a Btrfs snapshot is also a subvolume that shares its data with another subvolume.

For example, to get a list of subvolumes, you can enter the following command and it also lists the snapshots as subvolumes.

sudo btrfs subvolume list -p /
Btrfs Subvolumes' list in GNOME Terminal
Btrfs Subvolumes’ list in GNOME Terminal

The best use case of subvolumes is creating root and home as separate subvolumes which will allocate space automatically as per requirement. This eliminates the dilemma of choosing root and home partition sizes while installing Linux.

Having the Home directory on a separate subvolume has another advantage. The system snapshots will get quite large if you have the Home directory included in the snapshot.

This is also true for Windows System Restore as it also does not take backup all the files. Only system files are included to keep storage requirements for the restore points to a minimum.

As you can see in the screenshot below listing the Subvolumes in Btrfs Assistant.

Btrfs Assistant showing list of subvolumes
Btrfs Assistant showing list of subvolumes

Disadvantages of Btrfs

Nothing in this world has only positives. Btrfs is no exception.

You have seen what it does better than Ext4. Let’s have a look at things it is not good at.

RAID

RAID (Redundant Array of Independent Disks) is a storage technology that combines multiple disk drive components into a logical unit. It is beneficial in servers mainly for the performance and data loss prevention it provides.

Btrfs supports RAID however RAID 5 and RAID 6 modes are deemed unstable as of now. As RAID 5 is one of the best choices for RAID, it can deter the adoption of Btrfs on servers.

Fragmentation

File fragmentation might not be an issue for SSDs but there are many people still using rotational drives. This will hamper performance over time in those cases, also defragmenting a file will create a separate copy of that file.

Therefore, the size of the snapshot also increases due to defragmentation. You can deduplicate the file but that creates more hassle for the user.

You will be surprised to know XFS or Ext4 do not require defragmentation.

Encryption

Unlike Ext4, Btrfs does not support encryption on the file system level. However, you can use third-party methods to encrypt a Btrfs filesystem.

Corruption recovery

File system check is not possible on a mounted Btrfs file system but can be used to check or repair an unmounted Btrfs filesystem. However, this may not able to repair filesystem errors (even minor ones).

This is due to heavy development being done on the Btrfs file system check tool.

Conclusion

Btrfs may seem like a work in progress and you can check out the stability status from the official site anytime. However, it is under heavy, active development and is improving at a greater pace which gets me excited.

My recommendation is that if you have an SSD and use a rolling release distribution then go for it for the seamless recovery using snapshots. Otherwise, use the good old Ext4 for stability and performance.

Please do not take my word for it as this article is just my opinion and the pros and cons listed may not be the same for all the use cases.

I hope I was able to clear some air around using Btrfs of Linux. If you notice any technical errors, do let me know in the comment section.

Of course, a few points might be debatable. Feel free to express it in the comments.

Similar Posts

  • I’ve been running a btrfs filesystem on a luks2 partition for about a year now on an mmc drive in what used to be a chromebook, and it’s performed very well.
    To answer some of the questions below:
    – I have no snapshots, so there have been none automatically created. These can be managed in Btrfs Assistant manually or automatically with snapper (see next point). Some caveats from the docs: “A snapshot is not a backup: snapshots work by use of BTRFS’ copy-on-write behaviour. A snapshot and the original it was taken from initially share all of the same data blocks. If that data is damaged in some way (cosmic rays, bad disk sector, accident with dd to the disk), then the snapshot and the original will both be damaged. Snapshots are useful to have local online “copies” of the filesystem that can be referred back to, or to implement a form of deduplication, or to fix the state of a filesystem for making a full backup without anything changing underneath it. They do not in themselves make your data any safer.” I use a file based backup implementation so I don’t bother, therefore I cannot comment on how much space is taken, though the snapshots will definitely consume space.
    – Automated snapshots (using snapper) can be setup under “Snapper Settings” tab in Btrfs Assistant, to include a specification of how many snapshots should be retained. These can also be manually deleted on the “Snapper” tab in Btrfs Assistant.
    – A traditional filesystem check may not be possible on mounted filesystems, but a btrfs scrub can be manually performed (especially easy with Btrfs Assistant). This will pass over all filesystem data and metadata and verify the checksums to check for corruption. From the BTRFS Documentation “If a valid copy is available (replicated block group profiles) then the damaged one is repaired.” I performed this check just now and it found no errors. Also from the docs: “Data and metadata are checksummed by default, the checksum is calculated before write and verifed after reading the blocks from devices. The whole metadata block has a checksum stored inline in the b-tree node header, each data block has a detached checksum stored in the checksum tree.”
    – BTRFS allocates chunks depending on the type of data being stored. Data, metadata, system files will typically be allocated to large chunks, and filesystem info will be allocated to smaller chunks. I don’t see why BTRFS would cause any additional wear inherently, but if it does, this type of allocation should limit the damage to filesystem itself (assuming it does not often change), which will make failures less catastrophic.
    – BTRFS is copy-on-write, which I prefer for solid-state (or mmc) storage, as opposed to journaling file systems which may be more likely to lose data if unexpectedly taken offline before the journal changes can be synced to disk.
    – RE additional benefits from the docs (that stand out to me):
    – – Self-healing – checksums for data and metadata, automatic detection of silent data corruptions
    – – Writable snapshots, read-only snapshots (useful for more than online backups, see the docs)
    – – Space-efficient packing of small files
    – – SSD (flash storage) awareness (TRIM/Discard for reporting free blocks for reuse) and optimizations (e.g. avoiding unnecessary seek optimizations, sending writes in clusters, even if they are from unrelated files. This results in larger write operations and faster write throughput)

    For more info on the features, see https://btrfs.readthedocs.io/en/latest/Common-features.html

  • Everytime I used btrfs for my system it went corrupted after a short or medium period (within 6 months). Don’t use it on your main computer unless you have good backups. Yes, you still need backup because a corrupted btrfs disk will not be able to use any snapshots you may have taken before …

    • Totally agree. I read about it’s wonders. I installed it a couple of years ago and everything seemed fine. A few days later it was lagging badly and eventually froze. Had to reformat. Tried it again this past week figuring they have been working on it for a long time and even more positive articles have been written about it. Exact same thing happened. Save yourself some headaches and stick with Ext4 until stability is no longer an issue, whenever that might be….