I believe, that once I made sure my cache device state is "clean":

$ sudo cat /sys/block/bcache0/bcache/state

I can just physically remove it from the machine when it is powered off or boot with liveCD and clean the superblock with:

$ sudo dd if=/dev/zero of=<backing device for cache> bs=1024 count=1024

But I cannot find anywhere a confirmation, that this procedure wouldn't mess anything up.

3 Answers 3


I used bcache only in a writethrough configuration, and IIRC even then bcache doesn't like at all if the cache device vanishes while the machine is running. Expect the bcache device to stall completely if that happens.

I haven't tried to remove the cache device while the machine is powered down, so I can't say anything about that. I do think though that bcache is still pretty touchy, so I'd recommend that you try that with a VM or a physical test machine first.

To safely remove the cache device, you can detach the cache set from the bcache device:

echo <cache-set-uuid> > /sys/block/bcache0/bcache/detach

To determine the necessary cache set UUID, look in /sys/fs/bcache/:

host ~ # ll /sys/fs/bcache/
total 0
drwxr-xr-x 7 root root    0 Feb 19 00:11 eb99feda-fac7-43dc-b89d-18765e9febb6
--w------- 1 root root 4096 Feb 19 00:11 register
--w------- 1 root root 4096 Feb  7 07:17 register_quiet

So for example in this case, run:

echo eb99feda-fac7-43dc-b89d-18765e9febb6 > /sys/block/bcache0/bcache/detach

The state file should say no cache after that:

host ~ # cat /sys/block/bcache0/bcache/state
no cache
  • 7
    I may be missing some caveat here, but AFAICT the cache UUID doesn't need to be echo'ed to /sys/block/bcache0/bcache/detach, you can just echo '1'. At least, that works for me on kernel 3.13. For attach, however, you need to supply the UUID. Commented Mar 26, 2014 at 16:40
  • 1
    Before you can wipe and re-purpose the underlying device, you need to stop the cache: echo 1 > /sys/fs/bcache/$CACHE_SET_UUID/stop, see kernel.org/doc/html/v5.0/admin-guide/bcache.html Commented Jan 19, 2022 at 11:15

Suppose you've set up successfully a bcache, you are already working on it, put there a lot of important data too big to simply backup and start over, when you realized, that you'd better replace the caching device. This is how you can do it. This solution is based on a VM trials.

Lets say we are talking about the device /dev/bcache0, the new cache device is /dev/sdf1 and the backing device is /dev/md1. All commands done by root.

  1. Make sure that nothing is using that bcache0 device.
  2. Do in any order
    1. Remove the cache device just as Martin von Wittich wrote, by echoing setUUID into /sys/block/bcache0/bcache/detach. If you want to repartition the caching device, you need to reboot, because bcache still locks the partitions unless you unregister it.
    2. format- new cache device with make-bcache -C /dev/sdf1 and take a note of the setUUID of that device.
  3. Register our backing device with the new cache set:

    echo [setUUID of new cache device] >/sys/block/bcache0/bcache/attach

No need to reboot.



echo $(ls -d /sys/fs/bcache/*-*-* | cut -f5 -d/) > /sys/block/bcache0/bcache/detach

Then wait until cached clears:

while true; do if [[ $(cat /sys/block/bcache0/bcache/state) != "dirty" ]]; 
then echo "DONE"; break; 
else cat /sys/block/bcache0/bcache/dirty_data; sleep 30; fi; done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .