Virsh for regular users

2 minutes read

Introduction

You’ve been using virt-manager to manage your VMs but are now moving towards using virsh and the command line instead.
However when you try to list your VMs you don’t see them.

No show!

Let’s try and list our VMs

$ virsh list --all
 Id   Name   State
--------------------

Hmm, not what we’d hoped for. It turns out that the default behaviour (at least on Fedora 29) is for virsh to use virsh --connect qemu:///session which according to the virsh(1) manpage states:

qemu:///session
    connect locally as a normal user to his own set of QEMU and KVM domains

— virsh(1)

Solution

From the above mentioned manpage we also find the following connection option:

qemu:///system
    connect locally as root to the daemon supervising QEMU and KVM domains

— virsh(1)

So if we try this things are looking better.

$ virsh --connect qemu:///system list --all
 Id   Name      State
--------------------
1     master1   running
2     node1     running
You now have full permissions on all VMs, be careful!

Make it permanent

Also from the virsh(1) manpage:

LIBVIRT_DEFAULT_URI
    The hypervisor to connect to by default. Set this to a URI, in the same format as accepted by the connect option. This overrides the default URI set in any client config file and prevents libvirt from probing for drivers.

— virsh(1)

Easy enough

$ echo 'export LIBVIRT_DEFAULT_URI=qemu:///system' >> ~/.zshrc
$ source ~/.zshrc

And now for the final test

$ virsh list --all
 Id   Name      State
--------------------
1     master1   running
2     node1     running