BcacheFS Compilation and Installation on Ubuntu 20.04

BCacheFS is an awesome new Copy on Write (COW) filesystem created and developed by Kent Overstreet. This is a guide for installing bcachefs on Ubuntu.

The filesystem has some useful features, including (from bcachefs.org):

  • Copy on Write
  • Full data and metadata checksumming
  • multiple devices, including replication and other types of RAID
  • Caching
  • Compression
  • Encryption
  • Snapshots
  • Scalable – has been tested to 50+TB, will eventually scale far higher
  • Already working and stable, with a small community of users

Installing BCacheFS, however, is no small feat. I had pretty much given up on the endeavor until I found a Reddit post highlighting the steps. I’m mainly copying that here for posterity, fearing that the user may delete their posts in the future.

Add Sources

You’ll first have to enable some extra sources that exist within your sources.list.

$ sudo nano /etc/apt/sources.list

Uncomment the deb-src lines and the universe and multiverse ones as well. My sources.list ended up looking like this:

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us.archive.ubuntu.com/ubuntu focal main restricted
deb-src http://us.archive.ubuntu.com/ubuntu focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://us.archive.ubuntu.com/ubuntu focal-updates main restricted
deb-src http://us.archive.ubuntu.com/ubuntu focal-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://us.archive.ubuntu.com/ubuntu focal universe
deb-src http://us.archive.ubuntu.com/ubuntu focal universe
deb http://us.archive.ubuntu.com/ubuntu focal-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu focal-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://us.archive.ubuntu.com/ubuntu focal multiverse
deb-src http://us.archive.ubuntu.com/ubuntu focal multiverse
deb http://us.archive.ubuntu.com/ubuntu focal-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu focal-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://us.archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
deb-src http://archive.canonical.com/ubuntu focal partner

deb http://us.archive.ubuntu.com/ubuntu focal-security main restricted
deb-src http://us.archive.ubuntu.com/ubuntu focal-security main restricted
deb http://us.archive.ubuntu.com/ubuntu focal-security universe
deb-src http://us.archive.ubuntu.com/ubuntu focal-security universe
deb http://us.archive.ubuntu.com/ubuntu focal-security multiverse
deb-src http://us.archive.ubuntu.com/ubuntu focal-security multiverse

Install Dependencies

$ sudo apt update
$ sudo apt install devscripts gcc git libaio-dev libattr1-dev libblkid-dev libkeyutils-dev liblz4-dev libscrypt-dev libsodium-dev liburcu-dev libzstd-dev make pkg-config uuid-dev zlib1g-dev
sudo apt build-dep linux

Get Bcachefs Source Code

$ git clone https://evilpiepirate.org/git/bcachefs-tools.git
$ git clone https://evilpiepirate.org/git/bcachefs.git

Edit Bcachefs-Tools Makefile

Comment out lines 79 and 80 of the bcachefs-tools Makefile to disable pytest. It causes issues with the current version.

$ cd bcachefs-tools
$ nano +79 Makefile
#check: tests bcachefs
#    cd tests; $(PYTEST)

Build BcacheFS-tools

$ cd bcachefs-tools && make deb && cd ..

Build BcacheFS

Get your kernel config:

There are plenty of different ways to configure the kernel, but I would recommend either grabbing a kernel config from one of the Ubuntu Mainline Builds or grab one of your existing configs from /boot/config-* 

You just have to download the linux-headers-*-generic_*_amd64.deb file and extract it somewhere. Inside that, you’ll need to extract the data.tar file. You’ll want to copy the /./usr/src/linux-headers-*-generic/.config file. 

Then just copy the .config into the bcachefs directory. 

Configure the kernel

This will ask you a few questions about how your want to configure your kernel. 

$ cd bcachefs
make oldconfig

Answer yes to the following three options:

bcachefs filesystem support (BCACHEFS_FS) [N/m/y/?] (NEW)
bcachefs quota support (BCACHEFS_QUOTA) [N/y/?] (NEW)
bcachefs POSIX ACL support (BCACHEFS_POSIX_ACL) [N/y/?] (NEW)

Build the kernel

$ make bindeb-pkg

Install

$ cd ../ && sudo dpkg -i bcachefs-tools*.deb linux-image-4*.deb linux-libc-dev*.deb

Reboot into your new kernel

You can now try out bcachefs!

Creating a BcacheFS Volume

There are endless options you can choose from when creating a BcacheFS volume, but I chose lz4 foreground compression, gzip background compression, and a write-back configuration.

For reference, my SSD is /dev/sdb and my hdd is /dev/sdc.

$ sudo bcachefs format --group ssd /dev/sdb --group hdd /dev/sdc --foreground_target ssd --background_target hdd --promote_target ssd --compression=lz4 --background_compression=gzip

​Mounting a BcacheFS Volume

Now that you’ve created your BcacheFS volume, you’ll need to mount it before use. Unfortunately, I haven’t found any way to mount the volume at boot using fstab, but there’s a workaround: cron. Cron is able to run a command on boot, and that’s exactly what we’ll do here.

You’ll need to recall your drive references, /dev/sdb and /dev/sdc in my case. The mount command looks like this:

$ sudo mount -t bcachefs /dev/sdb:/dev/sdc /mnt/bcfs

Modify the mount point (/mnt/bcfs) and drive references to whatever you’d like, and run the command. Run a df and make sure you see the volume is mounted.

Adding the mount command to cron

To enable mounting on boot, add the command to cron. Run $ sudo crontab -e and add the following line to the bottom of the file after modifying the command to fit your needs:

@reboot    mount -t bcachefs /dev/sdb:/dev/sdc /mnt/bcfs

You’re now ready to go. Copy some data into your mointpoint and check out what’s going on in the background with:

$ bcachefs fs usage /mnt/bcfs

Or check your configuration with:

$ sudo bcachefs show-super /dev/sdb

Leave a Reply