How to Install and Configure Bcache: A Step-by-Step Guide

Learn how to combine the large storage capacity of a traditional hard drive with the fast performance of a solid-state drive on Linux using Bcache.

Combining Hard Drive Capacity with SSD Speed

What Is Bcache and How Does It Work?

Bcache (short for block cache) is a built-in Linux kernel feature that lets you use a fast solid-state drive (SSD or NVMe drive) as a high-speed cache for a slower, high-capacity mechanical hard disk drive (HDD). Instead of choosing between an expensive large SSD or a slow traditional hard drive, Bcache links both drives together into a single virtual storage device named /dev/bcache0. You can format and mount this virtual device with standard Linux filesystems like Btrfs or ext4, giving you fast everyday performance for frequently used data while keeping all the storage space of your hard drive.

Under the hood, Bcache works at the Linux block layer, meaning it caches small chunks of disk data rather than whole files. It is specially designed around how SSD flash memory works by grouping writes into erase-block-sized sections called buckets, which avoids slow random writes and reduces wear on your SSD. Bcache is also smart enough to recognize large sequential file transfers such as video copies or system backups and send them straight to the hard drive so they do not fill up or wear out your fast SSD cache.

Bcache offers multiple caching modes so you can choose the right balance between speed and data safety, and you can switch modes at any time without restarting your computer. By default, Bcache runs in writethrough mode, which speeds up read tasks while writing new data to both the SSD and the hard drive at the same time so your files remain completely safe even if the SSD fails. If you want faster write speeds as well, you can enable writeback mode, where new data is saved quickly to the SSD first and written neatly to the hard drive in the background. You can also choose writearound mode if you want to cache only read data while sending all new writes directly to the hard drive.

Major Prerequisites

  • A Linux system: Bcache is included in the mainline Linux kernel. This guide follows the official Arch Linux setup (package installation commands for Ubuntu/Debian and Fedora are also noted in Step 1).
  • Root or sudo access: You need administrator permissions to format drives, load kernel modules, and update boot configuration files.
  • One backing device (HDD or partition): A mechanical hard drive or partition to hold your main data (written as /dev/sdX1 in the commands below replace this with your real drive partition).
  • One cache device (SSD/NVMe or partition): A fast solid-state drive or partition to serve as the cache (written as /dev/sdY1 below replace this with your real SSD partition). If you plan to turn on writeback mode, do not share one single SSD across multiple hard drives, because an SSD failure would cause data loss.
  • Empty or partitioned target drives: Create your target partitions ahead of time using fdisk or parted if you are not using whole raw disks.
  • A full backup of important files: Running make-bcache formats both target partitions and permanently erases everything currently on them.
  • Arch User Repository (AUR) build tools: On Arch Linux, you need the base-devel and git packages installed so you can build and install bcache-tools.

Step-by-Step Installation

1. Install bcache-tools and Load the Kernel Module

On Arch Linux, install the required build tools, download bcache-tools from the AUR, and install it. Afterward, load the bcache kernel module and verify that the /sys/fs/bcache folder exists.

Bash
sudo pacman -S --needed base-devel git
git clone https://aur.archlinux.org/bcache-tools.git
cd bcache-tools
makepkg -si

# Load the bcache module into the Linux kernel
sudo modprobe bcache
ls /sys/fs/bcache

(Note: On Debian or Ubuntu, run sudo apt install bcache-tools. On Fedora, run sudo dnf install bcache-tools.)

2. Check Your Drives and Wipe Old Signatures

Check your exact drive and partition names carefully using lsblk -f. Then clear any leftover filesystem signatures from both partitions so make-bcache does not fail with a Device or resource busy error.

Bash
# View all connected drives and partitions
lsblk -f

# Erase old filesystem signatures on the HDD (sdX1) and SSD (sdY1)
sudo wipefs -a /dev/sdX1
sudo wipefs -a /dev/sdY1

3. Format the Backing Device and Cache Device

Use -B to format your slow hard drive partition (which creates /dev/bcache0) and -C to format your fast SSD partition.

Bash
# 1. Format the slow HDD partition as the backing device
sudo make-bcache -B /dev/sdX1

# 2. Format the fast SSD partition as the cache device
sudo make-bcache -C /dev/sdY1

Optional Alignment for 4K Drives: By default, make-bcache uses a 512B block size and a 128kB bucket size. If your hard drive uses 4k sectors and your SSD has a 2M erase block size, pass --block 4k to both commands so their block sizes match (mismatched block sizes will cause an Invalid argument error when attaching):

Bash
sudo make-bcache --block 4k -B /dev/sdX1
sudo make-bcache --block 4k --bucket 2M -C /dev/sdY1

(Tip: You can also format and link both drives in one single step with sudo make-bcache -B /dev/sdX1 -C /dev/sdY1. On distributions with newer upstream snapshots of bcache-tools, sudo bcache make -B /dev/sdX1 -C /dev/sdY1 works the exact same way.)

The bcache-tools package installs udev rules that register your drives with the kernel right away. If /dev/bcache0 does not show up automatically, register both partitions manually:

Bash
echo /dev/sdX1 | sudo tee /sys/fs/bcache/register
echo /dev/sdY1 | sudo tee /sys/fs/bcache/register

4. Attach the SSD Cache to the Backing Device

If you formatted your backing drive and cache drive with separate commands, link them together using the SSD's cache set UUID (cset.uuid). You only need to run this once udev rules remember the connection after every reboot.

Bash
# 1. Find the cset.uuid of your SSD cache partition
sudo bcache-super-show /dev/sdY1 | grep cset.uuid

# 2. Attach that cset.uuid to bcache0 (replace the example UUID with your own)
echo f0e01318-f4fd-4fab-abbb-d76d870503ec | sudo tee /sys/block/bcache0/bcache/attach

5. Configure the Cache Mode and Make Settings Permanent

Check which cache mode is currently active (the active mode appears inside square brackets, defaulting to [writethrough]):

Bash
cat /sys/block/bcache0/bcache/cache_mode

If your SSD caches only this single hard drive and you want faster write speeds in addition to read speeds, switch to writeback mode:

Bash
echo writeback | sudo tee /sys/block/bcache0/bcache/cache_mode

While cache_mode is stored on disk, extra tuning values in /sys such as sequential_cutoff (which skips large file copies above a set size, defaulting to 4.0M) reset when you reboot. Create a systemd-tmpfiles configuration file to apply your preferred settings automatically on every boot:

Bash
sudo tee /etc/tmpfiles.d/bcache.conf << 'EOF'
w /sys/block/bcache0/bcache/sequential_cutoff - - - - 1M
w /sys/block/bcache0/bcache/cache_mode - - - - writeback
EOF

sudo systemd-tmpfiles --create /etc/tmpfiles.d/bcache.conf

Important Safety Note: Do not turn on Bcache's internal discard setting in /sys, as the ArchWiki warns it causes system freezes and bugs. Use systemd's periodic fstrim.timer for SSD TRIM maintenance instead.

6. Create a Filesystem and Set Up Auto-Mounting

Format /dev/bcache0 with your preferred filesystem (such as Btrfs or ext4), mount it, and add its filesystem UUID to /etc/fstab so Linux mounts it automatically when your computer starts:

Bash
# Format bcache0 with Btrfs (or use ext4: sudo mkfs.ext4 /dev/bcache0)
sudo mkfs.btrfs /dev/bcache0

# Create a mount folder and mount the drive
sudo mkdir -p /mnt/bcache
sudo mount /dev/bcache0 /mnt/bcache

# Add the filesystem UUID to /etc/fstab for automatic mounting on boot
FS_UUID=$(sudo blkid -s UUID -o value /dev/bcache0)
echo "UUID=${FS_UUID}  /mnt/bcache  btrfs  defaults,noatime  0  0" | sudo tee -a /etc/fstab

7. Configure Initramfs for Early Boot Support (Arch Linux)

If /dev/bcache0 holds your root (/) partition or is needed early during startup, open /etc/mkinitcpio.conf in a text editor. Add bcache to the MODULES array, and add bcache inside the HOOKS list strictly between block and filesystems:

Ini, TOML
# /etc/mkinitcpio.conf
MODULES=(bcache)
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block bcache filesystems fsck)

Save the file and rebuild your initramfs image:

Bash
sudo mkinitcpio -P

8. Verify That Bcache Is Working

Run the commands below to confirm that bcache0 is linked to both partitions and check its live cache health and hit statistics:

Bash
# Confirm bcache0 is listed under both sdX1 and sdY1
lsblk

# Check cache status ('clean' means synced, 'dirty' means unwritten writeback data is in cache)
cat /sys/block/bcache0/bcache/state

# See how much unwritten data is currently stored on the SSD
cat /sys/block/bcache0/bcache/dirty_data

# View total cache hits, misses, and hit ratio
tail -n +1 /sys/block/bcache0/bcache/stats_total/*

Safe Teardown and Reset Commands

If you ever want to remove Bcache and reuse your drives normally, do not wipe the partitions while Bcache is still running. Doing so triggers a Device or resource busy error and if writeback mode is active, wiping the SSD early will destroy any data that has not been saved to the hard drive yet.

Follow these steps in exact order to flush your data, stop Bcache cleanly, and reset both partitions:

Bash
# 1. Unmount the filesystem
sudo umount /mnt/bcache

# 2. Detach the SSD cache (this safely flushes all dirty writeback data to the HDD)
echo 1 | sudo tee /sys/block/bcache0/bcache/detach

# 3. Check the state and wait until it says 'no cache' before continuing!
cat /sys/block/bcache0/bcache/state

# 4. Stop the backing device and unregister the cache set (replace with your cset.uuid)
echo 1 | sudo tee /sys/block/bcache0/bcache/stop
echo 1 | sudo tee /sys/fs/bcache/f0e01318-f4fd-4fab-abbb-d76d870503ec/stop

# 5. Wipe the Bcache superblocks from both partitions
sudo wipefs -a /dev/sdX1 /dev/sdY1

Finally, remove the /mnt/bcache line you added to /etc/fstab (and delete /etc/tmpfiles.d/bcache.conf if you created one) so your system does not look for the removed Bcache device the next time you reboot.

Final Thoughts

By completing this guide, you have successfully installed and configured Bcache on your Linux system through the following key steps.

  • Installed the Bcache tools and kernel module: Built and installed the bcache-tools package and loaded the bcache module into the Linux kernel.
  • Prepared and formatted both drives: Cleared leftover partition signatures using wipefs, then formatted your hard drive as the backing device (-B) and your SSD as the cache device (-C) with make-bcache.
  • Attached the SSD cache to the hard drive: Retrieved your SSD's cache set UUID (cset.uuid) and linked it to /dev/bcache0 so both drives work together as a single virtual storage device.
  • Configured cache modes and permanent boot settings: Selected your caching mode (writethrough or writeback) and created a systemd-tmpfiles rule so your custom performance settings stay active after every reboot.
  • Created a filesystem and enabled automatic mounting: Formatted /dev/bcache0 with a Linux filesystem, added its UUID to /etc/fstab, and added the bcache hook to /etc/mkinitcpio.conf for early boot support.
  • Verified cache health and learned safe removal: Checked live cache states and hit ratios in /sys/block/bcache0/bcache/, and learned how to safely flush unwritten data, stop Bcache, and reset both partitions without losing files.

With Bcache active on your machine, you now get fast SSD responsiveness for your everyday tasks while keeping all the large, affordable storage capacity of your traditional hard drive.

Dedicated servers in every region

Choose the location closest to your users.