Create a bcache SSD Cache Safely with make-bcache
You will finish with a dedicated block device formatted as a bcache cache device, using the installed make-bcache command, and a way to inspect the resulting bcache superblock. This is a destructive storage operation: formatting the wrong device can destroy its contents.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about 20 minutes for identification, checking and the format itself. You need the bcache-tools package, a Linux kernel with bcache support for the later assembly steps, and an SSD or partition that you have deliberately set aside. This guide stops after creating and verifying the cache metadata. It does not attach the cache to a backing device or create a filesystem.
The examples were checked with bcache-tools 1.0.8-5build1. The installed command's help lists more options than the local make-bcache(8) page, so use the local help as the final authority for flags available on your machine.
1. Check the installed command
Start with read-only checks. These commands do not need elevated privileges:
$ command -v make-bcache
/usr/sbin/make-bcache
$ dpkg-query -W -f='${Package} ${Version}\n' bcache-tools
bcache-tools 1.0.8-5build1
$ make-bcache --help
Usage: make-bcache [options] device
On this installation, --help shows -C, --cache for a cache, -b, --bucket for the bucket size, and additional options such as --cset-uuid, --writeback and --discard. The installed manpage documents the cache operation, UUID and bucket size, with a default bucket size of 128k. Keep the command and documentation versions together when writing a script.
Checkpoint: if command -v finds a different binary, or the package version is not the one shown above, stop and inspect that installation's help before copying the examples.
2. Identify the cache device before using sudo
Find the candidate device and its current identity with read-only commands:
$ lsblk -o NAME,PATH,SIZE,TYPE,FSTYPE,MOUNTPOINTS,MODEL,SERIAL
$ findmnt
$ ls -l /dev/disk/by-id/
Use a stable /dev/disk/by-id/ path in the final command where one exists. A device name such as /dev/sdb can change after a reboot or when hardware is added. Confirm the size, model and serial number against the physical SSD. Check every partition as well as the whole disk; selecting a whole disk when you intended a partition is an easy way to erase more than planned.
Do not proceed if the candidate is mounted, contains a needed filesystem, belongs to an active RAID or LVM volume, or is being used by another service. Stop those workloads through your normal change process and preserve a tested backup. make-bcache has no undo operation. Recovery means restoring the data or rebuilding the device layout from your backup.
3. Confirm the target is really disposable
Replace the example path with the device you identified. The following checks are still read-only:
$ CACHE_DEV=/dev/disk/by-id/REPLACE_WITH_THE_EXACT_SSD_ID
$ readlink -f "$CACHE_DEV"
/dev/sdb
$ lsblk -o PATH,SIZE,TYPE,FSTYPE,MOUNTPOINTS "$CACHE_DEV"
$ findmnt --source "$CACHE_DEV" || true
The resolved path and the size must match your change record. An empty findmnt result is useful, but it does not prove that the device is not part of a higher-level storage stack. Also check your monitoring, backup, container and virtual-machine configuration before formatting.
Checkpoint: write down the exact path you will format and ask a second operator to compare it with the physical device. Only continue when the target contains no data you need.
4. Choose a bucket size
Allocation and cache-hit accounting use buckets. The local manpage says a smaller bucket can use cache space more finely but can reduce write performance. It suggests matching the SSD erase-block size, commonly in the 128k to 512k range, and requires a power of two. The default is 128k.
If you have no measured erase-block information, leave the default in place. An explicit value makes a reviewed change easier to recognise:
$ BUCKET_SIZE=128k
$ printf 'cache device: %s\nbucket size: %s\n' "$CACHE_DEV" "$BUCKET_SIZE"
cache device: /dev/disk/by-id/REPLACE_WITH_THE_EXACT_SSD_ID
bucket size: 128k
Do not casually choose a smaller value because it sounds more efficient. The trade-off is between utilisation and write performance, and this setting is part of the cache format.
5. Format the cache device
This is the point of no return for the device's existing bcache-relevant metadata and normally its usable data. Use elevated privileges only after the earlier checks pass:
$ sudo make-bcache --cache --bucket "$BUCKET_SIZE" "$CACHE_DEV"
Creating a cache device
The exact success text can vary with the package build. A successful command returns exit status zero. If it fails, do not immediately retry with another device or option. Read the error, check that the device is the intended one, and confirm that no process has it open.
The local manpage also documents -C as the short form of --cache. The equivalent compact command is:
$ sudo make-bcache -C -b 128k "$CACHE_DEV"
Do not add --writeback, --discard or a custom UUID merely to make the command look complete. The installed help exposes those options, but each changes the resulting configuration and needs a specific storage design. The older local manpage's -B description also says backing-device kernel functionality is not implemented; this guide therefore does not present it as a working backing-device workflow.
6. Verify the bcache superblock
Inspect the device with the companion read-only tool:
$ sudo bcache-super-show "$CACHE_DEV"
sb.magic bcache
sb.version 1
dev.label
dev.uuid ...
dev.type cache
Formatting output is build-specific, so treat the displayed UUID as an example rather than a value to copy. The useful checks are that the command succeeds, the superblock identifies itself as bcache, and the device type is cache. If your output does not identify a cache device, stop before attempting registration or attachment.
For a second read-only check, inspect the block-device signature:
$ sudo file -s "$CACHE_DEV"
The wording from file varies by version. It is supporting evidence, not a substitute for bcache-super-show. Keep the original command output, device path and package version with the change record.
7. Recover from a mistake or failed run
If you selected the wrong device and the command has already succeeded, stop using that device immediately. Do not try to remove the superblock by guessing at offsets or by running another formatter. Restore the device from the tested backup, or use the documented rebuild procedure for the storage layer that owned it. If the command failed before writing a valid superblock, preserve the error output and have the device checked before reusing it.
Creating the cache does not by itself attach it to a backing device, mount anything or provide a usable filesystem. Those are separate, service-affecting operations. Take a fresh backup and follow the bcache and distribution documentation for registration, attachment and boot recovery before continuing.
Done means
- The installed
make-bcacheandbcache-toolsversion were checked. - The target device was identified by size, model, serial and stable path.
- Mounts, higher-level storage users and backups were checked before formatting.
- The cache was created with a reviewed bucket size and elevated privileges.
bcache-super-showconfirms a bcache cache superblock and cache device type.- No backing device, filesystem, mount or service configuration was changed by this guide.