KVM Virtualisation: Start VNC Remote Access For Guest Operating Systems

In this post we will try to cover one important task which we need in case of KVM virtual machine connectivity issues and that is VNC configuration of KVM virtual machines.

There are times when we need to troubleshoot Virtual Machines with unknown status like Hang in between, IP address issues, password problems, Serial console Hang etc.

In case scenarios, we could relay on VNC configuration of KVM Guest Machines. So let's try to understand,how could we make it possible.


For this post we are going to use Ubuntu17.04, Latest version as of now.

#virsh list
 Id    Name                           State
 18    ubuntu-17.04                   running

#virsh vncdisplay ubuntu-17.04
error: Failed to get VNC port. Is this domain using VNC?

Now we need to configure this KVM Guest in such way that, we could able to take VNC from Host machine. For same we need to take dumpxml of Guest machine and edit it accordingly.

So we would work on ubuntu-17.04 KVM Guest below.

#virsh list --all
 Id    Name                           State
 -     office_image                   shut off
 -     srv6                           shut off
 -     srv7                           shut off
 -     srv7.1                         shut off
 -     ubuntu-17.04                   shut off

First we should know directory store system image file

#virsh domblklist ubuntu-17.04
Target     Source
hda        /data/vmware_images/Ubuntu17.04/system.img

So should change directory on this and take dump for same.

#cd /data/vmware_images/Ubuntu17.04/
total 3.3G
-rw-r--r-- 1 root root 3.3G Aug  6 00:11 system.img
#virsh dumpxml ubuntu-17.04 > ubuntu-17.04.xml
total 3.3G
-rw-r--r-- 1 root root 3.3G Aug  6 00:11 system.img
-rw-r--r-- 1 root root 3.7K Aug  6 00:17 ubuntu-17.04.xml

Now we need to edit dumpxml file, so that we could start virtual machine with effected change. Add below line in dumpxml file, save and exit

<graphics type='vnc' port='-1' autoport='yes' passwd='Passw0rd'/>

In this change we assigned one password for VNC connection.
you can check my dumpxml file here.

Now need to create KVM Guest again with below command

#virsh create ubuntu-17.04.xml 
Domain ubuntu-17.04 created from ubuntu-17.04.xml

#virsh vncdisplay ubuntu-17.04

Now try to connect it from VNC Viewer like below







Small video on same