3

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!

3

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!

  • I tried to bcache a ramdisk to an lvm. The lvm consisted of md0 and an ssd. The md0 is what keeps showing as having bcache0 assigned when I run lsblk. I believe I've tried wipefs -a and stopped the mdadm as well as the ramdrive. Where is it reading the superblock from if I removed these devices on reboot? Shouldn't uninstalling prevent lsblk from showing bcache0? – thistleknot Aug 24 '15 at 22:15
  • Older versions of wipefs do not recognize the bcache signature, so try zeroing the first megabyte of md0 instead (again, be sure that there is nothing in md0 that you want to preserve). mdadm and bcache use udev rules to start automatically, so stopping them will not prevent them from coming up automatically again. On Ubuntu 14.04, uninstalling bcache-tools will remove the udev rules, but other distributions may behave differently. In any case, the kernel will happily manage bcache devices without bcache-tools, since that package contains only the userspace tools. – Vincent Yu Aug 25 '15 at 2:52
  • thank you, worked. Had to go through a new install anyways, but noticed after installing bcache again on the new install, /dev/bcache0 showed up. Ran the commands on both the backing and caching (probably just needed caching) and issue went away. – thistleknot Aug 30 '15 at 17:30
  • @VincentYu This works after reboot. But how do you get rid of /sys/block/bcache0 and /dev/bcache0 without reboot? Also you can't modprobe -r bcache until reboot. – Peter Nov 23 '16 at 22:46
  • 2
    WARNING: On linux-4.17.3 echo 1 > /sys/block/bcache0/bcache/stop resulted in the backing device being removed, but leaving a dangling reference. After subsequently removing the cache devices my /dev/bcache0 and /sys/block/bcache0/ directory remain. I think you are supposed to first detach it now via echo 1 > /sys/block/bcache0/bcache/detach. Either way, this appears to be a bug in this kernel as /sys/block/bcache0 remains, but it has no bcache subdirectory and no obvious way to remove it. – Daniel Santos Jun 28 '18 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.