我要评分
获取效率
正确性
完整性
易理解

Creating a Bcache Device

Bcache drives are classified into data drives and cache drives. Generally, HDDs are used as data drives, and SSDs are used as cache drives.

Perform the following operations on the three Ceph nodes. In the script, the 12 drives (/dev/sda to /dev/sdl) are data drives of the bcache device, and the 400 GB partitions in the NVMe drives are used as cache drives. In this example, /dev/nvme0n1p$n and /dev/nvme1n1p$n are used. The value of n ranges from 7 to 12, which corresponds to the cache drive in partitions created in Creating a Drive Partition.

In actual situations, the OS drive may be located in an HDD. For example, if the system drive is installed in /dev/sda, the following script cannot be executed directly. Otherwise, an error is reported when the installation progress reaches make-bcache --wipe-bcache -B /dev/sda. Instead, you need to modify the script to ensure that only data drives are operated and other drives such as the OS drive and SSD drive for DB and WAL partitions are not operated.

Run the following command to check drive partitions:

1
lsblk

As shown in Figure 1, the sda drives are system drives.

Figure 1 lsblk

Procedure

  1. Create a shell script for creating a bcache device.
    1. Create create_bcache.sh.
      vi create_bcache.sh
    2. Press i to enter the insert mode and add the following content:
      #!/bin/bash 
      n=7 
      for disk in {a..f} 
      do 
              sudo make-bcache -B /dev/sd${disk} -C /dev/nvme0n1p${n} 
              ((n = $(( $n + 1 )))) 
      done 
      n=7 
      for disk in {g..l} 
      do 
              sudo make-bcache -B /dev/sd${disk} -C /dev/nvme1n1p$n 
              ((n = $(($n + 1)))) 
      done

      The parameters in make-bcache -B /dev/sd${disk} -C /dev/nvme0n1p${n} are defined as follows:

      • -B specifies a backend drive (data drive).
      • -C specifies a cache device for accelerating the data drive.

      For example, the backend drive is sdb and the cache device is nvme0n1p7.

      make-bcache -B /dev/sdb -C /dev/nvme0n1p7

    3. Press Esc to exit the insert mode. Type :wq! and press Enter to save and exit the file.
  2. Run the script.
    1
    2
    chmod 700 create_bcache.sh
    bash create_bcache.sh
    
  3. Check whether the bcache device is successfully created.
    lsblk

    If the bcache device can be found under the corresponding data drive and cache drive, the creation is successful.