Inception: running Vagrant inside Vagrant with KVM

Since I package and maintain Vagrant and vagrant-libvirt for Fedora, I have a need to test new builds. But since I run just one version of Fedora and I don’t really feel like testing it directly on my host system, I actually use Vagrant to test Vagrant. In other words I run Vagrant with KVM and inside I download the new builds and run Vagrant with KVM again. This is possible because KVM supports nested virtualization. In fact I already wrote about setting that up with virt-manager. But today I show you how to do it using Vagrant itself.

First we need to configure vagrant-libvirt on the host system to enable KVM nested virtualization:

I have the above lines in my user’s Vagrantfile so these options are always applied (read more on that). If we would try to spin up a new machine with Vagrant and try to run Vagrant with libvirt inside it, we would get something like the following.

This happens because Vagrant already used the default network on eth0 interface. We can fix it by specifying a different one in our Vagrantfile:

This helps but trying vagrant up again still fails. This time Vagrant complains about memory allocation:

The thing is that we allocated a default 512 MB for our virtual machine and then again trying to allocate another 512 MB inside for our nested environment. Lucky for us, this is easy to fix by increasing the number in the Vagrantfile:

That’s it! As you can see Vagrant with vagrant-libvirt provider makes these things really simple.

Leave a comment

Your email address will not be published. Required fields are marked *