So, let’s say you’ve installed a fresh system on Btrfs. Now what? Well, Btrfs doesn’t ship with optimal default settings. Many popular Linux distributions don’t improve the situation, either. That leaves it up to the administrator to fine tune Btrfs for its particular use case.

The primary way to tune Btrfs is through mount options which are commonly enumerated in /etc/fstab for each volume on the system. I use a flat layout in my /etc/fstab for the separate Btrfs subvolumes on each system. Subvolumes within a user’s home directory, besides perhaps a standard .snapshots subvolume, are left out of my /etc/fstab to give users greater flexibility in managing their own home subvolume.

I’m planning on using Btrfs for all of my Linux machines, but these are all used as desktop computers and the mount options I selected reflect this.

fstab

First, let’s look at the /etc/fstab file on one of my machines.

/etc/fstab
/dev/mapper/sda2_crypt /                    btrfs   defaults,noatime,autodefrag,compress=zstd,commit=120,subvol=root 0 0
UUID=xxxxxxxxxxxxxxxxx /boot                btrfs   defaults,noatime,autodefrag,compress=lzo,commit=120 0 0
/dev/mapper/sda2_crypt /.snapshots          btrfs   defaults,noatime,autodefrag,compress=zstd,commit=120,subvol=snapshots 0 0
/dev/mapper/sda2_crypt /home                btrfs   defaults,noatime,autodefrag,compress=zstd,commit=120,subvol=home 0 0
/dev/mapper/sda2_crypt /home/bob            btrfs   defaults,noatime,autodefrag,compress=zstd,commit=120,subvol=home_bob 0 0
/dev/mapper/sda2_crypt /home/bob/.snapshots btrfs   defaults,noatime,autodefrag,compress=zstd,commit=120,subvol=home_bob_snapshots 0 0
/dev/mapper/sda2_crypt /opt                 btrfs   defaults,noatime,autodefrag,compress=zstd,commit=120,subvol=opt 0 0
/dev/mapper/sda2_crypt /root                btrfs   defaults,noatime,autodefrag,compress=zstd,commit=120,subvol=home_root 0 0
/dev/mapper/sda2_crypt /srv                 btrfs   defaults,noatime,autodefrag,compress=zstd,commit=120,subvol=srv 0 0
/dev/mapper/sda2_crypt /swap                btrfs   defaults,noatime,autodefrag,commit=120,subvol=swap 0 0
/dev/mapper/sda2_crypt /tmp                 btrfs   defaults,noatime,autodefrag,compress=zstd,commit=120,subvol=tmp 0 0
/dev/mapper/sda2_crypt /usr/local           btrfs   defaults,noatime,autodefrag,compress=zstd,commit=120,subvol=usr_local 0 0
/dev/mapper/sda2_crypt /var                 btrfs   defaults,noatime,autodefrag,compress=zstd,commit=120,subvol=var 0 0
/swap/swapfile         none                 swap    defaults 0 0

Wow, there’s a bunch going on here! This setup contains many separate subvolumes to facilitate snapshots of the root directory and users' home directories. It also includes a Btrfs Swapfile. These aspects of the file will be discussed in future posts. 😉

Notice that each subvolume specified here, except for /boot, explicitly states the mount options. These subvolumes use a flat layout as opposed to a nested layout. With the exception of the /boot subvolume which resides on a separate partition, they are all located at the root of /dev/mapper/sda2_crypt. When using Btrfs, nested subvolumes inherit the mount options of their parents and are automatically mounted. They don’t need to be included in /etc/fstab but they are restricted to using the exact mount options of their parents. The flat layout used here has the advantage of making it easy to view how system subvolumes are organized.

Since Btrfs does it’s own integrity checking, fsck should be disabled. The integer in the last column of each row indicates the fsck value and setting it to zero disables fsck.

Mount Options

Listed below are descriptions of each particular mount option.

Mount Options
defaults

Use default options: rw, suid, dev, exec, auto, nouser, and async. These are not Btrfs-specific.

noatime

Do not update inode access times on this filesystem. This speeds up reads since the access time metadata is not updated. This option isn’t specific to Btrfs either.

autodefrag

Enable automatic file defragmentation. This will automatically defragment small random writes into files.

compress

Filesystem-level compression is a beautiful thing. It increases read and write speeds while saving disk space. The speed of zstd compression makes it my general preference. The /boot subvolume above is mounted with lzo compression to accommodate an older version of Grub predating zstd support, which appeared in Grub 2.04.

commit

The number of seconds between periodic commits to the filesystem. This is 30 seconds by default. Increasing this value reduces the frequency of periodic writes which can reduce wear on the disk. However, this also increases the risk of data loss during the event of an untimely crash.

subvol

Mount the subvolume from the given path rather than the top-level subvolume. This option is organizational and used for the flat layout.

The ssd option is omitted since these settings are applied automatically when the underlying storage media is solid-state.

Conclusion

Hopefully you have a better idea of some of the available mount options for optimizing Btrfs for your particular use case.