Thanks to the work pioneered by Chris Mason, BtrFS or ‘Better’ File System is fast becoming the mainstream file system of choice in the open source file system world. It is Linux’s answer to ZFS developed by Oracle (actually by Sun before it was acquired by Oracle). Due to incompatibility of licensing, ZFS could not be used by Linux. Incidentally, Chris Mason started the development of BtrFS while working at Oracle.

So what makes BtrFS the new Sheriff in town for open source file system?

BtrFS borrows or is inspired by ideas of the ext file systems of ext2, ext3, ext4 as well as XFS and HP aufs. It also borrows from ReiserFS. It is implemented to be highly scalable, fault tolerant as well as cloud-ready. In fact, it forms the basis for Ceph distributed file system and implements the RADOS object store layer for cloud. Ted Tso himself, the lead developer of ext4 says of it “…it is the way forward”. Its features include;

  • Built-in volume management (also supports subvolumes)
  • Built-in copy on write
  • Highly scalable: up to 16 Exabytes (a billion Gigabytes)
  • Data and metadata integrity using checksums
  • Dynamic expand and shrink
  • It can be deployed on a desktop, server, cloud and even mobile platform
  • It supports compression and is optimized for SSD
  • Support for both hardware and software RAID

Majority of Linux distros have adopted the use of BtrFS, especially the enterprise Linux flavors. That being said, it is imperative to know when and where to use BtrFS. Only use BtrFS for operating system. It is advisable not to use it for data storage as it tends to fill up the disk fast and in some instances even prevent you from deleting items due to lack of space. Good news is that most enterprise Linux operating systems can support different file system types across subvolumes within the same server. In this case, you can implement BtrFS on the main operating system subvolume (the “/”) and implement XFS for instance on a subvolume that stores data. The illustration below depicts how this can be implemented on either a new file system or even an existing one.

As indicated earlier, BtrFS supports up to 16 EB (Exabytes) for the volume and file size. It uses the B-tree directory lookup algorithm and supports both offline and online file system check. You can also use hard and symbolic links, access control lists (ACLs) and Asynchronous and direct I/O with BtrFS. It also supports copy on write, sub volumes, manual defragmentation, conversion from ext2/3/4 and ReiserFS, quota groups and snapshots. Copy on write is a feature that comes in handy when doing rollbacks as changes are written in the metadata and not the actual data blocks.

Some of the common commands you can use with BtrFS include;

List subvolumes

btrfs subvolume list –p <path_or_device>

Example: obunga:~ # btrfs subvolume list –p /

List free disk space

btrfs filesystem df <path_or_device>

Example: obunga:~ # btrfs filesystem df /

Kindly note that ‘df’ above can be substituted with either ‘show’ or ‘usage’ to achieve the same purpose with variation sin the information that is displayed.

You can convert ext2/3/4 or ReiserFS to BtrFS. Kindly note that you need to unmounts the device before you start the conversion process.

obunga:~ # umount /dev/sda3

obunga:~ # btrfs-convert /dev/sda3

To effect this, the device needs at least 15% free space. You can roll back the changes using –r option.

BtrFS uses checksums to maintain data and metadata integrity. This helps capture silent data corruption also known as bit rot. You can use the scrub command to effect this on the terminal

btrfs scrub start <device/path>

It reads all data from the disk in the background and verifies the checksums. It is recommended to use scrub to detect issues on a live system and only perform btrfs check as a last resort.

As a result of using copy on write, files tend to fragment over time. BtrFS helps in defragmentation using the following command

btrfs filesystem defragment <path_to_file_or_directory>

It should be noted that defragmentation is recommended for hard disks and not SSDs since SSDs do not have seek time.

BtrFS also uses a balance to reclaim allocated but unused data and metadata chunks

btrfs filesystem balance start <path_or_device>

obunga:~ # btrfs balance start /

Some of the features that are not yet supported on enterprise Linux, and SLES 12 to be specific include

  • Object level RAID
  • Transparent compression
  • Auto defragmentation
  • Seeding devices
  • Multiple devices
  • Send/Receive

Credits: SLES 12 Advanced Administration Student Manual, btrfs man pages, http://marc.merlins.org

Image courtesy of http://markesi.com