Date created: Monday, March 6, 2017 4:53:36 PM. Last modified: Tuesday, March 7, 2017 9:33:30 AM

Serial/Console Access to Guest

Add "serial=tty0 console=ttyS0,115200n8" to the Kernlin boot line in /boot/grub/grub.cfg:

linux   /boot/vmlinuz-3.13.0-110-generic root=UUID=xxxxxx ro serial=tty0 console=ttyS0,115200n8

This allows the console output from the guest to be redirected (but it does not spawn a login shell so that the guest VM may be accessed):

user@kvm(~)$virsh --connect qemu:///system start vm1
Domain vm1 started

user@kvm(~)$virsh --connect qemu:///system console vm1
Connected to domain vm1
Escape character is ^]
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.13.0-110-generic (buildd@lcy01-30) (gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) ) #157-Ubuntu SMP Mon Feb 20 11:54:05 UTC 2017 (Ubuntu 3.13.0-110.157-generic 3.13.11-ckt39)
...
 * Stopping save kernel messages                                         [ OK ]
 * Starting CPU interrupts balancing daemon                              [ OK ]
 * Starting OpenSSH server                                               [ OK ]
 * Starting crash report submission daemon                               [ OK ]
 * Restoring resolver state...                                           [ OK ]
 * Stopping System V runlevel compatibility                              [ OK ]

In order to have a login shell spawned in addition the following change is also required:

username@guest-vm:~/ sudo cp /etc/init/tty1.conf /etc/init/ttyS0.conf
username@guest-vm:~/ sudo vi /etc/init/ttyS0.conf
# Replace the existing exec line with:
exec /sbin/getty -8 115200 ttyS0 xterm
# Then shutdown the VM and start it again.
user@kvm(~)$virsh --connect qemu:///system start vm1
Domain vm1 started

user@kvm(~)$virsh --connect qemu:///system console vm1
Connected to domain vm1
Escape character is ^]
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.13.0-110-generic (buildd@lcy01-30) (gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) ) #157-Ubuntu SMP Mon Feb 20 11:54:05 UTC 2017 (Ubuntu 3.13.0-110.157-generic 3.13.11-ckt39)
...
* Stopping save kernel messages [ OK ]
* Starting CPU interrupts balancing daemon [ OK ]
* Starting OpenSSH server [ OK ]
* Starting crash report submission daemon [ OK ]
* Restoring resolver state... [ OK ]
* Stopping System V runlevel compatibility [ OK ]
Ubuntu 14.04.5 LTS vm1 ttyS0 vm1 login:

If a guest VM updates it's grub menu and removes the serial/console redirection option (due to a kernel update for example), files within the guest virtual disk can be edited directly using virt-edit:

sudo apt-get install libguestfs-tools && sudo virt-edit vm1 /boot/grub/grub.cfg

Previous page: Qemu, KQemu, KVM
Next page: IOS-XRv Example