Connect to KVM: virsh Serial Console

You can access a KVM instance directly using a serial console interface.

The following information describes how to establish a serial console connection to a KVM instance by using the virsh console command.

Note:

A serial console connection to a KVM instance might be useful when a the instance isn't configured with a GUI display, or if the instance lacks a network configuration, preventing SSH access.
What Do you Need?
  • Administrator privileges
  • Name of the KVM instance.
  • The KVM instance is configured for serial console use. For example:
    • KVM serial console device defined – Ensure that a serial console device is defined on KVM. For example:
      sudo virsh ttyconsole kvm_name
      If output is shown, a serial console device is defined. Otherwise, define a serial console in the KVM XML configuration. One method you can use is virsh edit. For example, run:
      sudo virsh edit
      Within the <devices> tag, add the following text to the XML. For example:
      <devices>
        <console type='pty'/>
      </devices>
      See Domain XML format for more information.
    • KVM kernel console option enabled – Ensure that console=ttyS0 kernel option is enabled on KVM. If this option isn't configured, the virsh console connection to the serial console will be unresponsive.

      To verify the console=ttyS0 kernel option is configured on the KVM, use the cat /proc/cmdline command. The output configuration must include console=[console-name]. If the output doesn't include a console configuration, you must enable the console=ttyS0 kernel option.

      To enable the console=ttyS0 kernel option, (1) type:
      sudo grubby --update-kernel=ALL --args="console=ttyS0"
      (2) Ensure that the changes were applied, type:
      sudo grub2-editenv - unset kernelopts
      (3) Reboot the KVM instance.

Steps

Follow these steps to directly connect to the KVM serial console.

  1. On the host system, use the virsh console command to open up a KVM session in a serial console. For example:
    sudo virsh console testguest
    Where testguest is the name of the KVM guest.

    You can interact with the virsh serial console in the same way as you would with the CLI.

    Note:

    If the connection failed and the guest serial console is unresponsive, you can exit the connection by pressing: Ctrl key and the ] right square bracket key.