Search code examples
amazon-web-servicesamazon-ec2rebootrecoverbcache

how to recover BCACHE from EC2 machine reboot


I installed BCACHE on a m3.large EC2 machine with instance SSD as cache disk and the elastic volume as backing disk. But once I reboot the EC2 machine BCACHE was gone and i cannot access the disk used to be backing drive again.

If I detach SSD(run BCACHE without cache) before reboot then after reboot v will still be there and i can attach SSD to it again.

The question is how do I recover BCACHE from a EC2 unclean reboot.


Solution

  • You should try to unregister your cache devices on shutdown/reboot and re-create and attach them on boot, if not, It will cause you pain every time you decide to shut down your instance. There is a script that automates the startup and shutdown in the first

    For the unclean case (forced stop or sudden instance crash) you need to

    echo 1 > /sys/block/[Backing Device (EBS)]/bcache/running

    Example: echo 1 > /sys/block/xvdf/bcache/running

    Or if you use writeback and you assume your backing device will always boot healthy you can just add that line into your boot sequence (before your volume is mounted)

    References: