Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory

Hallo!

I’m trying to setup vagrant-libvirt in macOS, so that I can run qemu-provided Vagrant boxes. I have installed Vagrant 2.0.1 via caskroom/cask/vagrant, as well as the vagrant-libvirt 0.0.40 plugin, based on brew’s libvirt 3.9.0 formula (whew!)

However, when I try to run vagrant up --provider libvirt, Vagrant reports:

Error while connecting to libvirt: Error making a connection to libvirt URI qemu:///system?no_verify=1&keyfile=/Users/andrew/.ssh/id_rsa&socket=/var/run/libvirt/libvirt-sock:
Call to virConnectOpen failed: Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory

Now, I’m new to libvirt, so I’m not really sure how to get the /var/run/libvirt/libvirt-sock connection going in macOS. I’ve seen similar messages about missing sockets with Docker, that are easy enough to resolve by ensuring that Docker is running, and occasionally reloading the shell environment to update any important environment variables. But with libvirt, I don’t see an obvious way to get this socket setup. brew info libvirt doesn’t show any kind of service associated with libvirt, unlike with docker, redis, postgresql, etc. I did find virtlogd, and ran that foreground (silent) application, but by itself, it doesn’t appear to affect the missing socket error presented by Vagrant.

Any idea what a macOS user should do at this point? It would be helpful if the libvirt formula setup this socket on behalf of Vagrant users, but I wasn’t sure if I should suggest this on homebrew-core, in case Discourse is a better place to post this. Anyway, what are the next steps here?

Update

I found libvirtd and ran that foreground application in another terminal tab for now. This still does not allow any virsh -c "qemu+ssh://$(hostname)/system?socket=/var/run/libvirt/libvirt-sock" kind of connection to succeed, but I suspect it’s a form of progress. The libvirtd stderr log shows:

2017-11-14 07:22:56.636+0000: 18446744073709551615: info : libvirt version: 3.9.0
2017-11-14 07:22:56.636+0000: 18446744073709551615: info : hostname: mockingjay.local
2017-11-14 07:22:56.636+0000: 18446744073709551615: warning : virProcessGetStartTime:1070 : Process start time of pid 86142 not available on this platform
2017-11-14 07:22:56.640+0000: 18446744073709551615: error : virConnectOpenInternal:1118 : no connection driver available for qemu:///session

Not sure if this is okay, or if the no connection driver error is getting in the way of virsh from connecting. I just don’t know.

I think the Homebrew formula for libvirt should prepare the libvirtd service in a plist, present the command to the user in the brew info libvirt section, just like how docker, redis, postgresql services are described. Uh, we’ll probably need a more complete libvirtd configuration, but this is a start for really bringing the formula together into a more Just Works^TM mode.

Homebrew 1.9.2 still seems to exhibit related failure.
brew doctor
OK
brew install libvirt
… says it’s installed
brew services start
…says it’s running
But
virsh -c vbox:///
fails (there’s another thread with my writeup on that).

Ultimately, the failure seems to be the lack of any -sock files in
/usr/local/var/run/libvirt

is there something (known) incomplete w.r.t. the service startup or the configuration of libvirtd?

Since there aren’t followups on this thread, did you get it to work manually?

Option 1 (User only Socket):
The sockets seem to be created in ~/.cache/libvirt so using libvirt.socket = “~/.cache/libvirt/libvirt-sock” should work (not tested)

Option 2 (Global Socket):

  1. stop libvirtd if running (brew services stop libvirt)

  2. Edit /usr/local/Cellar/libvirt//homebrew.mxcl.libvirt.plist
    Since XML is not formatting here properly, find the command section (/usr/local/Cellar/libvirt//sbin/libvirtd), and add two new “string” lines (as it is an array) containing ‘-f’ and ‘/usr/local/etc/libvirt/libvirtd.conf’ respectively.

  3. Edit the libvirtd.conf file (find the section for unix_socket, similar to this:
    #################################################################

    UNIX socket access controls

    Set the UNIX domain socket group ownership. This can be used to

    allow a ‘trusted’ set of users access to management capabilities

    without becoming root.

    This is restricted to ‘root’ by default.

    unix_sock_group = “admin”

    Set the UNIX socket permissions for the R/O socket. This is used

    for monitoring VM status only

    Default allows any user. If setting group ownership, you may want to

    restrict this too.

    unix_sock_ro_perms = “0770”

    Set the UNIX socket permissions for the R/W socket. This is used

    for full management of VMs

    Default allows only root. If PolicyKit is enabled on the socket,

    the default will change to allow everyone (eg, 0777)

    If not using PolicyKit and setting group ownership for access

    control, then you may want to relax this too.

    unix_sock_rw_perms = “0770”

    Set the UNIX socket permissions for the admin interface socket.

    Default allows only owner (root), do not change it unless you are

    sure to whom you are exposing the access to.

    unix_sock_admin_perms = “0770”

    Set the name of the directory in which sockets will be found/created.

    unix_sock_dir = “/usr/local/var/run/libvirt”

  4. Start libvirtd (brew services start libvirt)

  5. In Vagrant file, have the fiollowing:
    config.vm.provider :libvirt do |libvirt|
    libvirt.driver = ‘qemu’
    libvirt.socket = “/usr/local/var/run/libvirt/libvirt-sock”
    libvirt.qemu_use_session = true
    end

After that I can use vagrant with libvirt on the mac. (running Mojave)

Hope that helps