1

In a discussion spawned from the issue to connect to libvirt through ssh we discussed about using libvirt with the usual default of qemu://session right after installing libvirt* packages as there are some hurdles to pass - those hurdles do not exist as soon as you re-login btw.

What will happen is like:

$ apt install libvirt-daemon-system
$ virsh list
error: failed to connect to the hypervisor
error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': 
Permission denied

But actually slightly more sinister is when it works but you later miss your guests. Which is due to the default right after install being from the binaries which is qemu:///session (in newer versions where this was changed).

$ apt install libvirt-daemon-system $ virsh uri qemu:///session

2

The reason for the issues above is that two things are missing in your current shell (or script) right after install.

  1. you lack the membership in the libvirt group. That membership is auto-added for all members of the wheel (who can run sudo) group, but isn't active until you log in (again) so that you pick up that group
  2. The default URI can change (e.g. upstream), Ubuntu opted for users to stay as they are used to be by exporting 'LIBVIRT_DEFAULT_URI=qemu:///system' but that is done in a profile.d element at '/etc/profile.d/libvirt-uri.sh' which again is only picked up at a new login.

Messing with the users login as package install time was discussed, but discarded for having too much potential to break things for something that fortunately is a corner case. But if you want to e.g. in one script install libvirt and use it you need some minor adaptions to be able to do so.

export LIBVIRT_DEFAULT_URI=qemu:///system
sg libvirt -c virsh <...>

Thanks @marosg for the discussion about this!

  • yeah, that was an interesting exercise, what threw me off was difference between 16.04 and 18.04, but as you explained it is due to changes upstream – marosg Mar 28 '19 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.