HIRO GEAR
Raspberry Pi

Storage Acceleration Setup Using Bcache on Raspberry Pi 5

Storage Acceleration Setup Using Bcache on Raspberry Pi 5

Introduction

While the Raspberry Pi 5 can utilize USB and SATA-connected storage, large-capacity HDDs have the drawback of slow read and write speeds. This article introduces a setup that leverages Bcache, a Linux kernel feature that uses an inexpensive SSD as a cache to boost HDD speeds to SSD-like levels.


Environment

ItemDetails
HardwareRaspberry Pi 5 Model B (8GB RAM)
OSDebian Bookworm (Linux 6.12, aarch64)
BootmicroSD 119GB (/boot/firmware)

Storage Configuration

SSD (MSI S270 240GB / SATA)  ← Cache device
 └─ sda2 (200GB) → bcache cache

HDD1 (1.8TB / sdb)
 ├─ sdb1 (1.5TB) ─┐
 └─ sdb2 (327GB)  ─┤
                   │ RAID1 (Mirroring)
HDD2 (3.6TB / sdc) │
 ├─ sdc1 (1.5TB) ─┤→ md2  (1.5TB RAID1) → bcache0 → /data (1.5TB)
 └─ sdc3 (336GB)  ─┘→ md127 (327GB RAID1) → bcache1 → /     (327GB)

Key Points

  • Redundancy via RAID1 (mirroring) across 2 HDDs → Protects data even if one HDD fails

  • Using an SSD as a cache layered over the RAID1 volumes to improve access speed

  • Configured the root partition (/) and data partition (/data) as separate, independent bcache devices


RAID1 (Mirroring) Configuration

What is RAID1?

RAID1 is a mirroring method that writes the exact same data to two or more disks. Even if one disk fails, data can continue to be read from the other disk, preventing data loss.

Write → [HDD1] ─┐
                ├─ Identical data
        [HDD2] ─┘

If HDD1 fails → Automatically continues reading from HDD2 (zero downtime)

RAID1 Arrays in This Setup

ArrayMember DevicesSizeMount Point
md2sdb1 + sdc11.5TBVia bcache0 → /data
md127sdb2 + sdc3327GBVia bcache1 → /

RAID1 Setup Steps (mdadm)

1. Install mdadm

sudo apt install mdadm

2. Create RAID1 Arrays

# For /data (1.5TB × 2)
sudo mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

# For / (327GB × 2)
sudo mdadm --create /dev/md127 --level=1 --raid-devices=2 /dev/sdb2 /dev/sdc3

3. Persist Configuration

sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u

Checking RAID1 Status

cat /proc/mdstat

Example output when healthy:

md2 : active raid1 sdc1[1] sdb1[2]
      1610480640 blocks super 1.2 [2/2] [UU]

md127 : active raid1 sdc3[0] sdb2[1]
      342768704 blocks super 1.2 [2/2] [UU]

[UU] = Both disks are operating normally. If it becomes [_U] or [U_], one disk has failed.

Handling Failures

# Remove failed disk
sudo mdadm /dev/md2 --fail /dev/sdb1 --remove /dev/sdb1

# Add new disk and rebuild
sudo mdadm /dev/md2 --add /dev/sdb1

# Monitor rebuild progress
watch cat /proc/mdstat

Bcache Configuration Details

bcache0 (for /data, 1.5TB)

ParameterValueDescription
cache_modewritebackWrites also go through the cache (fast)
sequential_cutoff0 (disabled)Sequential access is also cached
readahead_cache_policyallReadahead data is also cached
StatecleanCache and backing device are synchronized

bcache1 (for /, 327GB)

ParameterValueDescription
cache_modewritebackWrites also go through the cache (fast)
sequential_cutoff4MBSequential reads/writes of 4MB or more bypass the cache
readahead_cache_policyallReadahead data is also cached
StatedirtyUnflushed data exists in cache (normal)

Cache Hit Rate (Actual Results)

DeviceHitsMissesHit Rate
bcache0 (/data)920,17872,25792%
bcache1 (/)2,205,81475,13496%

The root partition achieved a 96% cache hit rate, delivering a dramatic improvement in perceived speed compared to standalone HDDs.


How Bcache Works

Application
  ↓
bcache (Kernel layer)
  ├─ Cache HIT  → Fast read from SSD (μs order)
  └─ Cache MISS → Read from HDD & save to SSD cache (ms order)

What is writeback Mode?

A mode where write requests are written to the SSD first and asynchronously flushed to the HDD later.

  • Advantage: Write speeds match SSD performance

  • Disadvantage: If the SSD fails suddenly, unwritten data in the cache may be lost (in this setup, the HDD side is protected with RAID1)


Bcache Setup Steps (Overview)

1. Install Package

sudo apt install bcache-tools

2. Create Cache Device (SSD Side)

sudo make-bcache -C /dev/sda2

3. Create Backing Devices (HDD/RAID Side)

sudo make-bcache -B /dev/md2
sudo make-bcache -B /dev/md127

4. Register and Attach Cache Device

# Check cache set UUID
ls /sys/fs/bcache/

# Attach cache to backing devices
echo  | sudo tee /sys/block/bcache0/bcache/attach
echo  | sudo tee /sys/block/bcache1/bcache/attach

5. Change Cache Mode to writeback

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

6. Persist Settings (Apply at boot via /etc/rc.local or udev rules)

# Example /etc/rc.local
echo writeback > /sys/block/bcache0/bcache/cache_mode
echo writeback > /sys/block/bcache1/bcache/cache_mode
echo 0 > /sys/block/bcache0/bcache/sequential_cutoff

Current Usage

/dev/bcache1 (/)     117GB used out of 321GB (39%)
/dev/bcache0 (/data) 601GB used out of 1.5TB (42%)

Summary

ComponentRole
HDD × 2 (RAID1)Large capacity & redundancy
SSD (Bcache cache)Improved access speed
writeback modeMaximized write speed

Even a modest single-board computer like the Raspberry Pi 5 can be utilized as a practical file server and home server by combining it with Bcache.

A cache hit rate of 96% means that for everyday workloads, it operates at virtually SSD speeds.


Created: March 2026