Compiling and Installing Bcache
CentOS 7.6
- Obtain the bcache source code and save it to /home.
- Decompress the source package.
1 2
cd /home unzip bcache-smart-write-cache.zip
- Compile the source code to obtain the bcache driver module.
1 2
cd /home/bcache-smart-write-cache/drivers/md/bcache make -C /lib/modules/$(uname -r)/build M=$(pwd)
During compilation, select the build directory of the kernel where bcache.ko needs to be run based on your environment.
- Check the reference count of the bcache module. If no information is displayed, skip step 5.
lsmod | grep -w bcache
Ensure that the reference count is 0.
bcache 458752 0
- Check that bcache.ko is not loaded in the current environment.
modprobe -r bcache
- (Optional) Delete the installation directory. Skip this step if bcache is not installed.
rm -rf /lib/modules/$(uname -r)/kernel/drivers/md/bcache
- Create an installation directory.
mkdir -p /lib/modules/$(uname -r)/kernel/drivers/md/bcache
- Copy bcache.ko to the installation directory.
cp bcache.ko /lib/modules/$(uname -r)/kernel/drivers/md/bcache
- Compress bcache.ko.
xz -z /lib/modules/$(uname -r)/kernel/drivers/md/bcache/bcache.ko
- Update the module dependency of bcache.ko.
depmod -a
- Update initramfs.
dracut --add-drivers bcache -f /boot/initramfs-$(uname -r).img
- Check whether bcache.ko is successfully installed.
- Command 1: Query bcache.ko in the initramfs file.
lsinitrd /boot/initramfs-$(uname -r).img | grep bcache.ko.xz
The command output is as follows:
-rw-r--r-- 1 root root 997136 Nov 30 11:45 usr/lib/modules/4.14.0-115.el7a.0.1.aarch64/kernel/drivers/md/bcache/bcache.ko.xz
- Command 2: Query detailed information about the bcache module in the current system.
ls -l /lib/modules/$(uname -r)/kernel/drivers/md/bcache/bcache.ko.xz
The command output is as follows:
-rw-r--r-- 1 root root 997136 Nov 30 11:45 /lib/modules/4.14.0-115.el7a.0.1.aarch64/kernel/drivers/md/bcache/bcache.ko.xz
If the content of the file in usr/lib/modules/ in the command output of command 1 is the same as that in /lib/modules/ in the command output of command 2, the bcache.ko file in the current system is successfully updated to the initramfs file.
- Command 1: Query bcache.ko in the initramfs file.
- Load bcache.ko.
modprobe bcache
openEuler 20.03
- Obtain the bcache source code and save it to /home.
- Decompress the source package.
cd /home unzip kernel-openEuler-1.0-LTS.zip
- Replace the system header file temporarily.
mv /usr/src/kernels/$(uname -r)/include/trace/events/bcache.h /usr/src/kernels/$(uname -r)/include/trace/events/bcache.h.bak cp /home/kernel-openEuler-1.0-LTS/include/trace/events/bcache.h /usr/src/kernels/$(uname -r)/include/trace/events/bcache.h
The /home/kernel-openEuler-1.0-LTS folder is obtained by decompressing the bcache source code.
- Compile the source code to obtain the bcache driver module.
1 2
cd /home/kernel-openEuler-1.0-LTS/drivers/md/bcache make -C /lib/modules/$(uname -r)/build M=$(pwd)
During compilation, select the build directory of the kernel where bcache.ko needs to be run based on your environment.
- Replace it with the original file.
\mv /usr/src/kernels/$(uname -r)/include/trace/events/bcache.h.bak /usr/src/kernels/$(uname -r)/include/trace/events/bcache.h
- Check the reference count of the bcache module. If no information is displayed or the reference count is 0, skip step 7.
lsmod | grep -w bcache
Ensure that the reference count is 0.
bcache 458752 0
- Check that bcache.ko is not loaded in the current environment.
modprobe -r bcache
- Delete the installation directory.
rm -rf /lib/modules/$(uname -r)/kernel/drivers/md/bcache
- Create an installation directory.
mkdir -p /lib/modules/$(uname -r)/kernel/drivers/md/bcache
- Copy bcache.ko to the installation directory.
cp bcache.ko /lib/modules/$(uname -r)/kernel/drivers/md/bcache
- Compress bcache.ko.
xz -z /lib/modules/$(uname -r)/kernel/drivers/md/bcache/bcache.ko
- Update the module dependency of bcache.ko.
depmod -a
- Update initramfs.
dracut --add-drivers bcache -f /boot/initramfs-$(uname -r).img
- Check whether bcache.ko is successfully installed.
If the following two commands output the same file information, the installation is successful.
- Command 1: Query bcache.ko in the initramfs file.
lsinitrd /boot/initramfs-$(uname -r).img | grep bcache.ko.xz
The command output is as follows:
-rw-r--r-- 1 root root 997136 Nov 30 11:45 usr/lib/modules/4.14.0-115.el7a.0.1.aarch64/kernel/drivers/md/bcache/bcache.ko.xz
- Command 2: Query detailed information about the bcache module in the current system.
ls -l /lib/modules/$(uname -r)/kernel/drivers/md/bcache/bcache.ko.xz
The command output is as follows:
-rw-r--r-- 1 root root 997136 Nov 30 11:45 /lib/modules/4.14.0-115.el7a.0.1.aarch64/kernel/drivers/md/bcache/bcache.ko.xz
- Command 1: Query bcache.ko in the initramfs file.
- Load bcache.ko.
modprobe bcache