KVM / QEMU Serial and Monitor options

When testing new kernels and distributions it is handy to start them in a virtual machine to check for generic problems. I use kvm/qemu for this.

When starting kvm it I want the monitor to be in the terminal where it starts, and the kernel's console output available via the virtual machine's serial port.

First, in a separate terminal window start a TCP socket listener on port 9999 that also writes output to a log file (for later review):

nc -l -p 9999 | tee boot.log

Switch to the terminal window where kvm will be started and add these options to the command line:

-monitor stdio -serial tcp:

If booting from a live-CD ISO image-file, set up the loop device:

sudo losetup /dev/loop0 /home/all/Downloads/jaunty-desktop-amd64.0203.1.iso

Add the options to mount the device as a cdrom and boot from it:

-boot d -cdrom /dev/loop0

The complete command-line might look similar to this:

kvm -name Ubuntu-Jaunty-Desktop -serial tcp: -monitor stdio \
 -m 768  -hda ubuntu-jaunty-desktop.qcow2 -boot d -cdrom /dev/loop0 \
 -usb -k en-gb  \
 -net nic,model=rtl8139,macaddr=56:44:45:30:31:32,vlan=0 -net vde,sock=/var/run/kvm0.ctl,vlan=0

(assumes there is a network vdeswitch interface (kvm0) configured that the VM guest will connect to)

When the system boots the kernel command line needs the following additional options:

debug console=tty0 console=ttyS0,115200n8

When starting from a live-CD these can be added via the 'F6' key "Other Options". If starting an installed system with GRUB, enter the GRUB menu and use the manual edit options (press E) to modify the kernel line, then press B to boot with the modifications.

The kernel output will appear in the terminal where nc is running and be saved to the log-file.