Friday 3 June 2011

Access a virtual machine's console

I'm not 100% sure about this objective, perhaps because it is at the same time very easy and more  complicated than the rest of the objectives.

The easy part first then. One can access the console of a virtual machine using virt-manager. Thus from a terminal you need to type:

virt-manager


Pretty picture of Virtual Machine Manager

This so unsatisfyingly simple and somewhat counter to standard practice that I find this objective very strange. If you tried to run virt-manager from a console, you will have realized that this is actually a graphical application and thus you need to install a windows manager in your server, which the default installation of the server edition does not do.

Let's do things the Linux way then.

Type virsh to enter the "user management interface"

You can then simply do console domain-id, where domain-id is the name of the virtual machine that you want to connect to.

Simple, right? Well, not quite. You'll be face by this
virsh console test1
Connected to domain test1
Escape character is ^]
Only thing that does anything here, is CTRL + ], ie. close this connection.  The problem here is that we are trying to connect to the serial console, but the system by default will only ouput to the virtual consoles tty0, etc. Therefore we have to make the kernel ouput on the serial console as well and this can be done by simply adding console=ttyS0 to your kernel parameters line in grub.conf file (/boot/grub/grub.conf). An example can be found below:
kernel /vmlinuz-2.6.32-71.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_LVM_LV=VolGroup/lv_root rd_LVM_LV=VolGroup/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=uk crashkernel=auto rhgb quiet console=ttyS0
Note, that you could also modify this line while booting, see this, but it won't be permanent that way.

Once you have done this, you can try again
virsh console test1
Connected to domain test1
Escape character is ^]
 Some result?, hit enter and you get this

Red Hat Enterprise Linux Server release 6.0 (Santiago)
Kernel 2.6.32-71.el6.x86_64 on an x86_64

localhost.localdomain login:
Now, we are talking :)

No comments:

Post a Comment