Virtualization on Mac OS X using Vagrant (Part 1)

Fiercely
3 min readNov 9, 2016

--

Note: Post kindly written by Nuno Pássaro, minor contributions by António Howcroft Ferreira

I have recently joined Fiercely and an interesting problem arose when I had to set up my environment, there is no way to run a linux CentOS box in a lightweight virtualization provider other than Docker on OSX.

At Fiercely, we are intensive users of Vagrant, as some of our clients have applications deployed on Windows connected to applications deployed on Linux, and vice-versa. As such, in order to be able to help them, we must be able to mimic this ecosystem on our machines. I know what you’re thinking “Just use Docker already…” and, trust me, we would but, some client systems are just not there yet. We need an intermediate solution to help us on our way…

So, on my MacBook Pro (Retina, 15-inch, Mid 2014), we started by adding a VirtualBox provider to our existing Vagrantfile and we spined up our two Linuxes and a Windows virtual machine. While that was happening… I went for a coffee, called my wife, took my dog for a walk and calmly sat back down while watching the final steps of the machines initialization (you get the point, it was a long wait). Starting with the box sizes, which affected download time (especially windows), and the speed at which things were being executed, everything just seemed too slow.

We all know that VirtualBox is heavy and slow. Don’t get me wrong, it is an awesome tool if you want to experiment with an OS or even use another OS without any heavy lifting, but once you have to put 3 different applications running, in 3 different virtual machines (one of them being Windows) with build processes running, “well, good luck!”.

We knew that there is little that can be done with the Windows behemoth (although Windows Server Core and, more recently, Nano Server are solving some of the issues). So we could only hope that at least the Linux machines would be optimizable. At this time, we knew that Docker had launched Docker for Mac using Hyperkit under the hood. And, from the words of Hyperkit’s authors came our salvation:

“HyperKit is a toolkit for embedding hypervisor capabilities in your application. It includes a complete hypervisor, based on xhyve/bhyve, which is optimized for lightweight virtual machines and container deployment.

We’ve found our saviour. Now, we only have to discover how it can save us. We decided that it should be in the form of a Vagrant provider, and luckily we found two:

Unfortunately, both were in a very early stage, but we had a starting point. Even so, we decided to go for oldpatricka/vagrant-xhyve, since it was already published as ruby gem, and overall, it looked simpler.

We established a few pre-requisites before starting on the vagrant provider. First, we have to know how to use xhyve to run a linux distribution in order to build a vagrant box successfully. Second, we experiment with our box and oldpatricka/vagrant-xhyve to discover the missing parts and the caveats. Finally, fork oldpatricka/vagrant-xhyve and start to build on top of it. In this process we found some interesting leads:

As you might have noticed, our Linux flavour is CentOS. It was kind of tricky to install and correctly boot the machine.

In the next post, I will tell you, in detail, how we installed and ran a CentOS 7.2 using xhyve and prepared it to be a Vagrant box.

--

--

Fiercely

We use the most current engineering techniques and tools to ensure our clients’ deliveries are value driven, fast and rock solid