Skip to content

Instantly share code, notes, and snippets.

@rollwagen
Last active May 24, 2021 09:56
Show Gist options
  • Save rollwagen/4cd3209104bbffabc45ee1bad020129f to your computer and use it in GitHub Desktop.
Save rollwagen/4cd3209104bbffabc45ee1bad020129f to your computer and use it in GitHub Desktop.
Vagrant on macos with libvirt

Vagrant using libvirt on macos

Pre-reqs

   brew install qemu gcc libvirt
   brew services start libvirt
   vagrant plugin install vagrant-libvirt

libvirt socket location / issues on macos

  • e.g. "Failed to connect socket to ‘/var/run/libvirt/libvirt-sock’: No such file or directory"
  • see Discussion and solution on brew.sh
  • depnding on error and socket location quick/dirty alternative is..
    • a symlink: sudo ln -s ~/.cache/libvirt/libvirt-sock /var/run/libvirt/libvirt-sock
    • directly specifying socket location in Vagrantfile

validate libvirt is working/running

$ virsh
virsh # connect qemu:///session?socket=/Users/rollwagen/.cache/libvirt/libvirt-sock
list

Vagrantfile

Vagrant.configure("2") do |config|

  config.vm.provider :libvirt do |libvirt|
    #libvirt.socket="/usr/local/var/run/libvirt/libvirt-sock"
    libvirt.uri="qemu:///session?socket=/Users/rollwagen/.cache/libvirt/libvirt-sock"
    libvirt.socket="/Users/rollwagen/.cache/libvirt/libvirt-sock"
    libvirt.qemu_use_session = true
    #libvirt.uri = "qemu:///session"
    libvirt.driver="qemu"
  end

  config.vm.box = "archlinux/archlinux"
  config.vm.synced_folder ".", "/vagrant", disabled: true
end

quemu / libvirt faq

  • What's the difference between qemu:///system and qemu:///session link

  • In case of quemu errors qemu-system-x86_64: Error: HV_ERROR, need to explicitely grant executable permission to qemu

    • create xml file e.g. entitlements.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>com.apple.security.hypervisor</key>
        <true/>
    </dict>
    </plist>
    • codesign -s - --entitlements entitlements.xml --force /usr/local/bin/qemu-system-x86_64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment