0

I have created a VM with virt-install, using as install media a Ubuntu 14.04.01 LTS server ISO. During the installation phase I was connected to the VM via the graphical console.

Now I have the VM running: I can ssh to it, and it is otherwise working fine. I can follow the boot process, with:

virsh console my-vm

But I am unable to see the login prompt. How can I access the login prompts with are normally allocated via the PTYs?

5
  • Use virt-manager? Oct 1, 2014 at 12:30
  • Then go find a computer that does have a GUI, such as the one you're sitting at. Oct 1, 2014 at 12:34
  • @MichaelHampton: As I said, no GUI: ImportError: No module named libvirt. virt-manager is broken in Ubuntu (actually, Mint)
    – blueFast
    Oct 1, 2014 at 13:32
  • Then you have bigger problems to solve. Oct 1, 2014 at 13:33
  • Not really. My VM is working fine, I do not use virt-manager, I do not want to use virt-manager. I just want to connect to the login prompt of the VM. Surely virt-manager is not a dependency of libvirt, correct? You can run VMs without virt-manager, with full functionality, correct? So, now that we have that cleared: how do I configure the VM to be able to connect with virsh console (or any other virsh command?) to the login prompt? I do not know it, and it seems you do not know it neither. Which is fine. Maybe somebody else knows it?
    – blueFast
    Oct 1, 2014 at 13:38

1 Answer 1

1

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.

  1. 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'>

  1. 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:

This is the configuration method for (guest) Ubuntu 9.10 (Karmic) and later versions.

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
  1. 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

  1. Connect using virsh

First we connect to the (local) qemu session:

virsh -c qemu:///session (this is optional, and if you prefer not to use a virsh console, you can simply prepend commands with virsh in bash. I.e. virsh start my_vm, virsh console my_vm etc)

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

  1. You're in!

  2. 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

The set of instructions has been shamelessly copied with minor adjustments from https://help.ubuntu.com/community/KVM/Access

5
  • This looks promising. I will check if my guest has the tty defined (I thought this was standard). What worries me is this sentence: "note that username input works even if the login promt is not shown". If I do not get visual output, this is not really gonna help me: no use running commands on the VM if I get not output.
    – blueFast
    Oct 1, 2014 at 13:54
  • I usually follow a different route and simply uncomment the ttyS0 line in inittab, but I've no idea whether Ubuntu still has it, I use RHEL/Fedora. After you execute virsh console VM, there is no prompt, but hitting enter makes it show up, and everything works from that point on.
    – dyasny
    Oct 1, 2014 at 13:56
  • For me hitting enter (repeteadly!) did not have any effect. My VM is not up now. but I will try this later and report. Thanks for the hint!
    – blueFast
    Oct 1, 2014 at 14:00
  • Well, I've seen plenty of cases when kvm/libvirt/qemu/etc misbehaved on ubuntu and worked perfectly on fedora, no surprises there :)
    – dyasny
    Oct 1, 2014 at 14:41
  • thanks!!! Defining the ttyS0 in the guest worked. Now I will be able to tweak the VM, even if network access is not working! If I could upvote you 10 times, I would do it!
    – blueFast
    Oct 1, 2014 at 16:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .