Date created: 03/06/17 16:53:36. Last modified: 03/07/17 09:33:30

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):

[email protected](~)$virsh --connect qemu:///system start vm1
Domain vm1 started

[email protected](~)$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 ([email protected]) (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:

[email protected]:~/ sudo cp /etc/init/tty1.conf /etc/init/ttyS0.conf
[email protected]:~/ 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.
[email protected](~)$virsh --connect qemu:///system start vm1
Domain vm1 started

[email protected](~)$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 ([email protected]) (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