Sat 27-11-2010 13:15
|
by Mikko Kortelainen
|
tags: KVM Linux Ubuntu Virtualization |
5 minute read
The virt-manager VNC screen is fine for LAN connections, and good for running
graphical sessions. X is not installed on Ubuntu server by default, and VNC is
really bad over slow links even for text console. I like to configure serial
console for all my virtualized guests, because with it, I can simply ssh into
the virtual machine host, and run "virsh console <guest-name>" to get a working
console. Very nice for fixing broken network connections or file systems, or any
kind of boot problems. And I can do it using just my cell phone, ssh over 3G
connection from anywhere!
In Ubuntu, there are three things you may want to configure to use serial console:
1. GRUB boot menu
2. Kernel and init messages
3. Pseudo tty to log in and get shell
Serial device for your virtual guest
But first things first: you must add a serial device for your guest machine in
order to be able to use the serial console.
In virt-manager it is as easy as adding a new hardware device, type Serial, and
device type "Pseudo TTY (pty)" into the machine configuration. No further
configuration needed, just add the device and that's it.
In the libvirt XML configuration file the device should look something like this:
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target port='0'/>
</console>
The GRUB boot menu, Linux kernel, and system init messages
With GRUB 1, it was possible to get the GRUB menu simultaneously over serial and
graphical VNC console. Unfortunately I haven't found a way to do that with GRUB
2. Linux kernel fortunately does output messages both to the serial and VNC
console if so configured. The upstart init will output its' messages to whatever
the kernel is configured to do.
To make the GRUB menu and kernel messages show up over serial console, you need
to edit the /etc/default/grub file and run update-grub afterwards. The changed
or added lines are marked with bold below:
/etc/default/grub:
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=
GRUB_HIDDEN_TIMEOUT_QUIET=false
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="text console=tty0 console=ttyS0,115200n8"
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_LINUX_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
Run update-grub after making the changes. During the next reboot, you will be
able to choose your kernel using the GRUB menu, or run any grub commands, using
the serial console.
The GRUB menu will show up only on the serial console, while the kernel and init
messages will show up on both serial console and the graphical screen.
Detailed explanation
Here's a description of what each of the changes mean:
GRUB_HIDDEN_TIMEOUT=
This simply enables the GRUB menu, which is hidden by default in Ubuntu.
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="text console=tty0 console=ttyS0,115200n8?
These two lines control the Linux kernel behaviour. This will append the
necessary kernel command line options to all kernels, both normal and rescue
mode. With the two console= options, the messages will go to both tty0 (VNC
screen) and ttyS0 (serial console).
Also upstart init will show messages on both, and single user mode (runlevel 1)
will work on both (the rescue mode root shell).
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND=