Ubuntu Linux comes with a useful server version which is designed to be run without a graphical console regularly attached. Combined with Ubuntu's "Long Term Support" (LTS) versions it provides a reasonable base for stable server Linux installs.
For various reasons, including installation onto my KVM hosted server it is useful to set Ubuntu Linux Server up with serial console. Ubuntu Linux Server does support this, and with a little manual work it's even possible to install (mostly) via serial console. There is an Ubuntu Linux suggestion to permit a "no keyboard" install via serial console. Ideally it'd be as easy as serial console on older Sun desktops: don't plug in a keyboard and it will default to serial console. But PC hardware (and especially the variety of keyboard technology over the years) doesn't make that quite as easy.
For a remote KVM install starting with a "keyboard"/"screen" attached, the process is similar to what I did to install OpenBSD remotely in KVM, viz (all square brackets replaced by XML angle brackets in config files):
Add a graphics and video section to the libvirt KVM device configuration:
[input type='mouse' bus='ps2'/] [graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'/] [video] [model type='cirrus' vram='9216' heads='1'/] [/video]
(You could, and I did, specify an explicit port and set autoport='no', or just let it auto-assign them starting at 5900. You could presumably also specify an IP other than 127.0.0.1, if you were in an environment where you could safely expose the console to local/remote networks.)
There should also be a serial console section:
[serial type='pty'] [source path='/dev/pts/13'/] [target port='0'/] [/serial] [console type='pty' tty='/dev/pts/13'] [source path='/dev/pts/13'/] [target port='0'/] [/console]
so that when you switch to serial console it'll be possible to use it. (In this case the serial console is connected via a Psuedo-TTY, and can be accessed via the libvirt console feature.)
As appropriate add a "cdrom" device that points at the CD image file:
[disk type='file' device='cdrom'] [driver name='qemu' type='raw'/] [source file='/install/ubuntu-10.04.3-server-i386.iso'/] [target dev='hdc' bus='ide'/] [readonly/] [/disk>
and make it the default bootable device for the duration of the install:
[os] [type arch='i686' machine='pc-0.12']hvm[/type] [boot dev='cdrom'/] [boot dev='hd'/] [/os]
Set up a ssh port forward for the console port (eg, 5900):
ssh -L 5900:localhost:5900 HOSTED-SERVER
Start virtual machine
Connect VNC viewer to the remote console:
vncviewer localhost:5900
(or whatever the port was on the local end of the port forward; it may also be possible to use the "-via" feature of your VNC Viewer to automatically bring up the ssh port forward)
From the VNC view of the console choose the appropriate langauge to use with the installer, eg "English" (the default). (The function keys needed for the next step will not work until this is done!)
When the main boot choice menu comes up, press "F6" to get at the advanced features, then "ESC" to cancel the menu that appears.
Having done that, the focus will be on the Linux boot command line. Edit that command line by adding:
console=ttyS0,115200
before the "--", and optionally removing the "quiet" if you would like to see boot progress messages on the serial console.
Press "Enter" to initiate the boot process with the modified Linux command line.
The VNC view of the console will disconnect (possibly due to geometry changes?), and it's then possible to connect to the KVM redirected serial console as normal and continue the install in text mode.
Install Ubuntu Linux Server as normal.
(The required keyboard magic to switch to serial console came from the comments on the Ubuntu Linux suggestion to provide serial console install, which also offers other hints on doing it now. With care the necessary keyboard steps could be done blind -- with just a keyboard attached but no screen -- but that doesn't really help in the virtual environment situation!)
When the installation is complete, you can change the boot order to boot from the hard drive rather than the install CD (ie, move the "hd" option to before the "cdrom" option), and remove the mouse and video card information from the KVM config (they shouldn't be required again unless there is some reason to boot from the install CD).
After the install, grub should be configured for serial console but the
Linux kernel is not. For grub look in /etc/default/grub
for lines like:
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
For the linux kernel, edit /etc/default/grub
and add/set:
GRUB_CMDLINE_LINUX="console=ttyS0,115200"
then run sudo update-grub
and it should work when you
next reboot. (You can check /boot/grub/grub.cfg
to
make sure that the serial console settings made it into the grub
configuration there.) You may also want to comment out the two lines
that hide the grub menu, viz:
#GRUB_HIDDEN_TIMEOUT=0
#GRUB_HIDDEN_TIMEOUT_QUIET=true
since otherwise you may connect to the KVM serial console redirection and have no output and think it isn't working. And potentially change the main menu timeout to something a bit longer (eg, 5-10 seconds), viz:
GRUB_TIMEOUT=10
Finally you may wish to consider removing "quiet" from the GRUB_CMDLINE_LINUX_DEFAULT, as otherwise there will be very few boot progress messages; just some RC script messages. But it depends on your taste.
Be sure to run sudo update-grub
after you're finished.
It's normally worth doing apt-get update && apt-get
dist-upgrade
before rebooting to test the serial console,
as on a new Ubuntu Linux server install there's a good chance that
there will be outstanding security updates that require a reboot,
and you might as well do all of them in one go. (If anything goes
wrong the VNC console should still work.)