Skip to content

Configuring CentOS 6 and Windows VMs for virsh console on KVM

2013 January 6

Accessing the console of a KVM VM directly rather than via SSH (Linux) or RDP (Windows) can occasionally be useful.  For example, if a Linux VM suffers a disk issue and is stuck at a single-user mode prompt, SSH won’t be possible.  Modern hypervisors provide convenient access to this console using VNC or something similar.  Besides VNC, KVM provides the ability to access the serial console of a VM using the virsh console <domain id> command on the host running the VM.  Enabling this typically requires a configuration change in the VM itself.

The configuration needed in CentOS 6 is extremely simple: edit /boot/grub/grub.conf and reboot.  Specifically, at the end of the “kernel” entry for the currently running kernel, add “console=tty0 console=ttyS0,115200n8”.  Other Linux distributions will require something similar.  With this minor change, virsh console should work correctly.  This change may be lost if you update the kernel with yum, so make sure to re-add it if necessary.  The following demonstrates the use of virsh console to access a CentOS 6 VM.  The KVM host in this example happens to be Ubuntu 12.04.1.

CentOS 6 virsh console

Windows VMs are also easy to configure for serial access.  All that is necessary is to enable the Emergency Management Services (EMS) feature and reboot.  For Server 2003 and earlier, this is done with bootcfg as explained in Description of the BOOTCFG Command and Its Uses.  For a typical VM, the command will look like:

bootcfg /EMS /PORT com1 /BAUD 115200 /ID 1

One this is enabled, virsh console will provide serial access to the VM.  You can access a cmd.exe session with a few commands.

Windows Server 2003 virsh console 1

Windows Server 2003 virsh console 2

Windows Server 2003 virsh console 3

With VMs running Windows Vista and above, bcdedit should be used to enable EMS.  This process is described in Boot Parameters to Enable EMS Redirection (Windows Drivers).  While testing Server 2012, the following commands worked for me:

bcdedit /emssettings EMSPORT:1 EMSBAUDRATE:115200
bcdedit /ems {current} on

As with Server 2003, you can access a cmd.exe session.

Windows Server 2012 virsh console

After enabling access to VMs via virsh console, hopefully you will never need to use it.  But it can definitely come in handy in a few situations.

 

Leave a Reply

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS

This site uses Akismet to reduce spam. Learn how your comment data is processed.