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:
1 2 3 4 5 6 |
<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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# If you change this file, run 'update-grub' afterwards to update # /boot/grub/grub.cfg. GRUB_DEFAULT=0 <strong>GRUB_HIDDEN_TIMEOUT=</strong> GRUB_HIDDEN_TIMEOUT_QUIET=false GRUB_TIMEOUT=10 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` <strong>GRUB_CMDLINE_LINUX_DEFAULT=""</strong> <strong>GRUB_CMDLINE_LINUX="text console=tty0 console=ttyS0,115200n8"</strong> # Uncomment to disable graphical terminal (grub-pc only) #GRUB_TERMINAL=console <strong>GRUB_TERMINAL=serial</strong> <strong>GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"</strong> # 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:
1 |
GRUB_HIDDEN_TIMEOUT= |
This simply enables the GRUB menu, which is hidden by default in Ubuntu.
1 2 |
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=
There was some bug in grub https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/490451
Now it’s fixed and
GRUB_TERMINAL=”serial console”
works at least in debian jessie.
Please note that “serial console” works better(it’s possible to use arrows in grub menu) then “console serial”
I am trying to access the console of a virtual machine on the host on which it is running, I made all the above changes to the /etc/default/grub, and tried:
virsh console vm-name
it shows the following error: Escape character is ^]
Check last response at: http://askubuntu.com/questions/1733/what-reason-could-prevent-console-output-from-virsh-c-qemu-system-console-g, which worked for me.
add the following in /etc/default/grub.conf in the VM (append to the “kernel” command):
kernel ….. serial=tty0 console=ttyS0,115200n8
Finally I secured the ttyS0 by adding “/etc/securetty” to enable root login from here
vi /etc/securetty
ttyS0