Virsh won't return domains

I’m trying to write a script and app shortcut to easily start and open a remote desktop session to a windows VM that I’m hosting on my PC with libvirt.

I’ve already run:

sudo usermod -aG kvm ${USER}
sudo usermod -aG libvirt ${USER}

But I can’t seem to get any output when I try to list VMs with virsh list unless I run it as root. I’m not getting a “permission denied” error anywhere, just an empty list.

Do you guys know what I need to do to get this working?

Have you read the man page for virsh?
For the list command I see this


          list [--inactive | --all]
               [--managed-save] [--title]
               { [--table] | --name | --uuid | --id }
               [--persistent] [--transient]
               [--with-managed-save] [--without-managed-save]
               [--autostart] [--no-autostart]
               [--with-snapshot] [--without-snapshot]
               [--with-checkpoint] [--without-checkpoint]
               [--state-running] [--state-paused]
               [--state-shutoff] [--state-other]

       Prints information about existing domains.  If no options are specified it prints out information about running domains.

When I did this it gets nothing

$ virsh list
 Id   Name          State

But when I added the option it gives this

$ virsh list --all
 Id   Name          State
 -    ubuntu18.04   shut off

Man pages are your friend.

Also, there are differences in the return when run with my regular user vs running it with sudo.
Your script may need to use sudo to achieve your goal.

Remember that you can give specific commands extra rights in the sudoers file.

1 Like

virsh list shows running domains
virsh list --all shows also the “shut off” one

If you still see nothing you have to use the URI to list it:
virsh -c qemu:///system list --all

You can set this URI as default creating a libvirt.conf in /home/username/.config/libvirt
adding uri_default = "qemu:///system"

Thanks @ilikelinux
I did not know the same answer.
Adding the entry you suggested to ~/.config/libvirt/libvirt.conf makes it so the return from ‘virsh list’ as my normal user returns the same as the command given as root.

I appreciate learning something new every day. :saluting_face:

1 Like

me too … that’s why i’m here