linux kernel
kernel 编译常见错误
编译选项
证书
make[1]: [/home/hjk/Desktop/workspace/00.linux-kernel/linux-6.14.2/Makefile:1994: .] Error 2
make: [Makefile:251: __sub-make] Error 2
编译时内存不足(多半是虚拟机分配的内存空间不足)
1. 创建分区 |
分配swap内存分区的时候可能会遇到文件busy打不开
dd: failed to open ‘/swapfile’: Text file busy
可以关闭swap分区再尝试进行分区
sudo swapoff -a |
文件挂载
D 是共享文件夹名称
查看共享文件夹 |
系统启动后自动挂载共享文件夹
sudo vim /etc/fstab |
kernel debug调试
使用qemu模拟对应的硬件平台, 然后使用gdb和vscode远程调试
虚拟机ubuntu设置
- 安装gdb和对应的qemu-system-目标平台
- 编译完的内核 vmlinux 需要开启debug info 对应去menuconfig中修改即可 默认是带调试信息的
- 启动qemu
qemu-system-x86_64 -kernel build_x64/arch/x86_64/boot/bzImage -append “console=ttyS0 nokaslr” -nographic -s -S
宿主机vscode设置
remote ssh连接上设备后, 配置.vscode/launch.json
可以通过ctrl+alt+p 选择设置launch.json
{ |
选中源码后使用gdb调试即可(注意先把断点打好)
qemu-system-aarch64 -machine virt -cpu cortex-a57 -kernel ./Image -drive file=./rootfs.ext4,format=raw,if=virtio -append “root=/dev/vda console=ttyS0” -s -S -smp 1 -nographic -serial mon:stdio
使用WSL代替vmware虚拟机(推荐)
退出gdb ctrl + D
退出qemu 先按 ctrl + a, 再按 c(x)
启动qemu
qemu-system-x86_64 -kernel ./00.kernel/linux-5.10.236/arch/x86_64/boot/bzImage -hda ./rootfs.img -append “root=/dev/sda console=ttyS0” -s -S -smp 1 -nographic
qemu-system-x86_64 -kernel ./00.kernel/linux-5.10.236/arch/x86_64/boot/bzImage -hda ./rootfs.img -append "root=/dev/sda console=ttyS0" -s -S -smp 1 -nographic |