KVM - The Linux Kernel-Based Virtual Machine
News, Blogs and Resources on the Linux (KVM) Kernel-Based Virtual Machine

Tip: How to run a headless guest machine using VNC with KVM

Running a KVM virtual machine on your desktop with the default screen output is fine if you're using it on your PC for desktop use. However, for running KVM guest machines in a server setting where you may have many virtual machines running concurrently, the best way to run the guest machine(s) is headless with a vncserver attached to the video console. To do this, run qemu/kvm with the -vnc option. For example

qemu-system-x86_64 -hda windows.img -m 384 -vnc :1

Note the space between -vnc and :1. This will start the virtual machine without any video output to your desktop screen so that it's now running as a headless daemon. To get a video console to your running machine, open up a vnc client and connect to the ip address of the kvm host with :1 at the end of the address. For example, if the ip address of the kvm host is 192.168.1.1 you will connect your vnc client to 192.168.1.1:1. If you're going to start any more headless machines concurrently then increment the display numbers ie :2, :3, :4 etc. This is a simple procedure but I'm sure there are some newbies out there who aren't very familiar with qemu/kvm's many options.

See Also

Comments

To complete your post, 1) The

To complete your post,

1) The vncserver included in qemu has a irritating drawback. There's a gap between the real mouse pointer and the vnc mouse pointer. You can use the "-usbdevice tablet" option to avoid this unpleasant effect.

qemu-system-x86_64 -hda windows.img -m 384 -vnc :1 -usbdevice tablet

2) using the -vnc option you can also use the -daemonize option to run qemu in daemon mode

3) using -vnc :1 option, every host on the network can obtain the vm display, you can limit access specifying the interface allowed to obtain the display (as mentioned in the qemu man page) there're also some tls or . x509 options to secure display access. I personally set -vnc option with 127.0.0.1:1 and I use ssh tunnels to access to the vm display.
Here is my kvm command

kvm -hda windows.img.qcow2 -m 1024 -vnc 127.0.0.1:1 -usbdevice tablet -daemonize

then, I start a ssh session specifying the tunnel from any host on the network

ssh -L 5901:127.0.0.1:5901 w.x.y.z

where w.x.y.z is the host address running the vm

and start a vncviewer session through the tunnel

vncviewer localhost:1

Regards

Jacques Landru

Very useful and practical

Very useful additions Jacques especially on the security aspect of ssh tunneling for securing your vnc session. Thanks for highlighting these details.

Very helpful

The tip on the USB Tablet thing is very helpful...

How about using rdesktop

How about using rdesktop instead of vnc ?

%/usr/local/bin/qemu-system-x86_64 -m 256 -soundhw es1370 -hda /media/E/winxp.img -hdb /dev/sda7 -localtime -net nic -net user -nographic -daemonize -redir tcp:3389::3389 -boot c -k en-us &

%rdesktop localhost:3389 -u *** -p *** -g 1440x880 -D -K -r sound:remote

Sincerely !

using a '-p -' instead of the

using a '-p -' instead of the =p passwd will get rdesktop to prompt you each time you start it. Bung it in a file and make it excecutable.

Post new comment

The content of this field is kept private and will not be shown publicly.