搭建单步调试bcache的环境,/dev/sdb作为backing dev, /dev/sdc作为cache dev。
一、宿主机环境
1)安装ubuntu 20.04 :
参考ubuntu20.04 搭建kernel调试环境第一篇--安装系统_ubuntu kernel-CSDN博客安装,其中的第六节(安装qemu)、第七节(安装apache服务)安装完成即可。
2)配置网络
host(ubuntu系统)和guest(qemu运行的系统,待调试)之间需共享文件,所以需要配置网络。
参考ubuntu20.04 搭建kernel调试环境第六篇(上)--网络配置_ubuntu20 menuconfig-CSDN博客,按其中的第三节(ubuntu宿主机配置步骤)、第4节(buildroot配置)、第五节(启动虚拟机)配置,最终能ping通外网就行。
二、静态编译bcache-tools工具
guest运行的kernel是我们自己编译的,busybox只支持一些简单的命令,动态库也很少,所以无法使用apt-get install bcache-tools方式安装bcache的用户态工具。需要自己下载源码,然后用静态方式编译出可执行文件。
1)git下载bcache-tools源码:
git clone https://github.com/g2p/bcache-tools.git
2) Makefile改成静态编译
root@linux:/home/gsf/code/bcache-tool-git/bcache-tools# git diff Makefile |
3)编译bcache-tools
root@linux:/home/gsf/code/bcache-tool-git/bcache-tools# make root@linux:/home/gsf/code/bcache-tool-git/bcache-tools# make install |
可能遇到的错误1:
Perhaps you should add the directory containing `uuid.pc' to the PKG_CONFIG_PATH environment variable No package 'uuid' found Package blkid was not found in the pkg-config search path. Perhaps you should add the directory containing `blkid.pc' to the PKG_CONFIG_PATH environment variable No package 'blkid' found make-bcache.c:11:10: fatal error: blkid.h: No such file or directory 11 | #include <blkid.h> | ^~~~~~~~~ |
解决:apt-get install libblkid-dev
可能遇到的错误2:
root@linux:/home/gsf/code/bcache-tools/bcache-tools-master# make cc -O2 -Wall -g `pkg-config --cflags uuid blkid` make-bca |