How to Connect to Virtual Machine using virt-viewer

Posted on

This is an article written for discussing on how a virtual machine created or started in a libvirt daemon or service is being accessed using a specific command. The command itself is ‘virt-viewer’ which is executed in any command line interface. The environment is in Ubuntu 16.04 but mainly it can be executed in any environment of operating system which has been installed with libvirt package. Based on the information retrieved from the manual page provided in Linux operating system, virt-viewer is used to display the graphical console for a virtual machine.

The reason for using virt-viewer to access a virtual machine in a graphical console is because the console provided by webvirt which is installed for managing virtual machines is not working. The following is the image of the feature provided by webvirt to access graphical console which is in the case of the situation faced not working at all :

How to Connect to Virtual Machine using virt-viewer

Since, Access via Console is not working as the feature shown in the image above, there will be a necessity to find another tool which can provide access directly to the virtual machines. The tool which is going to be discussed in this article for achieving that purpose is a tool called ‘virt-viewer’. It is retrieved from installing a package which also has the same name, it is ‘virt-viewer’ package. We can retrieve the information by executing a tool for generating information about that command. For an example, we can use ‘dpkg -s’ in ubuntu or any debian flavor of linux operating system. Below is the output of it :

root@hstname:~# dpkg -s 'virt-viewer'
Package: virt-viewer
Status: install ok installed
Priority: extra
Section: admin
Installed-Size: 1965
Maintainer: Ubuntu Developers <[email protected]>
Architecture: amd64
Version: 1.0-1
Depends: libc6 (>= 2.4), libgdk-pixbuf2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.41.1), libgtk-3-0 (>= 3.0.0), libgtk-vnc-2.0-0 (>= 0.3.10), libpango-1.0-0 (>= 1.14.0), libspice-client-glib-2.0-8 (>= 0.25), libspice-client-gtk-3.0-4 (>= 0.22), libvirt0 (>= 1.2.8-0ubuntu11), libxml2 (>= 2.7.4)
Suggests: netcat
Description: Displaying the graphical console of a virtual machine
 The console is accessed using the VNC protocol. The guest can be referred to
 based on its name, ID, or UUID. If the guest is not already running, then the
 viewer can be told to wait until is starts before attempting to connect to the
 console The viewer can connect to remote hosts to lookup the console
 information and then also connect to the remote console using the same network
 transport.
Original-Maintainer: Debian Libvirt Maintainers <[email protected]>
Homepage: http://virt-manager.et.redhat.com/
root@hostname:~# 

Make sure that the package has already installed as shown below :

root@hostname:~# apt list --installed | grep virt-viewer
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
virt-viewer/xenial,now 1.0-1 amd64 [installed]
root@hostname:~#

So, in order to connect to a certain virtual machine, just list the available virtual machine first :

root@hostname:~# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     my-virtual-machine             running
root@hostname:~#

Connect to the virtual machine using the ‘virt-viewer’ command as shown below :

virt-viewer -c qemu:///system my-virtual-machine

Leave a Reply