Setting a different libvirt uri for Vagrant

HashiCorp Vagrant normally selects the right hypervisor, but the version shipped with Fedora 30 prefers to run within the QEMU user session of the hypervisor. A Vagrantfile it would match the default behavior which doesn’t require any system privileges is shown below.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.define "test01" do |test01|
    config.vm.box = "centos/7"
    config.vm.box_version = "1902.01"
    config.vm.hostname = "test01.localdomain"
    config.vm.provider :libvirt do |domain|
      domain.uri = 'qemu:///session'
    end
  end
end

In some cases a virtual machine needs to run on QEMU system level and that can be done by changing the domain.uri from “qemu:///session” to “qemu:///system”. Vagrant now creates the virtual machine at the system level of the hypervisor and isn’t depending on any user environment to run.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.define "test01" do |test01|
    config.vm.box = "centos/7"
    config.vm.box_version = "1902.01"
    config.vm.hostname = "test01.localdomain"
    config.vm.provider :libvirt do |domain|
      domain.uri = 'qemu:///system'
    end
  end
end

Membership of group libvirt maybe required or the right permissions with sudo for example. The first isn’t really advised except on local development system and then even sudo is still advised to reduce any accidental errors.

Published by Hans Spaans

Unix & security consultant with a passion for Linux, Solaris, PostgreSQL, Perl and network services, but also a strong believer in open and free source, standards and content.