Debugging Linux Kernel via Qemu

  • Install Ubuntu image via linux virt-manager GUI
  • Edit image using virsh edit <image-name>
  • Replace
<domain type='kvm'>

with

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <qemu:commandline>
    <qemu:arg value='-s'/>
  </qemu:commandline>
  • In virt-manager GUI add filesystem device with path to downloaded kernel source code (which is built)

In my case it’s:

<filesystem type="mount" accessmode="passthrough">
  <driver type="path"/>
  <source dir="/mnt/hdd/linux"/>
  <target dir="/mnt"/>
  <alias name="fs0"/>
  <address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
</filesystem>

In VM mount the FS

mount /mnt /mnt -t 9p -o trans=virtio
  • Install kernel
cd /mnt/linux
make install
  • Disable kaslr (address randomization) to make gdb work
vi /etc/default/grub
# find GRUB_CMDLINE_LINUX_DEFAULT and append value 'nokaslr'
# save and run
update-grub

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *