</>EmbeddedInterview

How do you use QEMU to run and debug an ARM64 Linux kernel?

MediumVirtualization (QEMU & KVM)

Short answer: Use the virt machine: qemu-system-aarch64 -M virt -cpu cortex-a53 -smp 2 -m 1G -nographic -kernel Image -initrd rootfs.cpio.gz -append "console=ttyAMA0". Add -s -S to make QEMU wait for GDB on port 1234, then connect gdb vmlinux with target remote :1234 and debug the kernel from the first instruction.

qemu-system-aarch64 \
  -M virt -cpu cortex-a53 -smp 2 -m 1024 \
  -nographic \
  -kernel arch/arm64/boot/Image \
  -initrd rootfs.cpio.gz \
  -append "console=ttyAMA0 nokaslr" \
  -s -S
Option Meaning
-M virt generic ARM virtual board (no real hardware equivalent; QEMU generates its device tree)
-cpu cortex-a53 CPU model for TCG; with KVM use -cpu host
-smp 2 / -m 1024 2 vCPUs, 1 GiB RAM
-nographic no display window; serial console on the terminal (Ctrl-A x to quit, Ctrl-A c for the monitor)
-kernel / -initrd / -append direct kernel boot, no bootloader needed
-dtb use your own device tree instead of the generated one
-accel kvm (-enable-kvm) use KVM; only works when the host is ARM64
-s -S GDB server on TCP 1234 (-s), and do not start the CPUs until GDB says so (-S)

Debug session

aarch64-linux-gnu-gdb vmlinux     # or gdb-multiarch
(gdb) target remote :1234
(gdb) hbreak start_kernel
(gdb) continue
(gdb) bt

Build the kernel with CONFIG_DEBUG_INFO and CONFIG_GDB_SCRIPTS (then lx-dmesg, lx-ps work in GDB), and boot with nokaslr so addresses match the symbols.

More debugging tools

  • -d int,guest_errors -D qemu.log – log exceptions and invalid device accesses.
  • QEMU monitor (Ctrl-A c): info registers, info mtree (memory map), info qtree (devices), xp /16x 0x40000000 (physical memory).
  • -trace "pl011*" – trace events of a device model.
  • -machine dumpdtb=virt.dtb – save the generated device tree, then dtc -I dtb -O dts virt.dtb to read it.

Why teams use this: kernel and driver development before hardware exists, reproducible CI tests (boot every commit in QEMU), and debugging early boot crashes that are hard to catch on a real board.