Friday, 3 October 2014

Why BTRFS is Amazing

You may have heard of the BTRFS file system. BTRFS is an advanced, next-generation file system which was jointly developed by Oracle, RedHat and other companies.

When I came across BTRFS the first time, I dismissed it as yet another file system like EXT4 and NTFS. There are so many file systems available these days that most people don't care about what they are using. And there really is nothing to care about. The difference between file system formats like EXT3 and EXT4 are of interest only to advanced users. Sure, EXT4 provides journaling and better reliability than EXT3, but for the average user, there is nothing about EXT4 that changes the way they interact with their system on a daily basis.

BTRFS is different. It's such a big improvement over previous generation file systems that it will change the way you use your hard disks.

Consider the following:

  • Dynamic Partition Resizing - You can resize partitions dynamically while they are being used. There is no need to unmount and no need to reboot to a live CD. You can even resize the root partition while the system is running.

  • Disk Pooling - You can combine all your hard disks into one big volume which will act like a single partition even though they are on separate devices. You can add more devices to this pool and remove existing devices without having to unmount.

  • RAID Arrays - You can combine separate partitions on different hard disks to create a software RAID setup. For example, if you have two 1TB hard disks you can create a single BTRFS volume of 2TB capacity which uses the disks in a RAID-0 setup. Any file that you write to the volume will be written to both disks simultaneously, giving you almost twice the read and write speeds that you would get from a single disk.

  • Atomic COW Snapshots - You can create a snapshot of your system without copying a single file. The snapshot simply replicates file system metadata without duplicating files. The snapshot will take zero disk space when it is created initially since a single copy of each file is stored on disk. Files are duplicated when they get modified and common data blocks are shared. So you can create a hundred snapshots of your system without wasting disk space and restore the snapshots to undo system changes. The snapshots are also atomic. So if you take a snapshot at 10 seconds past 4:00 pm on 3rd October 2014, the snapshot will contain every single byte of data that existed on your system at 10 seconds past 4:00 pm on 3rd October 2014. Restoring a snapshot will give you the exact system that was snapshotted, down to the last byte.

  • Data Compression - BTRFS can automatically compress and decompress data that gets written to the BTRFS volume. This saves a lot of disk space and is similar to the NTFS compression available on Windows. Different compression algorithms can be selected (ZLIB,LZO,etc) to get the desired balance between better compression and faster performance. Un-compressible files like videos and music are automatically stored without compression.

  • Data Block Sharing - Let's say you have a 100GB file that you need to modify 10 times to create 10 different versions. On a normal file system like EXT4 the 10 files will occupy 1000GB space. On a BTRFS file system the different versions of the files can share common data blocks. The total disk space used by all 10 files will be the size of one file plus the modified blocks in each file.

These are just some of the things that you can do with BTRFS. More information is available at the following links:

Bitrot and atomic COWs: Inside "next-gen" filesystems

Funtoo.org BTRFS Fun

BTRFS Wiki Main Page

Using BTRFS

The simplest way is to install your system on a BTRFS partition when you install Ubuntu or Linux Mint. In some distributions like Linux Mint, BTRFS is not available by default. You will get the option in GParted only after installing the 'btrfs-tools' package with the following command:

sudo apt-get install btrfs-tools

Install the above package, use GParted to format the partition to BTRFS, then select the partition while installing Ubuntu or Linux Mint. By default it will create 2 subvolumes @ and @home which will be mounted to root (/) and home (/home) directories.

Note: You don't need to specify a separate partition for home while installing Ubuntu since the installer will automatically create a separate subvolume (@home) in the BTRFS partition.