01 August 2025

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.

Since, spice is being effectively deprecated, and in reality it never worked as reliably as vnc anyway (despite promises to be much better), I have to replace the spice displays on existing vms. For server vms, the serial console is a much better choice than VNC — lower overhead and works with virsh console command.

You’ll need to edit the guest with virsh edit to make sure it has the needed entries, some of which may already be present:

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

<serial type='pty'>
  <target type='isa-serial' port='0'>
    <model name='isa-serial'/>
  </target>
</serial>
<console type='pty'>
  <target type='serial' port='0'/>
</console>

and need to add these lines to /etc/default/grub on RedHat, or create a new /etc/default/grub.d/00_console.cfg (0644) on Debian.

GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8"

then run the command:

# redhat
grub2-mkconfig -o /boot/grub2/grub.cfg
# debian
update-grub
#
systemctl enable serial-getty@ttyS0.service
systemctl start serial-getty@ttyS0.service

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

  --console pty,target_type=virtio

If you create your guests with VMM, it defaults to creating a spice display, which you’ll need to change to VNC. After you create the machine you can add the console with virsh edit.

This article originally created 2025-03-13, revised 2025-08-01.