Ubuntu – How to install and use flashcache/bcache to cache HDD to SSD

bcachecachehard drivekernelssd

I want to know if there is anyone who has tried installing and running their kernel built with flashcache or bcache for SSD caching?

How did you manage to do it?

Best Answer

  • Well, we got a bcache answer but no flashcache answer. I chose flashcache because I already had an existing installation, so bcache was out of the question. To me it seemed easier to set up as well. I chose the DKMS method so I wouldn't be stuck rebuilding the module/tools every time I got a kernel upgrade.

    These steps are outlined in README-DKMS on Github.

    Building the Module

    1. The first thing you do is install the building prerequisites:

      sudo apt-get install dkms build-essential linux-headers-$(uname -r) git
      
    2. Then snag the source:

      git clone git://github.com/facebook/flashcache; cd flashcache
      
    3. Build and install the modules:

      make -f Makefile.dkms
      

    Creating a flashcache device

    (In this example I use writeback caching -- the default -- but flashcache can do writearound and writethrough as well)

    Caching a non-root (not mounted at /) device

    sudo flashcache_create -p back fcache /dev/sdbX /dev/sdaX Where fcache is the created device (/dev/mapper/fcache), /dev/sdaX is the SSD partion (or whole disk) and /dev/sdbX is the HDD partition.

    Caching your root device

    There are a few more steps if you're caching your root device. You will need an Ubuntu LiveCD/USB for this section.

    1. cd /path/to/flashcache/source

    2. make -f Makefile.dkms boot_conf

    3. Edit /boot/grub/grub.cnf and /etc/fstab to boot from /dev/mapper/fcache (I don't believe this step is really necessary, but it says to). Be sure to write down the UUID of your original root device.

    4. Reboot with the LiveCD/LiveUSB.

    5. Mount your root device: mount /dev/sda4 /mnt (/dev/sda4 is my Linux root partition)

    6. cd /mnt/path/to/flashcache/source

    7. sudo apt-get install dkms build-essential linux-headers-$(uname -r)

    8. make; sudo make install No need to do the whole DKMS setup in the live environment

    9. Unmount the root device sudo umount /mnt

    10. sudo flashcache_create -p back fcache /dev/sdbX /dev/disk/by-uuid/[UUID] Where fcache is the created device (it should be the same as you put in /etc/fstab and /boot/grub/grub.cnf, in my case it was fcache), /dev/sdbX is the SSD partition (or whole disk) and [UUID] is the UUID of your root partition.

    11. Reboot!

    Caveats when using the root device

    One minor annoyance when flashcache is used for the root device is that grub-probe fails to detect the root device and can mess up your boot menu so that you have two Ubuntu entires. But, it shouldn't matter which you use in all reality since the make -f Makefile.dkms boot_conf step above installs some scripts in your initrd that will detect and use the flashcache device.