I've tried to set up bcache in Ubuntu 14.04 with a fresh install and an empty /home partition (/dev/sdb2) as a backing device. I have a running system on my SSD and I'd like to use its /dev/sda2 partition to cache my /home . I've always managed to sort my ubuntu problems out from forums but I'm struggling to understand the basics here and need help:

  1. What account do I need to be logged in when I set up bcache in the first place? Obviously the user created during install on /dev/sdb2 has to be logged out for /home to be unmounted, so I set up a temporary user account on a separate partition to do it. This seems too clumsy already.

  2. make-bcache -B and -C both tell me that there are non-bcache superblocks on the device so I did sudo wipefs -a on both of the devices. The partitions then appear as unformatted without an UUID in GParted. Is this normal?

  3. If so, what happens to fstab and /home at boot? Do I need to use bcache's UUID in fstab? I did but the system didn't find the /home partition upon next boot.

  4. Both echo /dev/sdb2 > /sys/fs/bcache/register and echo /dev/sda2 > /sys/fs/bcache/register return 'Permission denied' messages; as I understand /sys cannot be written to.

    So echo /dev/sdb2 | sudo tee /sys/fs/bcache/register seems to have worked.

Can someone verify this is the proper way to do it in Ubuntu?

I seem to have managed to create, register and attach the backing drive but according to the tail /sys/block/bcache0/bcache/stats_total/* I only have bypassed data. My whole setup is quite a mess now so any clarification would be greatly appreciated.

  • Have you tested it? Appears that you know the "how-to", what you need to know? – Braiam Sep 14 '14 at 12:54
  • I tested it as above and I'm getting cache hits, misses and bypasses. Trouble is my backing device that is supposed to be my home partition is not mounted as home at startup but as a separate drive. So my /home is a folder on / at the moment and I'm testing bcache by copying files onto the backing device and accessing them. I was messing with fstab which was probably a mistake and I don't have a valid UUID for my /home partition now if that makes any sense.. What I need is an idiot-proof walk-through specifically for ubuntu. – Laszlo Almasi Sep 14 '14 at 22:53
  • OK, I messed up fstab and /home had the wrong UUID. It seems to work now. I would still be interested in how exactly is bcache supposed to be set up: from temporary user account, live CD/USB, or other? – Laszlo Almasi Sep 15 '14 at 0:09

With Ubuntu 15.10, alex's answer is no longer correct. The initramfs image is locked in the installer and will not be automatically re-generated when the system is installed. Thus one will have a bcache installation, but it won't be able to boot. I've written a more verbose description of the following process elsewhere; however, here are the basics:

1. Partitioning

Boot into the Ubuntu live-cd and create the following partition scheme with fdisk or gparted. Assuming /dev/sda is your SSD and /dev/sdb is your HDD:

/dev/sda1 - 1024 MB, EXT4, used for /boot (grub/grub2 doesn't support bcache)
/dev/sda2 - any format, for cache
/dev/sdb1 - EFI partition (if your machine needs it)
/dev/sdb2 - swap
/dev/sdb3 - any format, backing partition

2. Create the bcache device

Open up the terminal, wipe the file systems on the backing and caching device:

sudo wipefs -a /dev/sda2
sudo wifefs -a /dev/sdb3

Install bcache-tools and create the bcache device:

sudo apt-get update
sudo apt-get install bcache-tools
sudo make-bcache -B /dev/sdb3 -C /dev/sda2
sudo mkfs.ext4 /dev/bcache0

3. Install Ubuntu

Install the operating system using the custom partitioner as follows:

/dev/bcache0 - format EXT4, use as /
/dev/sda1    - format EXT4, use as /boot
/dev/sdb1    - EFI partition (if your machine needs it)
/dev/sdb2    - swap

DO NOT REBOOT after the installer completes!

4. Install bcache on the new installation

Using a chroot we install bcache-tools on the new installation. Setup the environment and enable DNS resolution

sudo mount /dev/bcache0 /mnt
sudo mount /dev/sda1 /mnt/boot
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys

For Ubuntu 17.10 or newer you also need to copy over the resolv.conf file so DNS resolution works within the chroot environment.

sudo mv /mnt/etc/resolv.conf /mnt/etc/resolv.conf.backup
sudo cp /etc/resolv.conf /mnt/etc/resolv.conf

Enter into the chroot and do the installation

sudo chroot /mnt
sudo apt-get update
sudo apt-get install bcache-tools

During the installation you should notice the initramfs is re-generated and installed to the (chroot-ed) /boot partition.

5. Cleanup

Cleanly dismount the filesystem and reboot.

sudo mv /mnt/etc/resolv.conf.backup /mnt/etc/resolv.conf # for 17.10+ only
sudo umount /mnt/sys
sudo umount /mnt/proc
sudo umount /mnt/dev
sudo umount /mnt/boot
sudo umount /mnt
sudo reboot
| improve this answer | |
  • Five years later and this still works well. Thanks @bklppenborg for updating the instructions for 20.04: kloppenborg.net/blog/2020/05/22/… – Paulo May 24 at 14:22
  • Thanks for the reminder about this post. I updated it to include the resolv.conf instructions for Ubuntu 17.10+. – bkloppenborg May 25 at 15:38

After some trial and error I've arrived at the following solution for a clean install:

  • Partition the HDD the way you like (assuming /dev/sdb2 is the space you want for your /home).
  • # apt-get install bcache-tools
  • # make-bcache -B /dev/sdb2 -C /dev/sda2 (This creates /dev/bcache0, but the UI installer can't use it yet.)
  • # mkfs.ext4 /dev/bcache0 (This makes the installer see a "partition /dev/bcache0" under "device /dev/bcache0" and allows you to use it as "/home" during installation.)
  • Run the installer as usual, be sure to select advanced disk partition options.
  • The installer creates initrd image with the bcache kernel module included and loaded due to that we've installed bcache-tools earlier, so after reboot it just works.
  • After booting the installed system, install bcache-tools once again, so that further updates don't cripple the boot process by omitting the necessary bcache kernel module from initrd image.
| improve this answer | |
  • I went without bcache in the end because I needed cacheing for both Ubuntu and Windows in a double-boot configuration plus I access my drives from another system as well. So I decided cacheing is just not suitable for this PC. Thanks for your help anyway. – Laszlo Almasi Jan 2 '15 at 20:26

I too tried and failed many times till I found these instructions: http://www.wdong.org/wordpress/blog/2014/05/28/installing-ubuntu-14-04-to-bcache/

They sound somewhat hairy but this is probably the only feasible way to get bcache going, at least until bcache becomes part of the ubuntu installer.

The only curious omission in the instructions is the very last stage.

After you've done everything, look up the UUID of the cache set in /sys/fs/bcache and do this:

echo <UUID> > /sys/block/bcache0/bcache/attach

If you'd like to enable writeback mode (which I'd strongly recommend):

echo writeback > /sys/block/bcache0/bcache/cache_mode

catting various files in /sys/block/bcache0/bcache/ will tell you all about how the cache is running. I set up my system using these instructions on July 26th this year and everything is running perfectly since. cat /sys/block/bcache0/bcache/stats_total/cache_hit_ratio shows a highly satisfactory 88 per cent and subjectively, the machine feels like an all-SSD setup.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.