13 March 2023

A Working Serial Console in KVM Guests

Topics: Linux
Tags: kvm
You can't login to your kvm guest via ssh, and you want to connect with virsh console. Then nothing happens.

By default guests don’t have a working console.

You’ll need to edit the guest with virsh edit to make sure it has the needed entries:

<console type='pty'>
  <target type='virtio' port='0'/>
</console>

<controller type='virtio-serial' index='0'>
  <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
</controller>

and need to add these lines to /etc/default/grub.

  GRUB\_CMDLINE\_LINUX\_DEFAULT="console=ttyS0,115200n8 console=tty1"
  GRUB\_TERMINAL="serial console"
  GRUB\_SERIAL\_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"

then run the command:

(redhat) grub2-mkconfig -o /boot/grub2/grub.cfg
(debian) update-grub

If you create your guests with virt-install, then adding the flag will create the console entry:

  --console pty,target_type=virtio

This works for me on redhat derivitives, but not on debian, so I have more to figure out.