How to enable Xen console for your guests


Updated: March 12, 2012

Normally, when you run your virtual machines as domU guests in Xen, you will view their console using virt-manager or virt-viewer. For all practical purposes, the console buffer will be an animated image that you cannot interact with directly, at least until you boot into a graphical interface, if ever.

So what do you do if you wish to have the console output available at all times? Can you somehow redirect the console output to your host and turn it into usable, parsable text? The answer is yes. This can be done, but it is not that trivial. Let me show you how this can be achieved for both fully virtualized and paravirtualized guests.

Teaser

Paravirtualized guests

By default, the console should work without any special configurations or tweaks on your end. Unfortunately, life is rarely that fair, so you might to tweak and hack a little. There are several possible workarounds available.

Edit configuration file

Add the following variations to the virtual machine configuration file:

extra="console=hvc0 xencons=tty"

You may also specify xvc0 instead of hvc0 and use either of the two extra options one key value pair at a time. You might need to make several changes and test before you find what works best, if at all.

Edit inittab on your guest

You will need to add this new console to your guest. This is done by editing /etc/inittab, something like this:

x0:12345:respawn:/sbin/agetty -L 9600 xvc0 xterm

Please adjust the console name based on what you have specified in the virtual machine configuration. You may also have to change /etc/securetty to include this new console. Just open the file and add x0. Please make the necessary backups before making changes. Optionally, you may also need to pass the extra parameters to the kernel command line or edit the GRUB menu. We will see another example further below. This should work, but then, it may not. You may see the following sequence of error in your /var/log/messages:

init: Id "x0" respawning too fast: disabled for 5 minutes
init: Id "x0" respawning too fast: disabled for 5 minutes
init: Id "x0" respawning too fast: disabled for 5 minutes
init: Id "x0" respawning too fast: disabled for 5 minutes

If this happens, your guest operating system udev might not be creating the device, so you will have to create it manually under /dev. This is not an ideal workaround, but it could help you gain the console if all the rest of the tweaks do not work for you.

Finally, you can try:

virsh console <domain id>

You can obtain the domain id by running xm list.

Fully virtualized guests

According to man pages, xm console is not available for fully virtualized guests, but you can resolve the problem using a workaround. There are two things that need to be done. On your host, dom0, in the relevant configuration file for the guest, add the following directive:

serial="pty"

In the guest, edit the /boot/grub/menu.lst or /boot/grub/grub.conf with the following lines, add them somewhere above the first kernel entry, probably just below the default and timeout directives.

serial --unit=0 --speed=9600
terminal --timeout=5 serial console

Then, in the relevant GRUB entry add to the kernel line:

console=ttyS0

Reboot the guest and you should have the console. Now to check, you must attach the console to the guest from your dom0. This is done as follows:

#xm console <domain name>

The line will drop and supposedly the terminal will appear hung. Now, if you reboot the guest, you will see the shutdown/startup messages coming up. To exit, press Ctrl + ]. Here's a handful of examples showing boot and shutdown as well as a kernel crash triggered using the Magic Keys:

#xm console test1
INIT: Switching to runlevel: 6
INIT: Sending processes the TERM signal
INIT: Sending processes the KILL signal
Boot logging started on /dev/ttyS0(/dev/console) at Thu Dec 1 2011
Master Resource Control: previous runlevel: 3, switching to runlevel: 6
Shutting down service at daemon                                done
Shutting down auditd                                           done
Shutting down automount (force)                                done

Some images:

Booting

Crash kernel

Do note that the console is redirected now and will not show in the guest. You will need to add console=tty1 to the GRUB menu to see the console messages in the guest, too.

More reading

You might also want to check these:

Xen troubleshooting

More Xen troubleshooting

Installing SLES11 under Xen

Xen guest console hangs at boot

Conclusion

That is all. A fairly not-trivial topic, but perhaps useful. At the very least, you have learned a tad more on how to work with the Xen command line, how to invoke various commands and check different parameters, how to edit system configuration files, including the boot menu. Last but not the least, several solutions and workaround are presented, for both paravirtualized and fully virtualized guests. Much ado about Xen console.

All right. Enough for today. Stay sweet.

Cheers.

RSS Feed icon

del.icio.us del.icio.us stumbleupon stumble digg digg reddit reddit slashdot slashdot



Advertise!

Would you like to advertise your product/site on Dedoimedo?

Read more

Donate to Dedoimedo!

Do you want to
help me take early retirement? How about donating
some dinero to
Dedoimedo?

Read more

Donate