Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Access vm in libvirt/qemu/kvm on serial console from hypervisor

You can access the serial port console of a virtual machine running in qemu, if you have configured the guest kernel correctly.

Configure the guest

# add serial console
sed -i -r -e '/^GRUB_CMDLINE_LINUX=/{s/(\s*)\"$/ console=ttyS0 console=tty1\"/;}' /etc/default/grub
grub2-mkconfig > /boot/grub2/grub.cfg

I have these steps in my kickstart %post scriptlet, so all my VMs get this setting. These steps modify grub to tell the kernel to open a listening console on the first serial console (ttyS0) and also the regular virtual terminal tty1. It is important to denote both, so the spice client sees the tty1, and that virsh on the command line can get to the serial console.

Accessing the guest from the hypervisor

sudo virsh console $GUESTNAME

Once the guest OS has booted, just run this command and you're connected to the serial console. You have to log in like a true console session, and then you're in!

Comments