How to access the text console of a virtual KVM guest from within virsh

(done on clean installation of Ubuntu 11.10/KVM)

After getting a KVM host up and running on Ubuntu, often the graphical VM management application, virt-manager, is installed.  This useful utility makes it a snap to create new virtual machines and gives ready access to the virtual X desktops via graphic consoles.

However, when it’s time to make a serious use of KVM virtualization in the real world, a workhorse KVM host is more likely to have a number of Linux guest servers running with text consoles instead of X graphic consoles.  This helps to cut down on the total overhead on the host and allows more guest virtual machines to be jammed into a KVM host.

On a CLI-only KVM host, the text-based utility virsh is how one can manipulate the guests on a host.

It only makes sense that virsh would also allow access to the text console of a virtual machine, right…..right?  Let’s try switching to the console of a guest VM:

virsh # list
Id Name                 State
2 ubu1                 running
virsh # console ubu1
Connected to domain ubu1
Escape character is ^]

Argh, no further output!  No welcome message or command prompt is shown for the ubu1 VM.

It’s annoying at first but the lack of access to the text guest consoles can be resolved by taking these additional steps in the guest VMs:

The guest VM needs its serial console to be populated with a login prompt, which will present itself upon a successful serial connection from virsh.

In the guest Ubuntu VM:

Save some time/work by copying one of the tty configuration files:

sudo cp /etc/init/tty1.conf /etc/init/ttyS0.conf

edit ttyS0.conf and change the line:

exec /sbin/getty -8 115200 ttyS0 xterm

After restarting the guest VM, it’s now possible to use virtsh to get a console to the guest.

As long as we’re getting dirty here, let’s go the whole hog and get guest console to show practically everything!  How about seeing all the kernel messages during a guest boot?

Tell grub2 to output the kernel messages to the serial console.

sudo vi /etc/default/grub


sudo update-grub2

After restarting the guest, all the kernel messages will zip by until the command prompt is shown.

This entry was posted in Linux. Bookmark the permalink.