Compiling and Installing BCacheFS on Ubuntu 18.04

Compiling and Installing BCacheFS on Ubuntu 18.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.

Edit the sources.list

$ sudo nano /etc/apt/sources.list

Uncomment the deb-src lines and the universe and multiverse ones as well

deb http://ca.archive.ubuntu.com/ubuntu/ bionic main restricted 

deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic main restricted 

deb http://ca.archive.ubuntu.com/ubuntu/ bionic-updates main restricted 

deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic-updates main restricted 

deb http://ca.archive.ubuntu.com/ubuntu/ bionic universe 

deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic universe 

deb http://ca.archive.ubuntu.com/ubuntu/ bionic-updates universe 

deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic-updates universe 

deb http://ca.archive.ubuntu.com/ubuntu/ bionic multiverse 

deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic multiverse 

deb http://ca.archive.ubuntu.com/ubuntu/ bionic-updates multiverse 

deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic-updates multiverse 

deb http://ca.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse 

deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse

Now update your package list

$ sudo apt update

Install the necessary dependencies:

$ 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

Grab the bcachefs and bcache-tools source code:

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

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

Build the bcachefs userspace utility

$ cd bcachefs-tools make deb cd ..

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

bcachefs filesystem support (BCACHEFS_FS) [N/m/y/?] (NEW)

Answer “y” to build Bcachefs support into the kernel, answer “m” to build bcachefs as a loadable kernel module. 

bcachefs quota support (BCACHEFS_QUOTA) [N/y/?] (NEW)

Answer “y” if you plan to use disk quotas, otherwise you can answer “n”. 

bcachefs POSIX ACL support (BCACHEFS_POSIX_ACL) [N/y/?] (NEW)

Answer “y” if you plan to use access control lists, otherwise you can answer “n”. 

Finally, there are a couple more questions about development-related options, but I usually leave them off. 

Build the kernel

$ make bindeb-pkg

Or optionally, build the kernel using 3 cores (jobs) and append the short git commit hash to the version (so you can easily go back and figure out what your kernel was built against). 

$ make bindeb-pkg -j 8 EXTRAVERSION=-$(git rev-parse --short HEAD) LOCALVERSION=

Install your newly-built bcachefs utility and kernel

$ cd ..

$ sudo dpkg --install bcachefs-tools*.deb linux-image-4*.deb linux-libc-dev*.deb

Reboot into your new kernel

You can now try out bcachefs!

——-

I’m assuming that you’ve already compiled and installed the bcachefs and bacachefs-tools git repos and rebooted the system according to this guide. I’m also assuming you want a UEFI install.

——-

For this example, the drive is at /dev/sdb. You can use gparted or gnome-disks to double-check.

Open Gparted or Disks (gnome-disks) and create a new GPT partition table.

With gparted, create a 250MB FAT32 partition with 2MB before it and everything else after it. This will be /boot/efi(/dev/sdb1)

Create ~2GB EXT2 partition with everything else after that. This will be /boot (/dev/sdb2)

Create one more partition of any kind to the size you want. If you have 200GB left, use it all minus what you want for swap. This will be / (/dev/sdb3)

Create the swap partition if you want swap. (/dev/sdb4)

Still using gparted, assign the flag “esp” and “boot” to the EFI partition. (/dev/sdb1)

Apply Changes

Open a terminal (CTRL + ALT+ T)

sudo bcachefs format /dev/sdb3

It’ll ask you to confirm. Double check with gparted or gnome-disks to verify it’s the right one, and then enter in y.

Paste the following into the terminal (THIS ASSUMES THE DRIVE IS /dev/sdb!!!)

sudo mount /dev/sdb3 /mnt

sudo mkdir /mnt/boot

sudo mount /dev/sdb2 /mnt/boot

sudo mkdir /mnt/boot/efi

sudo mount /dev/sdb1 /mnt/boot/efi

Everything should be ready for chrooting

Installing bcachefs on Ubuntu is no small feat, but you’ve done it! You’re not finished, however. For getting the filesystem to mount on boot, see my post on that.