Install KVM guest using VNC

It's simple enough to install a headless (without display) distro using KVM, but when it comes to installing a guest with a user interface, this needs to be done over VNC, and here's how to do it:

sudo virt-install --name YOUR-VM-NAME --ram 12288 --disk path=~/kvm/images/DISK-NAME.qcow2,size=100 --vcpus 8 --os-type linux --os-variant generic --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole --cdrom /home/base4/ubuntu-17.04-desktop-amd64.iso

The important part of the above command are the following two parameters:

–graphics vnc,listen=0.0.0.0
–noautoconsole

–graphics vnc,listen=0.0.0.0 instructs virt-install to use a VNC display

–noautoconsole instructs virt-install not to wait for a console connection

By default VNC will use the first available screen on port 5900. To check this you can run the following command on the HOST:

sudo virsh vncdisplay YOUR-VM-NAME

The following should be returned:

:0

To check that VNC is running on port 5900:

netstat -tln|grep :59

The following should be returned:

tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN

The final step to connect to VNC of the guest VM is to open your VNC viewer on any PC on the same network and connect using the following:

vnc://192.168.100.8:5900

Where 192.168.100.8 is the address of the HOST and 5900 is the default VNC port.

You will now connect up to the VM using VNC to complete the installation using the GUI.