Rate This Document
Findability
Accuracy
Completeness
Readability

Basic Bcache Operations

  • Create bcache backend and cache drives.
    1
    make-bcache  -B /dev/sdx1 -C /dev/sdx2
    

    -B: specifies a backend drive (data drive).

    -C: specifies a cache device (for accelerating the data drive).

    Example: Create backend drive sdb and cache device sdc.

    1
    make-bcache  -B /dev/sdb -C /dev/sdc
    

  • Delete a cache drive.
    1. View the cset-uuid of a cache drive.
      1
      bcache-super-show /dev/sd*
      

      Example: View the cache device sdc.

      1
      bcache-super-show /dev/sdc
      

    2. Clear the cache.
      1
      echo $cset-uuid  > /sys/block/bcache<n>/bcache/detach
      

      Example: Delete the cache drive whose cset-uuid is 5f50eddf-69d8-45e3-9b67-7386ffdaceb7.

      1
      echo 5f50eddf-69d8-45e3-9b67-7386ffdaceb7 > /sys/block/bcache0/bcache/detach
      

      Then sdc is detached from bcache0.

      To re-attach the cache, run the following command:

      1
      echo cset-uuid  > /sys/block/bcache<n>/bcache/attach
      
  • Deregister a cache drive.
    1
    echo 1  > /sys/fs/bcache/<cset-uuid>/unregister
    

    Example: Deregister the cache drive whose cset-uuid is 5f50eddf-69d8-45e3-9b67-7386ffdaceb7.

    1
    echo 1  > /sys/fs/bcache/5f50eddf-69d8-45e3-9b67-7386ffdaceb7/unregister
    
  • Disable a cache drive.
    1
    echo 1  > /sys/fs/bcache/<cset-uuid>/stop
    

    Example: Disable the cache drive whose cset-uuid is 5f50eddf-69d8-45e3-9b67-7386ffdaceb7.

    1
    echo 1  > /sys/fs/bcache/5f50eddf-69d8-45e3-9b67-7386ffdaceb7/stop
    
  • Disable a backend device.
    1
    echo 1 > /sys/block/bcache<n>/bcache/stop
    

    Example: Disable the backend device whose n is 0.

    1
    echo 1 > /sys/block/bcache0/bcache/stop
    

    Then both sdb and sdc are detached from bcache0.

  • Uninstall the bcache module.

    After the uninstallation, the bcache module cannot be used. Exercise caution when performing this operation.

    1
    rmmod bcache