下载buildroot
buildroot
可以根据自己需求构建自己的内核,目前准备的内核是为了调试zfs
.因此需要一个微内核,然后采用qemu-kv gdb
方式进行调试.后续也想着怎么把lustre
环境搞到里面了。
代码语言:javascript
复制[root@ubuntu /mnt/buildroot-2022.02.4]$ sudo apt install dwarves libelf-dev[root@ubuntu ~]$ wget https://buildroot.org/downloads/buildroot-2022.02.4.tar.gz[root@ubuntu ~]$ tar zxvf buildroot-2022.02.4.tar.gz && cd buildroot-2022.02.4
配置buildroot
选项
代码语言:javascript
复制// buildroot 预设置[root@ubuntu ~]$ make qemu_x86_defconfig
// 菜单配置[root@ubuntu ~]$ make menuconfig
代码语言:javascript
复制// 配置菜单说明
Target options ---> 目标选项
Build options ---> 生成选项
Toolchain ---> 工具链
System configuration ---> 系统配置
Kernel ---> 内核
Target packages ---> 目标包
Filesystem images ---> 文件系统映像
Bootloaders ---> 引导加载程序
Host utilities ---> 主机实用程序
Legacy config options ---> 旧版配置选项
代码语言:javascript
复制// 菜单选项的配置
System configuration --->
/dev management (Dynamic using devtmpfs eudev)// 配置如下的选项
Build options --->
[*] build packages with debugging symbols
gcc debug level (debug level 3) Toolchain --->
C library (glibc)
Custom kernel headers series (5.15.x) Kernel --->
Kernel version (Custom version)
代码语言:javascript
复制[root@ubuntu /mnt/buildroot-2022.02.4/fs/ext2]$ vi Config.in
// 这里必须修改config BR2_TARGET_ROOTFS_EXT2_SIZE
string "exact size"
default BR2_TARGET_ROOTFS_EXT2_BLOCKS if BR2_TARGET_ROOTFS_EXT2_BLOCKS_WRAP # legacy 2017.08
// 这里设置为4G
default "4g"
help
The size of the filesystem image. If it does not have a
suffix, it is interpreted as power-of-two kilobytes. If it is
suffixed by 'k', 'm', 'g', 't' (either upper-case or
lower-case), then it is interpreted in power-of-two kilobytes,
megabytes, gigabytes, terabytes, etc.// 方式二,忘记修改了可以修改[root@ubuntu /mnt/buildroot-2022.02.4/fs/ext2]$ vi ext2.mk
#ROOTFS_EXT2_SIZE = $(call qstrip,$(BR2_TARGET_ROOTFS_EXT2_SIZE))// 这里的单位是K,评估发行版的os大小ROOTFS_EXT2_SIZE = 4240000
代码语言:javascript
复制// 脚本会自动下载包记性gcc编译[root@ubuntu ~/buildroot-2022.02.4]$ make -j12 linux-menuconfig// 运行很长时间会弹出linux内核配置,然后执行make,会编译很长时间[root@ubuntu ~/buildroot-2022.02.4]$ make -j 4 // 编译完成后会有如下输出// 编译完成保留buuld/linux-4.19和images[root@ubuntu ~/buildroot-2022.02.4/output]$ tree ./ -L 2./├── build
│ └── linux-4.19└── images
├── bzImage
├── rootfs.ext2
└── start-qemu.sh3 directories, 3 files
开始调试阶段
代码语言:javascript
复制qemu-system-x86_64 -kernel ~/buildroot-2022.02.4/output/images/bzImage -hda ~/buildroot-2022.02.4/output/images/rootfs.ext2 -append "root=/dev/sda console=ttyS0" -s -S -smp 1 -nographic
代码语言:javascript
复制[root@ubuntu ~/buildroot-2022.02.4/output/build/linux-4.19]$ gdb ./vmlinux
GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90(gdb) set architecture i386:x86-64
The target architecture is set to "i386:x86-64".(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x000000000000fff0 in ?? ()(gdb) br do_mount
Breakpoint 1 at 0xc119a850: file fs/namespace.c, line 2710.(gdb) c
Continuing.
Breakpoint 1, do_mount (dev_name=0xc7802410 "devtmpfs", dir_name=0xc7802420 "devtmpfs", type_page=0xc177fd81 "/", flags=1936093293, data_page=0x0) at fs/namespace.c:27102710 {