# Setting up Btrfs on Arch Linux

I recently purchased a Dell Precision 5530 mobile workstation for my development purposes. As expected of me, I began making preparations for installing Arch Linux on this system. For a moment I thought, why not make the most out of this hardware by fine-tuning everything? Upon further researching, I found that one of the most important factors in improving performance is the filesystem which is used. As it turned out, my system had a 512 GB class 40 M.2 NVME SSD. I read up various articles from Arch wiki, Gentoo wiki and other threads coming to a conclusion that Btrfs is the choice of filesystem for my new workstation.

Btrfs, commonly known as “Butter FS” in computer jargon, is a filesystem based on “Copy on Write” principle with powerful features such as subvolumes, snapshots, quota management, file-level compression, etc to name a few. Various threads^1 recommend using it as the default filesystem for non-rotational disks. Although we can convert an existing ext4 partition into btrfs, it is best when you partition the disks as btrfs during your OS installation. Below I will show you how to set up and configure Arch Linux to use btrfs as the root as well as other partition’s filesystem.

# Create partition:

You can use the cmd line tool which you are familiar with, to create partitions on your hard drive. For example, using fdisk. Btrfs subvolumes provide the flexibility of traditional partitions, therefore you may not want to create separate MBR/GPT based partitions for mount points such as /home, /var, etc as these will be emulated via subvolumes.

Assuming you have booted into the live installation media and have created the two required partitions one for boot and another for root, let’s format the root partition as btrfs:

Replace X with device number and N with partition number.

# Create Btrfs subvolumes:

After formatting the disk with btrfs, we can now proceed to create subvolumes as follows:

Here, we have created three subvolumes by the name @root, @var and @home for mounting /, /var and /home respectively. We have deliberately created a seperate mountpoint for /var so that this partition is not backed up when we create snapshots. /var contains runtime files and logs which are lost when your machine is powered down. Backing this up will take unnecessary space in your precious SSD 😬

# Mount subvolumes:

ssd tells btrfs to use SSD Specific options(btrfs will automatically detect and enable this if it finds a non-rotational disk).

compress allows us to specify the compression algorithm which we want to use. Btrfs provides lzo, zstd and zlib compression algorithms. Based on this phoronix test case, zstd seems to be the better performing candidate.

noatime is used to prevent frequent disk writes by instructing the Linux kernel not to store the last access time of files/folders^3 thereby increasing the lifetime of our drive.

space_cache allows btrfs to store free space cache on disk to make caching of a block group much quicker. This will allow btrfs to find free blocks for allocations much faster^4.

commit is the time interval in which data is written to the filesystem. I have shamelessly copied the value of 120 from Manjaro’s minimal iso.

subvol key is used to indicate the subvolume which we want to mount at the particular location.

Post this, follow the regular Arch installation(if you haven’t, check this one out!).

Note 1: Btrfs does not support swap files. Instead use zram or zswap as swap replacement which compresses data in-place inside RAM, a concept similar to how our mobile OS handles Memory Management.

Note 2: Btrfs cannot be used as /boot filesystem with zstd compression^6. Either use a different compression or format it to FAT32 filesystem.

# Snapper: Automatic Snapshots

Install the packages: grub-btrfs, snapper. Follow the instructions at snapper wiki for configuration. Make sure to start and enable appropriate systemd services. grub-btrfs adds the snapshots entries into grub menu, therefore allowing us to recover from system failure. To enable automatic updation of grub menu^5, run the following:

This will run the grub-mkconfig -o /etc/default/grub command each time a snapshot is created or deleted. Your snapshots will now appear in the grub menu under “Snapshots”.

# TLP (Optional)

Those who have installed TLP for power saving purposes, add the following at the end of your /etc/default/tlp file:

That’s it, folks. Hope this guide was helpful to you. Suggesstions, comments, criticisms are welcomed!