qemu 调试linux内核

一.编译linux内核

$ cd linux

$ make ARCH=x86_64 x86_64_defconfig

$ make ARCH=x86_64 menuconfig

# 打开 `Kernel hacking ->

Compile-time checks and compiler options ->

Compile the kernel with debug info ->

Provide GDB scripts for kernel debugging`

$ make -j

二.编译 rootfs

使用 buildroot 编译 rootfs

在使用 buildroot 编译 rootfs 时,若在内网使用,记得设置代理服务器。

$ git clone git://git.buildroot.net/buildroot

$ cd buildroot

$ make menuconfig

# select `Target Options ->

Target Architecture ->

x86_64`

# select `Filesystem images ->

ext2/3/4 root file system ->

ext4`

$ make -j

三.编译 qemu

configure --enable-kvm  --target-list=x86_64-softmmu --enable-virtfs --prefix=/home/tyrion_shi/.bin

提示无法找到某个lib 但是lib的确已经安装 pk-config 也可以找到

export宏,告诉链接器链接路径

export $LD_LIBRARY_PATH 无效

export $LIBRARY_PATH 有效

运行虚拟机

qemu-system-x86_64 -s -S -no-kvm -kernel ~/work/test/linux/linux-master/arch/x86_64/boot/bzImage  -boot c -m 2048M -hda ~/work/test/buildroot-2023.05.x/output/images/rootfs.ext4  -append "root=/dev/sda rw console=ttyS0,115200 acpi=off nokaslr"  -serial stdio -display none

用9p 虚拟机和本地建立共享

 -fsdev local,security_model=passthrough,id=fsdev0,path=/home/tyrion_shi/share/qemushare -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare

完整命令

qemu-system-x86_64 -s -S -no-kvm -kernel ~/work/test/linux/linux-master/arch/x86_64/boot/bzImage  -boot c -m 2048M -hda ~/work/test/buildroot-2023.05.x/output/images/rootfs.ext4  -append "root=/dev/sda rw console=ttyS0,115200 acpi=off nokaslr"  -serial stdio -display none   -fsdev local,security_model=passthrough,id=fsdev0,path=/home/tyrion_shi/share/qemushare -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare

四.使用 gdb 调试内核启动流程

重新开窗口运行

1 $ gdb vmlinux

(gdb) target remote localhost:1234

(gdb) break start_kernel

(gdb) c

(gdb) layout src

挂载外部共享文件夹到虚拟机内部

1.mkdir /mnt/host_files

2.mount -t 9p -o trans=virtio,version=9p2000.L hostshare /mnt/host_files

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值