The Hybrid Storage Dilemma: HDD vs. SSD
Storage management is always a balancing act between cost, capacity, and speed. While NVMe SSDs have become the standard for boot drives, using them for multi-terabyte data storage remains expensive. On the other hand, traditional Hard Disk Drives (HDDs) offer massive space for pennies per gigabyte but suffer from sluggish I/O performance, especially during random read/write operations.
This is where bcache comes into play. Bcache is a Linux kernel patch that allows you to use a fast drive (typically an SSD) as a cache for one or more slower drives (HDDs). Unlike simple software RAID, bcache understands which data is frequently accessed and moves it to the faster tier automatically. On my production Ubuntu 22.04 server with 4GB RAM, I found this approach significantly reduced processing time for database-heavy tasks that previously choked on raw HDD latency.
Bcache vs. Other Caching Methods
Before jumping into the configuration, it helps to understand where bcache sits compared to alternatives like LVM Cache or ZFS L2ARC.
- LVM Cache: Integrated into the Logical Volume Manager. It is flexible but can be more complex to configure if you aren’t already using LVM extensively.
- ZFS L2ARC/ZIL: Excellent performance, but requires you to use the ZFS filesystem. Bcache is filesystem-agnostic; you can run ext4, XFS, or Btrfs on top of it.
- Bcache: Operates at the block level. It is highly efficient for random I/O and has been part of the mainline Linux kernel for years, making it incredibly stable for production environments.
Pros and Cons of Using Bcache
Every architectural choice has trade-offs. My experience with bcache has highlighted a few specific areas you should consider before migrating your data.
The Advantages
- Cost Efficiency: You get the speed of an SSD for your most active data while keeping the bulk storage on cheap HDDs.
- Transparency: Once configured, the system sees a single block device. You don’t have to manually move files between drives.
- Write Optimization: Bcache can group random writes into sequential writes, which HDDs handle much better.
The Drawbacks
- Setup Complexity: You cannot easily convert an existing drive with data into a bcache device without formatting it. You need a backup-and-restore strategy.
- Failure Risk: If you use “write-back” mode and the SSD fails, you risk losing data that hadn’t yet been synced to the HDD.
Recommended Setup: Choosing Your Caching Mode
Bcache offers three primary modes. Choosing the right one depends entirely on your data safety requirements.
- Writethrough: The safest mode. Data is written to both the SSD and HDD simultaneously. Read performance is boosted, but write performance remains limited by the HDD speed.
- Writeback: The fastest mode. Data is written only to the SSD first and flushed to the HDD later. This provides a massive performance boost but carries a risk if the SSD fails or power is lost.
- Writearound: Similar to writethrough, but it avoids caching writes to prevent the SSD from being filled with data that might not be read again soon.
For most of my builds, I use Writeback combined with a high-quality UPS (Uninterruptible Power Supply) and regular backups. The performance gains are simply too high to ignore.
Implementation Guide: Setting Up Bcache
For this setup, let’s assume /dev/sdb is your fast SSD (caching device) and /dev/sdc is your large HDD (backing device). Warning: These steps will erase all data on the target drives.
1. Install Necessary Tools
First, ensure your system has the bcache utilities installed. On Debian-based systems like Ubuntu or AlmaLinux, the package name is usually the same.
sudo apt update
sudo apt install bcache-tools
2. Prepare the Drives
We need to wipe the partition tables of the drives to ensure a clean start. Use wipefs to remove any existing signatures.
sudo wipefs -a /dev/sdb
sudo wipefs -a /dev/sdc
3. Create the Bcache Devices
We define the backing device (HDD) and the caching device (SSD). You can do this in one command:
sudo make-bcache -B /dev/sdc -C /dev/sdb
The -B flag defines the backing device, and -C defines the cache. This command initializes both and links them together.
4. Registering the Device
After creation, a new virtual device will appear, typically at /dev/bcache0. You can verify this by checking the kernel messages or listing the block devices:
lsblk
dmesg | grep bcache
5. Formatting and Mounting
Now, treat /dev/bcache0 like any other hard drive. Format it with your preferred filesystem and mount it.
sudo mkfs.ext4 /dev/bcache0
sudo mkdir /mnt/data
sudo mount /dev/bcache0 /mnt/data
6. Tuning for Performance (Writeback Mode)
By default, bcache starts in writethrough mode. To unlock the full potential I mentioned earlier, you need to manually switch it to writeback. You do this by writing to the sysfs interface:
echo writeback | sudo tee /sys/block/bcache0/bcache/cache_mode
To make this change permanent across reboots, you may need a simple udev rule or a systemd service, as some kernels revert to the default mode.
Monitoring and Maintenance
Once the system is running, you’ll want to see if the SSD is actually doing its job. You can check the cache hit ratio via the /sys filesystem:
cat /sys/block/bcache0/bcache/stats_total/cache_hit_ratio
A high percentage (e.g., 85%+) indicates that your hot data is being served effectively from the SSD. If the ratio is low, it might mean your working set of data is larger than your SSD capacity.
Handling SSD Failure
If the SSD fails while in writeback mode, the /dev/bcache0 device will likely become I/O blocked to prevent corruption. If you need to recover the backing device (HDD) independently, you can “unregister” the cache, but be aware that data loss is possible if the cache wasn’t clean. This is why I always monitor SSD health using smartmontools.
sudo smartctl -a /dev/sdb
Final Thoughts
Bcache is a fantastic way to breathe new life into old hardware or build a high-capacity server without breaking the bank. By offloading the heavy lifting of random I/O to a small SSD, your massive HDD arrays can finally keep up with modern application demands. Just remember: always keep a backup, especially when chasing the high-performance writeback mode.

