Mounting BCacheFS on Boot

Mounting BCacheFS on Boot

BCacheFS is an exciting Copy on Write (COW) Linux filesystem that is being developed by Kent Overstreet. The filesystem is based on cache and is already feature-full, though it’s in the alpha stage. It has worked well for me, aside from one issue: how to go about mounting bcachefs on boot.

I was able to compile BCacheFS on Ubuntu 18.04 by following a handy Reddit tutorial (also saved on this site), but was not able to mount the filesystem on a reboot. While not a big deal, mounting bcachefs on boot would alleviate issues where I forget to mount the filesystem after a reboot, saving time wasted on troubleshooting.

So, after some time Googling and some trial and error, I thought I could cat /proc/mounts to get the correct mount options:

$ cat /proc/mounts
/dev/sdb:/dev/sdc /mnt bcachefs rw,relatime,compression=lz4,background_compression=gzip,foreground_target=ssd,background_target=hdd,promote_target=ssd 0 0

I created an fstab entry based on that output but the VM would not boot. I’m guessing that it’s because of the unusual /dev/sdb:/dev/sdc drive that the entry is pointing to.

Finally, I realized that it would be easiest to add a crontab entry that would mount the filesystem on boot:

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

While this solution may not be the most elegant or correct, it works.