6

I have an LVM and I wanted to use bcache to cache one of its LVs. (Yes, I know I could use lvmcache, but I was having issues booting and I gave up using it.)

First, I used blocks to convert the LV to a bcache backing device (this seemed to actually work!):

blocks to-bcache /dev/my_vg/my_lv

I created a caching device on my SSD:

make-bcache --block 4k --bucket 2M -C /dev/sdc4

I then attempted to attach the cache to the backing device:

bcache-super-show /dev/sdc4 | grep cset.uuid
echo 'above_uuid' > /sys/block/bcache0/bcache/attach

I then rebooted my machine (after adding /dev/bcache0 to /etc/fstab) and realized that the cache wasn't running.

# cat /sys/block/bcache0/bcache/state
no cache

# bcache-super-show /dev/my_vg/my_lv | grep cache_state
dev.data.cache_state    0 [detached]

Am I missing something? Is there another command I need to use to enable caching?

Why does bcache not like my cache device and not letting me attach it to my backing device? Did I use the wrong values for --block and --bucket?

4
  • 1
    Did you register the hacking and caching devices? Registration and attachment are separate steps. evilpiepirate.org/git/linux-bcache.git/tree/Documentation/… Apr 17, 2017 at 23:25
  • If I do ls /sys/fs/bcache/, I see the cset.uuid for my cache drive (as well as register and register_quiet) and I can mount /dev/bcache0, so it looks like everything was registered.
    – gen_Eric
    Apr 18, 2017 at 16:44
  • 1
    Do you have a script to re-register the devices? You should only need to attach them once, but they need to be registered every time you boot. Arch Linux has a config file for this: wiki.archlinux.org/index.php/Bcache#Configuring Apr 18, 2017 at 21:06
  • If I try to (re-)register the devices, I see -bash: echo: write error: Invalid argument, which I think means they are already registered.
    – gen_Eric
    Apr 25, 2017 at 0:47

3 Answers 3

4

I managed to fix this by re-creating the superblock on /dev/sdc4. Looks like the --block 4k --bucket 2M was incorrect and that's why the cache device wasn't attaching.

I cleared the superblock, then ran:

make-bcache -C /dev/sdc4

Now when I did:

echo 'uuid' > /sys/block/bcache0/bcache/attach

it worked!

4

I had the same problem:

make-bcache --block 4k --bucket 2M -C /dev/nvme0n1p1

caused the write error: Invalid argument.

Specifically, it was the --block 4k that caused the problem.

make-bcache --bucket 2M -C /dev/nvme0n1p1 

Worked perfectly.

1
  • 2
    Just had the same issue. Surprised the docs still haven't been updated
    – regomodo
    Jun 7, 2019 at 21:02
0

First, try some clean-up:

echo $cset_uuid | sudo tee /sys/fs/bcache/pendings_cleanup
echo $backing_uuid | sudo tee /sys/fs/bcache/pendings_cleanup

Use bcache-super-show to get the uuids.

Then try again to register:

echo $cset_uuid | sudo tee /sys/fs/bcache/register
echo $backing_uuid | sudo tee /sys/fs/bcache/register

The cache uuid should exist in /dev/fs/bcache if the cache device is successfully registered.

If your backing device has a cache_state of invalid, your backing data is in the mercy of fsck.

If bcache-super-show says that that the backing dev.data.cache_state state is clean and the cset.uuid consists only of zeros, the bcache device is in the invalid state and must be recreated. [source]

However, if clean, you could try force-starting the backing device without cache device:

echo 1 | sudo tee /sys/class/block/$dev/bcache/running

You must log in to answer this question.

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