This is a guide about how to setup an Arch Linux system with a main HDD for storage and a SSD used as a backing to speed up data transfers. (Especially recently used data)
This has been adapted from a pdf format into the web. For those interested, the pdf can be found here.
This is a guide for Arch Linux power users. It is assumed that the reader is familiar with the Arch Linux install process. Once this setup is complete the user will have a fully functioning Arch Linux environment that is backed by a larger HDD with a smaller but faster SSD cache. In many modern operating systems, to get this same setup one would have to purchase expensive software or use RAID technologies that become attached to the motherboard that they were installed on. This guide offers a simple, fast, and robust setup that will migrate wherever the Arch Linux setup may need to as it will not be attached to any motherboard or outdated software. Furthermore, if the Arch Linux user ever wants to add even more data to the setup this only requires a few commands to BCache, LVM, and the user’s file system of choice. (This is not covered in this how to.)
Stuff you will need
- At least one HDD for the data backing
- At least one SSD (or faster drive) for the cache
- Computer fully capable of running Arch Linux
- Disk with Arch Linux ISO
Preparing to Install
Before any installing can be done you will need to build the bcache-tools package and copy it onto the flash drive. (You will probably need a functioning computer running Arch Linux to do this.) While archiso includes the kernel drivers needed by bcache it doesn’t include the actual userspace programs that are needed to actually use bcache.
# to build the package you might chose to run makepkg -sr
Boot the computer you wish to install to and install the bcache-tools package from the flash drive.
pacman -Sy pacman -U path/to/bache-tools.pkg.tar.xz
You can safely ignore the errors. These are just trying to make sure that kernel support is added to the kernel image that is loaded on boot. This, of course, fails because we are using a read-only live CD. This is OK because the ISO has the support built-in anyway.
Preparing the partitions
Warning be extra careful in this step. Using the wrong drives could mean needing restarting the install process from the beginning.
First you should delete all partitions that may exist so that you can make room for the new partitions. (duh ;))
You will want to make a partition for
/boot on your SSD for extra speed when booting. This should be
500MB in size just to be sure that you won’t run out of room no matter if you are using Legacy BIOS or UEFI. The rest of the SSD and HDD space will be used for actual caching and as the storage backing.
Make sure you allocate space for the bcache partitions in the empty space on the HDD and SSD.
If all is well, you should get similar output to below for
/dev/sda is the HDD and
/dev/sdb is the SSD)
Next, inform bcache of the partitions, instruct bcache to create bcache partitions, and link them together all in a single command.
make-bcache -B /dev/backing1 /dev/backing2 -C /dev/cache1 /dev/cache2
If successful, you will get an output with a few UUIDs of the bcache partitions. Furthermore, you will now see a new device:
/dev/bcache0. This is the new cache enabled device.
Now, you will make an LVM partition setup from
Create physical LVM volume:
Create a volume group. In this example “Arch” is chosen as the physical group name:
vgcreate Arch /dev/bcache0
Create swap logical volume. Change 1G to the desired swap size.
lvcreate -L 1G Arch -n Swap
Create root partition. This command will use all remaining space. This may not be suitable for users who want to make use of lvm’s partition imaging features or create more partitions after the install.
lvcreate -l 100%FREE Arch -n Root
These new partitions should now be visible under
/dev/mapper/. If successful, you should have something like this for the partitions scheme.
Formatting the Partitions
Now you just need to format the partitions. This should be something an experienced Arch Linux user should be able to figure out. Unless you have a specific need, I suggest EXT4 and EXT2 for the root and boot partitions respectively.
# Format boot partition mkfs.ext2 /dev/bootpartition # Format root partition mkfs.ext4 /dev/Arch/Root # Create swap partition mkswap /dev/Arch/Swap
Mounting the partitions
Now mount the partitions and activate the swap.
swapon /dev/Arch/Swap mount /dev/Arch/Root /mnt mkdir /mnt/boot mount /dev/bootpartition /mnt/boot
Check the results using
mount -l and
Installing Arch Linux
Install Arch Linux as normal. (I assume the reader knows how to do that already because it falls outside the scope of this post.) This guide may be useful for those (normal) people who don’t know all of the steps by heart. When it comes time to install the bootloader proceed to the following instructions.
Installing bcache-tools in new Arch Install
Install the bcache-tools package in the new Arch Linux install with
pacman -U just like how was done before.
/etc/mkinitcpio.conf and add
bcache to the list of modules.
... MODULES="bcache" ...
bcache lvm2 in that order to the list of hooks before
filesystems but after
block. (WARNING: The exact placement here is critical!) This is so linux knows how to read the BCache and LVM partitions.
... HOOKS="... block bcache lvm2 filesystems ..." ...
Regenerate the Linux image in /boot/: If successful there will be no errors. (A few warnings is likely fine.)
mkinitcpio -p linux
Your output should look something like this:
pacman -S grub
/etc/default/grub and add
root=/dev/path/to/root/device that way
Linux knows where to find the root partition because it needs it early on.
Install grub to the disk that has the boot partition:
grub-install --recheck /dev/sdx
Write grub’s configuration files to the boot partition:
grub-mkconfig -o /boot/grub/grub.cfg
Reboot If all went well your new cache enabled Arch Linux install will boot and it is ready for tinkering.
Why Bache? Wouldn’t it be better to use LVM’s caching feature?
I noticed that LVM did not play well with grub and had difficulty generating boot entries for booting even if there was a separate partition for