Turning Off kASLR to Debug Linux Kernel Using Qemu and GDB

debugginggdblinuxqemuUbuntu

I'm trying to debug linux kernel using qemu and gdb. The problem is that gdb won't stop at breakpoint. I've searched about it and found that turning kASLR off may help, because kASLR confuses gdb.

— Install that kernel on the guest.

+- Install that kernel on the guest, turn off KASLR by adding "nokaslr" to
the kernel command line .

now I don't know what it means to add nokaslr to command line and the way to do that. Any idea?

Best Answer

Kernel boot parameters can be set temporarily per boot or always via some configuration file; how this is done depends on the bootloader which for current versions of Ubuntu is grub2;

$ grep GRUB_CMDLINE_LINUX_DEFAULT /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
$ sudo perl -i -pe 'm/quiet/ and s//quiet nokaslr/' /etc/default/grub
$ grep quiet /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet nokaslr"
$ sudo update-grub

and then reboot; confirm at the grub menu that the parameters appear as expected.

Related Question