Saturday 18 January 2014

VNC Access to Xen Guests

So I managed to get Xen up and running on my Arch Linux box and installed a Windows 8 guest using virt-manager forwarded to an X11 session on my Mac. I even managed to get a PCI controller passed through for some of my USB ports which allow me use mouse and keyboard in the VM.Yay!

However, using the windows desktop in this way is very clunky as I find the X11 session slow and it has mousing problems. So, I've started bypassing virt-manager altogether and launching my VM using XL create and a config file.

This leaves the problem of how to access the VM desktop. The obvious solution is a VNC client but it's not so straightforward, Here's how I managed to get it working...





prerequsites

The host machine running Xen must have sshd running and accessible.
The VM config must have VNC enabled. These are the relevant lines

vnc = '1'
vnclisten = '0.0.0.0'



STEP 1: Identify Console Port

With VNC enabled in a guest, xen/virtd presents each VMs console on a port starting at 5900.

To identify the correct port for your VM, issue xl list on the command line;

[root@enterprise ~]# xl list
Name                                        ID   Mem VCPUs State Time(s)
Domain-0                                     0  4096     2     r-----    1691.6
Win8                                         5  4091     2     -b----     276.6


You can see above, my Win8 VM has an ID of 5. To determine which VNC port this VM uses, issue the following;

[root@enterprise ~]# xenstore-read /local/domain/5/console/vnc-port
5900

(you would need to replace the '5' in the xenstore-read parameter with the ID determined in the previous command)

In my case, my VM is serving VNC on port 5900



STEP 2: SSH tunneling

Unfortunately, it wasn't possible to simply VNC into that port on my Linux pox.It's first necessary to set up an ssh tunnel using the -L option which specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.

iMac-Office:~ meep$ ssh -L 5901:localhost:5900 192.168.1.199

In the above, issues in a terminal on my my MAc, I'm connection port 5901 on my local machine with 5900 on my Xen hosting box (192.168.1.199)

I needed to use 5901 locally as 5900 was already in use. It doesn't really matter what local port you use as long as it does not conflict.



STEP 3: VNC Connection.

On my Mac I use Chicken of the VNC as my VNC client. Entering 'localhost:5901' in the server field of a new connection, I could connect through the tunnel and was presented with the Windows Desktop (via vnc port 5900 on the xen machine).

Of course, it wasn't all that straightforward. The VNC client was connecting but immediately disconnecting with an error: 'Unknown Rectangle Encoding;. A quick google search identified the problem relating to connection profiles and to fix it, I had to switch off all encoding standards apart from RAW


Windows 8 running in Xen VM accessed via VNC on OSX


REFERENCES
Using VNC to connect to a XenServer VMs Console
http://blogs.citrix.com/2011/02/18/using-vnc-to-connect-to-a-xenserver-vms-console/

About.com Linux SSH command reference
http://linux.about.com/od/commands/l/blcmdl1_ssh.htm

Fixing the Unknown Rectangle Encoding issue
http://www.mikesel.info/fixed-unknown-rectangle-encoding-1835861421/

2 comments:

Anonymous said...

Thanks for this post! It saved my sunday afternoon, trying to figure out how to connect to my Windows XP VM. And finaly, I am connected using Remmina and your advices ;-)

Anonymous said...

Thank you so much!