List virtual machines using the command line

(from Tutorials and videos)

Open a Terminal window.

On Fedora and Debian you will need to become root. Type the following command and, when prompted, your root password:


Then you can list all the virtual machines:

virsh list --all

On Ubuntu, you should use sudo to run the command as root instead:

sudo virsh list --all

virsh list output explained #

When you run the command you should see a listing like this:

 Id Name                 State
  3 FedoraRawhide        running
  - Debian               shut off

The three columns are:

Other virt tools commands can use either the Id or the Name to refer to the virtual machine. For example these two commands are equivalent ways to show the console:

virt-viewer 3
virt-viewer FedoraRawhide

virsh list troubleshooting #

If virsh list displays an error, then try searching for the error or contacting us. For QEMU, KVM, and remote connections, ensure that the libvirtd service is running.

Many errors are obvious from the error message, for example:

error: no connection driver available for xen:///
error: failed to connect to the hypervisor

would mean that the Xen hypervisor is not running on the local machine.

If virsh list --all runs but displays nothing, it could mean:

virsh flags #

The --all flag lists all virtual machines, which includes ones which are currently running and ones which are switched off. If you omit this flag then only running virtual machines are shown.

Another useful flag is -c which can be used to select the hypervisor. This can be used if you are running two hypervisors on one machine (eg. Xen and QEMU guests), or if you are not root and want to connect to the system hypervisor, or to connect to a remote server running libvirtd.

Use the -r flag to connect read-only to the hypervisor. This is useful to perform operations while not requiring the root password.

For example, if you are not root and want to list QEMU and KVM guests without needing the root password you could do:

virsh -r -c qemu:///system list --all

This libvirt documentation describes remote connections in detail.

Back to Tutorials and videos.

Copyright © 2011 Red Hat, Inc. — License: GPL or CC — Last updated on 13:42:47 14-Jun-2011