vagrant-libvirt: could not find capabilities for domaintype=qemu on mac

I almost have vagrant-libvirt running on macos, but running into an issue.

vagrant, libvirt and qemu are installed from homebrew. vagrant-libvirt is installed with vagrant plugin install vagrant-libvirt

Sample vagrant file:

Vagrant.configure(2) do |config|
  config.vm.provider :libvirt do |lv|
    lv.driver = 'qemu'
    lv.socket = '/usr/local/var/run/libvirt/libvirt-sock'
    lv.cpus = 1
    lv.memory = 512
  end
  config.vm.define 'test' do |node|
    node.vm.hostname = 'test'
    node.vm.box = 'generic/ubuntu1804'
  end
end
$ vagrant up
Bringing machine 'test' up with 'libvirt' provider...
==> test: Checking if box 'generic/ubuntu1804' version '1.9.16' is up to date...
==> test: Creating image (snapshot of base box volume).
==> test: Creating domain with the following settings...
==> test:  -- Name:              t_test
==> test:  -- Domain type:       qemu
==> test:  -- Cpus:              1
==> test:  -- Feature:           acpi
==> test:  -- Feature:           apic
==> test:  -- Feature:           pae
==> test:  -- Memory:            512M
==> test:  -- Management MAC:    
==> test:  -- Loader:            
==> test:  -- Nvram:             
==> test:  -- Base box:          generic/ubuntu1804
==> test:  -- Storage pool:      default
==> test:  -- Image:             /var/lib/libvirt/images/t_test.img (32G)
==> test:  -- Volume Cache:      default
==> test:  -- Kernel:            
==> test:  -- Initrd:            
==> test:  -- Graphics Type:     vnc
==> test:  -- Graphics Port:     -1
==> test:  -- Graphics IP:       127.0.0.1
==> test:  -- Graphics Password: Not defined
==> test:  -- Video Type:        cirrus
==> test:  -- Video VRAM:        256
==> test:  -- Sound Type:	
==> test:  -- Keymap:            en-us
==> test:  -- TPM Path:          
==> test:  -- INPUT:             type=mouse, bus=ps2
Error while creating domain: Error saving the server: Call to virDomainDefineXML failed: invalid argument: could not find capabilities for domaintype=qemu

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 42 (10 by maintainers)

Most upvoted comments

@ladar Thanks for the reply.

  1. There is not any virbrXX interfaces listed when I do ifconfig.
  2. If I play around with the device (i.e. try bridge0 which I see in ifconfig, I get a different error:

/Users/ermurphy/.vagrant.d/gems/2.4.6/gems/vagrant-libvirt-0.0.45/lib/vagrant-libvirt/driver.rb:59:in `open_read_only': Call to virConnectOpenReadOnly failed: internal error: unexpected QEMU URI path '/system', try qemu:///session (Libvirt::ConnectionError)

I am way over my head here on diagnosing the problem since I am new to these tools. Would be wonderful if someone could create a guide for using QEMU/Libvirt/Vagrant on Mac OS.

Have the same issue on my Mac

/Users/testuser/.vagrant.d/gems/2.6.6/gems/vagrant-libvirt-0.3.0/lib/vagrant-libvirt/driver.rb:59:in `open_read_only': Call to virConnectOpenReadOnly failed: Failed to connect socket to '/usr/local/var/run/libvirt/libvirt-sock-ro': No such file or directory (Libvirt::ConnectionError)

I explicitly specify the socket in my VagrantFile: v.socket = "/Users/testuser/.cache/libvirt/libvirt-sock"

The same error occurs with either one of the driverskvm or qemu (with or without session enabled)

Here’s a related issue that was filed against the libvirt project: https://gitlab.com/libvirt/libvirt/-/issues/75

Hi,

Tried the same on macOS and failed too…

created a baked-in packer image with

      "use_default_display": true,
      "display": "none",
      "accelerator": "hvf",

Was surprised it worked 😃.

Installed libvirt via brew but started the service with sudo (so that I had the qemu://system available) I also had to symlink libvirt-sock: sudo ln -s /usr/local/var/run/libvirt/libvirt-sock /var/run/libvirt/libvirt-sock

Then installed vagrant-libvirt with that wonderful command: CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/usr/local/include/libvirt with-libvirt-lib=/usr/local/lib' GEM_HOME=~/.vagrant.d/gems GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems PATH=/opt/vagrant/embedded/bin:$PATH vagrant plugin install vagrant-libvirt

But the simplest vagrantfile fails badly:

ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt'
Vagrant.configure("2") do |config|
  config.vm.define "fedo-01" do |config|
      config.vm.hostname = "fedo-01"
      config.vm.box = "fedora-31-x86_64.libvirt.box"
      config.vm.box_check_update = false
      config.vm.synced_folder ".", "/vagrant", disabled: true # do not work otherwise, try to start some SMB magic
      config.vm.provider :libvirt do |v|
        v.memory = 1024
      end
  end
end

which outputs /Users/charliemordant/.vagrant.d/gems/2.4.9/gems/vagrant-libvirt-0.0.45/lib/vagrant-libvirt/util/network_util.rb:117:in list_networks’: Call to virConnectNumOfNetworks failed: this function is not supported by the connection driver: virConnectNumOfNetworks (Libvirt::RetrieveError) `

This seems to be due to the fact that network is not valid on MacOS: https://github.com/libvirt/libvirt/blob/master/configure.ac#L198

How can we go further? I’m far from being a libvirt/qemu guy, just trying to make it work to have better perf than VirtualBox…

@ladar I would love to get to the bottom on at least understanding what is feasible, so either we can say this can’t work at all, or it can only work provided you set up networking outside of vagrant-libvirt because libvirt can’t do the network setup on macos. I don’t know how much effort can be put towards it, I think mostly it would have to start with a request for someone to confirm that libvirt + virt-manager is usable on MacOS and that you can create and boot a VM and share the XML files generated.

More a workaround than, but can we customise QEMU options ? The idea is to pass some option like these ones:

        <qemu:arg value='-netdev'/>
        <qemu:arg value='user,id=n1,hostfwd=tcp::2222-:22'/>
        <qemu:arg value='-device'/>
        <qemu:arg value='virtio-net-pci,netdev=n1,bus=pcie.0,addr=0x19'/>

Gathered from https://www.naut.ca/blog/2020/08/26/ubuntu-vm-on-macos-with-libvirt-qemu/, full XML template for Qemu is here: https://raw.githubusercontent.com/yoonsikp/vm_configs/master/ubuntu.xml

This way we can vagrant up and then ssh into the VM… which can be useful

As a backend developper, I always preferred to use Java rather than Assembly, so I would prefer a contribution to libvirt (that won’t be only useful for this plugin). However, I’m just discovering Qemu and infra/VM unix ecosystem so for sure not a good source of truth…

Hi,

Tried the same on macOS and failed too…

created a baked-in packer image with

      "use_default_display": true,
      "display": "none",
      "accelerator": "hvf",

Was surprised it worked 😃.

Installed libvirt via brew but started the service with sudo (so that I had the qemu://system available) I also had to symlink libvirt-sock: sudo ln -s /usr/local/var/run/libvirt/libvirt-sock /var/run/libvirt/libvirt-sock

Then installed vagrant-libvirt with that wonderful command: CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/usr/local/include/libvirt with-libvirt-lib=/usr/local/lib' GEM_HOME=~/.vagrant.d/gems GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems PATH=/opt/vagrant/embedded/bin:$PATH vagrant plugin install vagrant-libvirt

But the simplest vagrantfile fails badly:

ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt'
Vagrant.configure("2") do |config|
  config.vm.define "fedo-01" do |config|
      config.vm.hostname = "fedo-01"
      config.vm.box = "fedora-31-x86_64.libvirt.box"
      config.vm.box_check_update = false
      config.vm.synced_folder ".", "/vagrant", disabled: true # do not work otherwise, try to start some SMB magic
      config.vm.provider :libvirt do |v|
        v.memory = 1024
      end
  end
end

which outputs /Users/charliemordant/.vagrant.d/gems/2.4.9/gems/vagrant-libvirt-0.0.45/lib/vagrant-libvirt/util/network_util.rb:117:in list_networks’: Call to virConnectNumOfNetworks failed: this function is not supported by the connection driver: virConnectNumOfNetworks (Libvirt::RetrieveError) `

This seems to be due to the fact that network is not valid on MacOS: https://github.com/libvirt/libvirt/blob/master/configure.ac#L198

How can we go further? I’m far from being a libvirt/qemu guy, just trying to make it work to have better perf than VirtualBox…

the same issue, do you have resolved this problem?

I am very interested in getting qemu and libvirt working on Mac as well. I have had some success but am currently running into an error.

/Users/ermurphy/.vagrant.d/gems/2.4.6/gems/vagrant-libvirt-0.0.45/lib/vagrant-libvirt/driver.rb:121:in `list_all_networks': Call to virConnectListAllNetworks failed: this function is not supported by the connection driver: virConnectListAllNetworks (Libvirt::RetrieveError)

I also had to create symbolic link sudo ln -s ~/.cache/libvirt/libvirt-sock /var/run/libvirt/libvirt-sock

Current Vagrantfile

Vagrant.configure(2) do |config|
  config.vm.provider :libvirt do |lv|
    lv.driver = 'qemu'
    lv.cpus = 1
    lv.memory = 512

    # Use QEMU session instead of system connection
    lv.qemu_use_session = true
    # URI of QEMU session connection, default is as below
    lv.uri = 'qemu:///session'
    # URI of QEMU system connection, use to obtain IP address for management
    # TODO: Unsure what to do here on Mac running in user space
    lv.system_uri = 'qemu:///system' 
    # Management network device
    #lv.management_network_device = 'virbr0'

  end

  config.vm.define 'test' do |node|
    node.vm.hostname = 'test'
    node.vm.box = 'centos/7'

    node.vm.network :public_network,
      :dev => "virbr1",
      :mode => "bridge",
      :type => "bridge"
  end
end

Please let me know if there is anything obviously wrong here. I am new to Vagrant, Qemu, and Libvirt.

I am interested in collaborating to resolve this issue. I would like to demonstrate CentOS 7 running.