Linux – How to remove the cache device from bcache

bcachelinuxmemory

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.

Best Answer

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
Related Question