Ubuntu KVM 3: Virsh Console Fix

Posted by Jared Kipe on | 0 Comments

Tags: , , , ,

You may find that immediately after installing your guest, you cannot connect to the guest via `virsh console`. Follow along as I add a serial console, designate it for use by grub, and add it to the guest's configuration file for virsh to use.

Note* For these articles I'm going to assume a clean Ubuntu 14.04 Trusty server install with minimal extras (nano, htop, openssh-server etc.) and/or the outcome of previous articles.

Virsh Console

Libvirt and Virsh can control the guest's state in a number of ways.  Though I typically connect to a running guest through SSH, there are times where I want to connect to a basic console for maintenance work.  Out of the box, `ubuntu-vm-builder` does not create a serial console that virsh can use for these times.

Create new serial console on guest

To create the console I make a new file at /etc/init/ttyS0.conf with the following contents:

start on stopped rc or RUNLEVEL=[2345]
stop on runlevel [!2345]

exec /sbin/getty -L 115200 ttyS0 vt102

Upstart will take care of getting this serial console running for us now

If you don't need, or want, to see the boot sequence within virsh, you can skip to the VM configuration edit piece.

Get grub to use this console

Edit /etc/default/grub to make the first 20 or so lines look more like this:

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DISTRIBUTON=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX="text console=tty0 console=ttyS0,115200n8"

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)

# Uncomment to disable graphical terminal (grub-pc only)
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --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

As described int this file, you must now run `update-grub` from your shell.

sudo update-grub

Time to edit /boot/grub/menu.lst to modify the very bottom of this file, where there are lines that look like "kernel ... ro ..."

#bottom kernel section
kernel ... ro vga=normal console=tty0 console=ttyS0,115200n8
kernel ... ro vga=normal console=tty0 console=ttyS0,115200n8 single

Edit Virtual Machine Configuration to add Serial Console

Pop over into your physical host and edit the configuration for your guest, e.g. `sudo virsh edit demo1`. Add the following lines into the <devices> node.

    <serial type='pty'>
      <target port='0'/>
    <console type='pty'>
      <target type='serial' port='0'/>

You can now restart your guest and connect to the guest's console, e.g. sudo virsh console demo1

Post your comment


No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments