OCaml/MirageOS Diary, Part 4A

Published:

In preparation for the MirageOS Hackathon I spent some time setting up a development environment.

Installing and Developing Inside OSX

Install OCaml (if you haven't already), using Home Brew:

# get opam package manager
brew install opam
# get latest ocaml
opam switch 4.02.3
eval `opam config env`
# a repl
opam install utop

Then install the mirage libraries [2].

Then it's a case of following the documentation on the MirageOS website [3].

Very straight forward.

Deploying to Xen, with Ubuntu, Inside VBox, Inside OSX

This process is more complicated. MirageOS unikernels will ultimately be deployed inside the Xen hypervisor (as used by many cloud hosting services) (hypervisor like supervisor, not "really, really good visor").

A hypervisor or virtual machine monitor (VMM) is a piece of computer software, firmware or hardware that creates and runs virtual machines. [4]

Running inside OSX (or other *nix OS), the Mirage OS compilation process uses various opam modules that allow your server application to run as a regular executable.

When compiled for Xen these modules are swapped for equivalents that interact directly with Xen's emulated hardware (QEMU) environment. It becomes a self contained Operating System. The resulting .xen file contains the entire unikernel (application and OS in one).

To have a self contained development environment, on your workstation, two nested hypervisors are required: VirtualBox and Xen. VBox to run a Linux/Unix distribution (as dom0) side-by-side with Xen. The Mirage unikernels will run in/on Xen/domU.

Setting these up manually took a couple of hours and was a little fiddly. I found Magnus Skjegstad's guide to be the most clear and helpful [5].

I had pre existing Docker Machines, with host only networks, on Virtual Box so had to adjust the instructions to use a different IP. Another option was removing everything from VBox and starting fresh.

I looked Packer/Vagrant images [6] [7] but these didn't work first try, I stuck with what I had.

Next Steps

I'm interested in testing my knowledge by creating a guide, similar to Magnus's, using Alpine Linux.

Then build a Packer/Vagrant project for getting a repeatable automated environment working.

A long term goal could be to create a set of tools similar to those used in the docker/lxc ecosystem. Providing something like docker-machine and docker-compose to aid setup of VMs, build, deployment and networking between instances.

If that tool was built in OCaml, I'd be very happy (although this is beyond me just now).

The tools described above would be very useful for on boarding developers looking to get up and running with Mirage without having to get into the finer points of how the environment fits together. And, perhaps, all this is being worked on by Docker/Unikernel Systems?