When a VM's network is broken, SSH is useless. A serial console gives you a text login over the hypervisor, with no network or graphics. This guide shows how to set up a KVM serial console and use virsh console.
Before you start
- Root on the KVM host and the guest (via VNC for the first setup if needed).
- VPS customers usually use the panel's VNC console instead; see VNC console access.
Check the VM has a serial device
virsh dumpxml web01 | grep -A3 "<serial"virt-install adds one by default. If missing, add with virsh edit:
<serial type='pty'><target port='0'/></serial>
<console type='pty'><target type='serial' port='0'/></console>Power-cycle the VM afterwards.
Configure the guest kernel and GRUB
Edit /etc/default/grub in the guest:
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"Regenerate GRUB: sudo update-grub (Debian/Ubuntu) or sudo grub2-mkconfig -o /boot/grub2/grub.cfg (RHEL family). Cloud images often already include console=ttyS0.
Enable a login prompt
systemd usually starts serial-getty@ttyS0 automatically when the kernel console is set. To be sure:
sudo systemctl enable --now serial-getty@ttyS0.serviceConnect
virsh console web01Press Enter to see the login prompt. Exit with Ctrl+]. Reboot the VM while connected to watch GRUB and boot messages, very useful for boot problems.
Rescue tricks from the serial console
- At the GRUB menu press e, append
systemd.unit=rescue.targetto the linux line and press Ctrl+X to boot into rescue mode. - Fix network config or firewall rules that locked you out of SSH.
- Read boot errors that scroll past too quickly in VNC.
Troubleshooting
- Blank console: press Enter; if still blank, the kernel lacks
console=ttyS0or getty is not running. - "Active console session exists": someone else is connected; use
virsh console web01 --force. - Garbled text: speed mismatch; use 115200 everywhere.
Frequently asked questions
Does Windows support the serial console?
Windows offers the Emergency Management Services console, but most admins use VNC/RDP instead.
Is the serial console secure?
Only users with access to the hypervisor can reach it, and the guest still requires a login.
Can I log the console?
Yes, use <log file='/var/log/libvirt/qemu/web01-serial.log'/> in the serial device.
