Serial Console in KVM

A serial console provides a text-based interface for accessing a system, especially when graphical interfaces are unavailable or network connections are down. It allows you to interact with the system using a terminal program, even during boot sequences or critical failures. Here are some scenarios where serial consoles prove beneficial.

Remote system administration:

  • Linux is often deployed at unstaffed sites or for critical network infrastructure (e.g., DNS, DHCP).
  • System administrators can remotely manage these computers using SSH, but sometimes console access is necessary for diagnosing and correcting software issues.
  • Serial consoles allow remote access via a modem, enabling administrators to dial in and troubleshoot.
  • Think of it as a lifeline to your system when everything else fails.

High-density racks of computers:

  • Clusters of personal computers, assembled into 19-inch racks, can outperform mainframes for specific applications.
  • Placing a keyboard and monitor on each computer is impractical due to space constraints.
  • Instead, serial consoles allow monitoring from a central location, even if the computers are spread out.
  • A standard RS-232 cable can extend up to 15 meters, making longer distances feasible.

Recording console messages:

  • Kernel programmers often encounter error messages that flash briefly before a system reboots.
  • By connecting a serial console, you can capture these messages for later analysis.
  • Another Linux machine can serve as the serial terminal, ensuring critical information isn’t lost.

How to enable serial console access for KVM guests

When working with KVM virtual machines, you can enable serial console access to enhance management and troubleshooting.

Here’s how:

Inside the KVM Guest:

Log in to your KVM guest via SSH, virt-manager, or Cockpit.

Run the following commands to enable and start a serial console:

sudo systemctl enable serial-getty@ttyS0.service
sudo systemctl start serial-getty@ttyS0.service

These commands should be executed within the guest VM, not on the KVM host.

Verify the serial console configuration:

To confirm that the serial console is enabled, examine the VM’s configuration XML file using:

virsh edit rocky9

If serial console is enabled, you’ll see lines similar to:

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

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

Access the serial console from the host:

  • Start the virsh console of the guest system using:
    virsh console rocky9
  • You’ll be greeted with a message: “Connected to domain rocky9. Escape character is ^].
  • Press ENTER, then enter your username and password to access the guest machine’s console.

Remember, serial consoles provide a lifeline for system administration, especially in remote or critical environments. They’re like the emergency exit when everything else fails!

If you want to discuss the topic with other technology-minded people, join my Discord: https://discord.gg/YbSYGsQYES

Now we have an IRC channel as well: irc.libera.chat / #tomsitcafe

Leave a comment