Skip to content

Instantly share code, notes, and snippets.

@zarvox
Last active March 15, 2016 19:30
Show Gist options
  • Save zarvox/4e87f02b98ea0d34df98 to your computer and use it in GitHub Desktop.
Save zarvox/4e87f02b98ea0d34df98 to your computer and use it in GitHub Desktop.

Using vagrant-spk with libvirt

If you're running on Linux, you have the option of using vagrant-spk with Vagrant's libvirt backend. Some developers have performance or reliability issues with VirtualBox and prefer to use libvirt.

Some caveats:

  • libvirt is not the default Vagrant backend, and is nowhere near as widely used as the VirtualBox backend. Things may break, either in Vagrant, libvirt, or in vagrant-spk.
  • You will have to do some additional up-front configuration, which may be annoying/burdensome.

That said, Drew (@zarvox) uses the libvirt backend for all of his vagrant-spk work, and would prefer that it work for people in general, so if you're so inclined, try it out, and file bugs if you hit issues. Thanks!

Install libvirt/libvirtd/virt-manager

On Fedora, this would be:

sudo dnf install virt-manager libvirt libvirt-daemon

On Debian/Ubuntu:

sudo apt-get install libvirtd virt-manager

Install vagrant

Fedora:

sudo dnf install vagrant

Install vagrant-libvirt

Fedora:

sudo dnf install vagrant-libvirt

Disable sandboxing of your VM/SELinux enforcement

This is necessary to allow mounting shared folders from your user's home directory (or wherever the app you're developing is located) read-write, and getting the correct permissions out the other side.

Fedora: edit /etc/libvirt/qemu.conf and set the following keys (there are comment blocks for each in the default config):

security_driver = "none"
user = "root"
group = "root"
dynamic_ownership = 0
clear_emulator_capabilities = 0
  • The first key says "disable SELinux enforcement".
  • The second and third say "run qemu-kvm as root", which is needed so that the process has CAP_DAC_OVERRIDE and can create files owned by your user account.
  • The fourth key says "don't change files to be owned by root". We want files owned by your user account, by and large.
  • The fifth key says "don't drop CAP_DAC_OVERRIDE". Linux has a curious feature which allows processes running as root to drop certain privileges. However, in this case, we need the one that allows you to read/modify/write files owned by other users (namely, the user you are doing development as).

Install vagrant-mutate and import a box

We need the vagrant-mutate plugin to import a box originally packaged for VirtualBox, convert it to the libvirt disk image format, and register it as the equivalent box name for Vagrant to use it.

Install the plugin:

vagrant plugin install mutate

Import the VirtualBox box:

vagrant box add sandstorm/debian-jessie64

Produce an appropriate box for usage with libvirt:

vagrant mutate sandstorm/debian-jessie64 libvirt

Set libvirt default provider

Fedora users can skip this step.

To make sure vagrant knows to use the libvirt backend for managing VMs, you'll need to set an environment variable:

export VAGRANT_DEFAULT_PROVIDER=libvirt

You'll probably want to put the above line in your $HOME/.bashrc so you don't have to type it every time you open a shell that you use vagrant-spk in.

Use vagrant-spk with libvirt

Now, whenever you use vagrant-spk, vagrant should attempt to use the libvirt backend when creating VMs. :)

If you have an app where vagrant-spk previously created a VirtualBox VM, vagrant will continue to interact with that VM until you run vagrant-spk destroy, after which the next vagrant-spk up should create a libvirt VM.

@dwrensha
Copy link

I also needed to dnf install the redhat-rpm-config, libvirt-devel, and ruby-devel packages, plus:

vagrant plugin install vagrant-mutate

and

vagrant plugin install --plugin-version 0.0.3 fog-libvirt

(see fog/fog-libvirt#16)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment