← Home

Oracle Linux 7 on Vagrant - Creating a new base box

For the last few months, I’ve been using Vagrant to spin-up local virtual environments. To use it, you specify a base OS installation (a box) and then “provision” whatever you need on top (e.g. run some shell scripts), define the networking and vagrant will start everything up for you.

Vagrant lets you use base OS installations (boxes) from a cloud repository which makes it quick to get going, but I’m uneasy about running mystery virtual machines made by strangers on my PC and often, there’s a standard build in place at each organisation.

You can make your own base box by starting up Virtualbox and manually installing the operating system using the instructions at [0] but you end up with a document full of steps to follow and a binary blob, which makes it difficult to make changes to the base build and maintain a full revision history.

A better way is to use the packer [1] tool to build a box from a configuration file and a bunch of shell scripts locally. This means that your base installations can be maintained as source code in a repository. You can optionally upload the resulting VM image in Hashicorp’s Atlas [2] system for distribution, which saves your team members from having to recreate the box locally or from having to distribute it some other way e.g. file share.

Atlas also has a build system, which lets you upload your build configuration and scripts (packer push ./template.json) and let their system build it in the cloud for free, which is what I ended up doing.

I needed an Oracle Linux 7 box, so I forked from the packer example Ubuntu box. Ubuntu uses pre-seeding to do unattended installation, whereas RHEL et al. use Kickstarter. Once I’d done that, and switched out apt-get for yum, it mostly worked.

The biggest issue I had was getting the Virtualbox Guest Additions installed so that networking and shared drives could be used within Vagrant. This was confusing because once I’d got the relevant dependencies installed (bzip and some compilation tools), the build logs showed that it had installed, and yet it still didn’t work.

This turned out to be down to a yum update rebuilding the kernel and making the guest additions stale. The DKMS package used by Debian-based systems allows the Virtualbox Guest Additions to be retained after a kernel update, but this isn’t available in Oracle Enterprise Linux. After many failed Atlas builds, I moved the yum update to early on in the process and stuck in a reboot and it worked perfectly after that.

Atlas / packer can’t restart at any points in the flow, so each failure resulted in a complete rebuild. Not much effort in wall clock time, but it took a few days to of calendar time to get it right.

If Atlas could be updated to take a VM snapshot before each step completes so that you can restart at a given provisioning point and download the snapshots, it would make debugging a much faster process. It could be also be improved by hooking into GitHub or other source code repositories (in the same way that Appveyor and other cloud CI services work) so that an updated repo results in an updated base box with a specific revision - i.e. Atlas proves that the box is actually built from a specific repo at a specific code revision. Also, I’m not sure that the Atlas build servers cache the ISO downloads, since this seems to take longer than it should.

Anyway, the Atlas configuration and scripts are over at [3] and the base box is at [4]

If you need a base UK Oracle Enterprise Linux installation, you can use the box “a-h/oracle_linux_7” as the box name in your Vagrantfile or fork my configuration and make your own.