KVM Home | Installation | Networking | Create Guests | Managing | Guest Console Access | Directly | FAQ |
Direct terminal access via Serial Console
It is possible to access a KVM Guest directly using the Serial Console interface, in which case setting up bridged networking, SSH, and similar is not necessary. Access via the Serial Console provides an alternate way of accessing your servers to compliment or replace the default VNC access.
This is done using the virsh utility which is a shell interface for libvirt.
Define a console device for the Guest
Check whether a console device had been defined:
virsh ttyconsole my_vm
If the output is shown(e.g. /dev/pts/41), it indicates the Guest has a console device already.
Otherwise, define one with virsh edit. Here is an example to be added inside <device></device>. Refer to libvirt XML format for details.
<console type='pty'> <target port='0'/> </console>
Configure a Serial Console in the Guest
First, we need to configure a serial console in the guest, in order that it will accept a connection:
If the version of your guest Ubuntu OS is 15.04 (Vivid) or later, run the following systemctl commands to enable the serial console:
systemctl enable serial-getty@ttyS0.service systemctl start serial-getty@ttyS0.service
The following configuration method works for (guest) Ubuntu 9.10 (Karmic) until Ubuntu 14.10 (Utopic):
sudo editor /etc/init/ttyS0.conf
Add the configuration:
# ttyS0 - getty # # This service maintains a getty on ttyS0 from the point the system is # started until it is shut down again. start on stopped rc RUNLEVEL=[2345] stop on runlevel [!2345] respawn exec /sbin/getty -L 115200 ttyS0 xterm
Run the following command to initiate the Serial Console (or restart the VM):
sudo start ttyS0
Here we are using "xterm" as the terminal type, which works well if we are connecting using a gnome-terminal (or xterm) instance. It is likely preferable to set this to match the terminal type which will be used to connect. This can be found using this command in the host/client terminal you will be using to connect:
echo $TERM
For example, if you are running screen it is "screen", for byobu "screen-bce", etc.
You can also set the variable temporarily when you are already connected to the console:
export TERM=screen
If you are using an earlier version of Ubuntu see SerialConsoleHowto for instructions.
Connect using virsh
First we connect to the (local) qemu session:
virsh -c qemu:///session
Now in the virsh shell, start the virtual machine:
start my_vm
When it has started connect to the console:
console my_vm
Press Return to get the login prompt, and login as usual (note that username input works even if the login promt is not shown).
You're in!
Misc notes
Use Ctrl + ] to exit the console.
If the console acts strangely or displays incorrectly, check that the TERM variable is set correctly (see above).
If the terminal seems to cut off the top of the output, change it to have 80x24 of viewing area, e.g. in byobu this means you will need to account for the statusbar and have the window itself at 80x26
This page seems to be missing part of the procedure for console access. The instructions do not include configuring the host machine for serial access. You may need to search google if you see "No console available for domain".
KVM Home | Installation | Networking | Create Guests | Managing | Guest Console Access | Directly | FAQ |