Skip to content

Instantly share code, notes, and snippets.

@mcastelino
Last active October 22, 2018 19:01
Show Gist options
  • Save mcastelino/aa118275991d4f561ee22dc915b9345f to your computer and use it in GitHub Desktop.
Save mcastelino/aa118275991d4f561ee22dc915b9345f to your computer and use it in GitHub Desktop.
NEMU QEMU Early Serial Port Early Kernel Debug

How to debug early boot kernel crashes

On the virt platform if the kernel crashes early (even before the virtio-serial port comes up), you need to be able to debug the early boot process. This can be done using the sysbug-debugcon device which is available right at boot.

The key items to note below are

  • Kernel commandline: console=ttyS0
  • Additional sysbus-debugcon device: -device sysbus-debugcon,iobase=0x3f8,chardev=serialcon -chardev file,path=/tmp/serial-log,id=serialcon

Note:

  • 0x3f8 maps to COM1. You can have additional serial ports if needed.
  • As modeled by sysbus-debugcon these are output only port
dos     common                  IO    
name     name     major minor address 
COM1   /dev/ttyS0  4,  64;   3F8      
COM2   /dev/ttyS1  4,  65;   2F8      
COM3   /dev/ttyS2  4,  66;   3E8      
COM4   /dev/ttyS3  4,  67;   2E8      
     QEMU=~/build-x86_64/x86_64-softmmu/qemu-system-x86_64
     KERNEL=~/linux/arch/x86_64/boot/bzImage
     BIOS=~/ovmf.fd.virt
     OSIMAGE=~/clear.img
sudo $QEMU \
     -kernel $KERNEL -append 'console=ttyS0 console=hvc0 root=/dev/vda3 rw rootfstype=ext4 data=ordered rcupdate.rcu_expedited=1 tsc=reliable no_timer_check noapictimer log_buf_len=1M debug loglevel=7' \
     -bios $BIOS \
     -nographic \
     -nodefaults \
     -L . \
     -net none \
     -machine virt,accel=kvm,kernel_irqchip \
     -smp 4,maxcpus=8\
     -m 512M,slots=3,maxmem=4G \
     -device virtio-serial-pci,id=virtio-serial0 -device virtconsole,chardev=charconsole0,id=console0 -chardev stdio,id=charconsole0 \
     -device virtio-blk-pci,drive=image -drive if=none,id=image,file=$OSIMAGE,format=raw \
     -monitor telnet:127.0.0.1:55555,server,nowait \
     -netdev user,id=mynet0,hostfwd=tcp::${VMN}0022-:22 -device virtio-net-pci,netdev=mynet0 \
     -device sysbus-debugcon,iobase=0x402,chardev=debugcon -chardev file,path=/tmp/debug-log,id=debugcon \
     -device sysbus-debugcon,iobase=0x3f8,chardev=serialcon -chardev file,path=/tmp/serial-log,id=serialcon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment