How to remove bcache0 volume

bcache

I've tried echoing to detach and stop. The device will remove itself, but will show up again on reboot. One time on reboot, it restored the mdadm raid I had as a backing device!

The other time I disabled the ramdrive that it was paired with, did a detach. And /dev/bcache0 came back up again after reboot.

There is no unregister under

/sys/fs/block/bcache

I've also looked in /sys/fs/bcache…
/sys/block/md0/md0p1/bcache

for this non existent unregister.

only register and register-quiet

I even uninstalled bcache-tools, and /dev/bcache0 still shows up after reboot and is caching /dev/md0!

Best Answer

If you want to permanently destroy the bcache volume, you need to wipe the bcache superblock from the underlying device. This operation is not exposed through the sysfs interface. So:

  1. Stop the bcache device as usual with echo 1 > /sys/block/<device>/bcache/stop. On newer kernels this may fail with "Permission denied". In such a case, you would need to stop the device by its UUID as explained here:

    ls -la /sys/block/<device>/bcache/set 
    # lrwxrwxrwx 1 root root 0 Jun 19 18:42 /sys/block/<device>/bcache/set -> ../../../../../../../../fs/bcache/<UUID>
    # Note: UUID is something like "89f4c92a-7fae-4d04-ab3c-7c1dd41fa1a5"
    
    echo 1 > /sys/fs/bcache/<UUID>/stop
    
  2. Wipe the superblock with head -c 1M /dev/zero > /dev/<device>. (If you have a sufficiently new version of util-linux, you can use wipefs instead, which is more precise in wiping the bcache signature: wipefs -a /dev/<device>.) Obviously, you need to be careful to select the right device because this is a destructive operation that will wipe the header of the device. Take note that you will no longer have access to any data in the bcache volume!

Related Question