What Is Btrfs File System and Should You Use It?

btrfs file system overview

You have a new Linux device and it already wants you to make critical decisions? What a killjoy! Choosing a file system for Linux can be a daunting challenge, so it’s something we can relate to. Lucky for you, it’s also something we know a lot about.

Today, we’ll discuss the Btrfs file system and how it bodes against the competition EXT4 file system.

File Systems Explained

linux btrfs file system

The easiest way to explain a file system is as a database of all files within an operating system. Every OS has a file system that helps store data efficiently and retrieve it when necessary. A file system tells you where a specific file is stored and how.

As you can imagine, a file system is of critical importance for the healthy functioning of your machine and its entire storage system.

If you want to know more, check the video below for details:

Free Download

For Windows XP/Vista/7/8/10/11

Free Download

For macOS X 10.10 or later

While Windows and macOS have default file systems that you can’t replace, Linux is unique in this regard – and a bit more demanding.

When you install Linux on your device, you must choose between Ext, Ext2, Ext3, Ext4, JFS, ReiserFS, XFS, Btrfs, ZFS, and swap file systems. The default option for Linux OS is Ext4, but more and more users are choosing to replace it with Btrfs.

Why?

Let’s find out.

What Is the Btrfs File System?

btrfs file system structure

Like all other file systems, it controls what happens to files once you modify them. Btrfs has a unique approach to that. The main characteristic of this file system is its so-called copy-on-write (COW) resource management technique. This mechanism doesn’t replace files with modified versions but preserves both versions by saving a copy of a new file.

An excellent feature of the Btrfs file system is that it does not make duplicates by creating copies.

How is that possible, you ask?

Instead of copying a file as a whole, Btrfs captures only a modified part by taking a snapshot. That is a fantastic trick in terms of efficiency, as it avoids reduplication. Since there’s no reason to create a copy of the original file, Btrfs takes tiny snapshots that don’t create clutter.

For this and other reasons, Btrfs became very popular with the emergence of Fedora in the early 2000s – especially for use cases that involve ample storage and fast performance.

The Btrfs file system also goes by the name of the B-tree file system. It has been stable in the Linux kernel since 2013 and has remained entirely open source.

Features of the Btrfs File System

Btrfs is one of the many file system variants for Linux devices.

In addition to snapshots, which allow you to store up to 16 exbibytes or 18446.7 petabytes of data, Btrfs file system offers a range of other features. Linux users might find them valuable and preferable to alternative file system capabilities.

Some of the best features of the Btrfs file system include the following.

  • Snapshots

We’ve already talked about snapshots as the most distinctive and desirable Btrfs feature, but let’s highlight it again for the sake of clarity. A file snapshot is how Btrfs’s copy-on-write mechanism manages file modifications. Technically, it is a subvolume that carries the same data and metadata as the original file, minus the unmodified part.

taking snapshots in btrf file system
  • File Cloning

File cloning is the mechanism behind Btrfs snapshots. Simply put, it is a way to reduce the number of links connecting to the same inode. Btrfs’ clone operation creates a new inode for every file snapshot, with disk blocks that are mutual to the new inode and the original file.

  • Deduplication

To boost metadata consumption and save storage space, Btrfs deduplicates data by searching for the files with the same data blocks and deleting one copy of data blocks while combining other parts as file clone copies.

  • Extent-Based File Storage

Btrfs is an extend-based file storage, meaning that every file you store on Linux requires a separate extent. Larger files can sometimes spread across multiple extents, in which case metadata connects them. Btfrs allows you to modify an entire data extent, copying it to a different location to prevent data loss due to a power outage.

  • Swapping Files and Partitions

The Btrfs file system enables you to create swap files on all devices that use Linux Kernel 5.0 or newer.

  • Online Defragmentation

As a COW file system, Btrfs deals with fragmentation by allowing you to defragment the file system online. Defragmentation relocates extents so that fragments of the same file are as close together and continuous as possible. That is important because fragmentation can significantly slow down your file system.

  • Subvolumes

The Btfrs file system’s root tree branches into binary trees. Each binary tree is a separate namespace that we call a subvolume.

btrfs subvolume
  • File Shrinking

The file system automatically compresses and decompresses Btrfs files in the background.

  • Dynamic Inode Allocation

Dynamic inode allocation allows you to store as many files as you need to for as long as you have free disk space. It distributes inodes across files instead of allocating a fixed number of inodes.

  • RAID Support

One of Btrfs’ most attractive features is support for multiple RAID levels, including Btrfs RAID 0, RAID 1, RAID 10, RAID 5, and RAID 6.

  • Self-Healing

Btfr files self-heal through checksums of data and metadata. The system creates two copies of metadata for every file and then validates both. When it finds two copies that don’t match, it identifies a corrupted file by comparing it against the other copy (metadata mirroring). As the last step, it uses RAID volumes to recover broken data.

Btrfs Stability

The Btrfs file system has been stable since 2013. That means that Btrfs has been usable and fully functional for a long time, but is it reliable enough, too? Can it support massive volumes of data and endure high performance? Well, that depends on who’s asking.

If you’re planning to use it in a production environment, some features might not yet be ready. We suggest checking the official Status – Btrfs Wiki page, where the Btrfs team shares updates on current progress. At the moment, the page states as follows:

The Btrfs code base is stable. However, new features are still under development. Every effort is made to ensure that it remains stable and fast at each and every commit. This rapid pace of development means that the filesystem improves noticeably with every new Linux release so it’s highly recommended that users run the most modern kernel possible.”

Pros of the Btrfs File System

These are the most notable advantages of the Btrfs file system.

  • Flexible and Quick Resizing With Subvolumes

It might be easier for new Linux users to grasp the concept of subvolumes if we compare them with partitions. However, even though they behave in a similar fashion, they are not the same. In fact, Btrfs subvolumes resemble volumes in Logical Volume Manager (LVM) more than traditional disk partitions.

Be that as it may, Btfsr subvolumes ensure flexible and fast resizing.

How is that useful in practice?

For example, subvolumes allow you to create root and home separately when you’re installing Linux. Doing so will automatically divvy up space, thus saving you the trouble of deciding partition sizes for root and home.

  • Data Compression (More Available Space)

Btrfs takes resource management efficiency very seriously.

One of this file system’s most convincing selling points is its ability to reduce file size significantly. That creates a range of excellent benefits, and we’re not only talking about more storage space – which is the evident perk of data compression.

Another favorable side effect of data compression in a Btrfs file system is that it is less overwhelming for flash-based media storage devices, which means a longer device lifecycle.

Data compression also makes loading faster – unless you’re running a process that requires heavy access to your hard disk drive. In that case, accessing the hard disk might cause the opposite effect and slow down the performance.

  • Use of Snapshots

Snapshots are the most praised feature of a Btfrs file system because they organize storage space and allow effortless data recovery.

Btrfs snapshots are so tiny that they don’t occupy any additional storage space. Still, they keep a copy of everything within the file system.

That is a massive benefit for private and business users, as it neutralizes one of the top problems that today’s users face – human error. If you accidentally delete or misplace as little as a fraction of a file, using snapshots can save you from having to deal with corrupted or lost data.

Cons of the Btrfs File System

The following cons are Btrfs’ weakest points.

  • Difficult Corruption Recovery

While checksums do work, they are somewhat complicated. Another challenge is that you cannot use Btrfs file corruption recovery in unmounted versions.

  • No File System-Level Encryption

There’s no way to quickly protect your files when you use Btrfs because there is no native Btrfs encryption. You can add it via third-party providers if you don’t mind going through additional hoops. 

  • Fragmentation

When you modify a large file that spans across multiple extents in a COW file system, the clone operation might scatter original files and modifications to separate extents all over the storage device. We call that fragmentation.

Fragmentation is a problem because it slows down performance.

Btrfs users are welcome to fix this problem with online defragmentation, which works to some extent. Defragmentation is not the best solution because it creates another file copy and increases the snapshot size.

  • Unstable Raid Support

That’s right – though the Btrfs file system is stable, RAID is one of the elements that are still under development.

Btrfs vs. EXT4 – Which One Is Better?

btrfs and ext4 comparison

The ultimate question remains – which is better, Btrfs or Ext4? We’ve mentioned earlier that Ext4 is Linux’s default file system. In case you’re unfamiliar with it, all you need to know is that Ext4 is long-established and very reliable.

The many dissimilarities between Btrfs and Ext4 stem from their fundamental difference – Btrfs is a copy-to-write type of file system, while Ext4 is a journaling system. Journaling file systems keep metadata in a journal, which helps them keep track of files and file changes.

Sadly for Ext4, journaling systems lack many critical capabilities of COW systems.

Thanks to its COW mechanism, Btrfs has snapshots, deduplication, and compression, while Ext4 doesn’t. Essentially, that means that Btrfs can save space and store much more data than Ext4 – up to 16 times more.

Also, Btrfs can manage multiple devices because of its RAID support. Ext4 can’t.

Another critical difference is that Btrfs has a checksum, which allows it to self-heal and recover corrupted data, while Ext4 can’t help with broken data.

On the other hand, Ext4 has system-level encryption, unlike Btrfs. Of course, you can always add third-party encryption to Btrfs, but that’s still a point for Ext4. Since it’s not a COW file system, Ext4 doesn’t create fragmentation problems, which is another win.

So, which one is the winner?

Ultimately, that is a question of quality vs. quantity. Not to say that Btrfs isn’t a high-quality system, but it’s still not stable enough compared to the time-honored Ext4. Btrfs provides more space, but it might fail you. Ext4 is much smaller, but it’s sturdy and dependable.

How To Restore Files From the Btrfs File System?

Let’s say you decide to go with Btrfs because you need snapshots, deduplication, and compression, so that’s completely reasonable. However, what if it does fail you? If Btrfs loses your data, is there anything you can do about it?

Fortunately, yes!

Not only is there a way to recover data from Btrfs, but there are also three different methods you can use:

  1. Undelete-Btrfs Script
  2. Btrfs Restore Utility
  3. Linux Data Recovery Software

You can visit Undelete files from Btrfs for a step-by-step guide.

We should tell you right away – the first two methods require coding. If you don’t know how to do that or are still an amateur coder, practicing your skills on a different occasion might be better. Making a coding mistake can create worse problems than data loss.

The easiest (and safest) way to restore data from Btrfs is with a Linux data recovery software like Wondershare Recoverit. Wondershare Recoverit is a data recovery tool that can help you restore over 1,000 file types in more than 500 data loss scenarios – and in the case of Linux, it also works through a remote connection.

Here’s a video tutorial on how to use Wondershare Recoverit Linux File Recovery to restore deleted files from Btrfs.

Free Download

For Windows XP/Vista/7/8/10/11

Free Download

For macOS X 10.10 or later

FAQs About the Btrfs File System

Yes and no. Although Btrfs has many excellent file system management capabilities, including a self-recovery feature, it’s still under development, and many users report problems with Btrfs RAID 5.

That’s entirely circumstantial. Btrfs and ZFS offer different features that users will find more or less valuable. Users needing a lot of free storage space prefer Btrfs, but ZFS is generally more reliable.

Yes, you can use Btrfs on Windows. There is also Btrfs for Mac devices, but neither has official support.

Conclusion

You won’t make a mistake if you choose the Btrfs file system over other available Linux options. Even though it’s still under development, Btrfs is getting better every day. Even if other file systems are more reliable, Btrfs still has the hardest-working team and the best support.

Besides, Btrfs is the only top contender with COW snapshots and other features for file shrinking and self-recovery. If you need a lot of free space, it’s a no-brainer. Even if Btrfs fails to protect your data, you can always use Wondershare Recoverit to recover what you lost. 

You May Also Like