Building Vagrant boxes with veewee
If you used vagrant (great tool, right?) you have probably downloaded a basebox from some remote location to get you started. This is a great quick start, and there are many good boxes out there that you can use; vagrantbox.es does a great job in listing various public vagrant boxes. But if you are like me, you probably will want to customize the boxes you are using; you might want to install them from scratch based on your own little/or/big customizations. Well if you are like that, then you will be happy to hear that Patrick Debois had exactly the same problem when he decided to write veewee. And veewee is exactly that missing part of vagrant that allows you to easily build your own vagrant boxes from scratch.
So let’s see how we can use veewee. I’m assuming you already have vagrant installed (and virtualbox), but if you don’t please install them first. To install veewee we just have to install the veewee gem:
gem install veewee
once you installed veewee you can see a new task added to vagrant: basebox.
Here is the list of the templates we get out of the box once we install veewee:
**vagrant basebox templates** The following templates are available: vagrant basebox define '' 'archlinux-i686' vagrant basebox define '' 'CentOS-4.8-i386' vagrant basebox define '' 'CentOS-5.6-i386' vagrant basebox define '' 'CentOS-5.6-i386-netboot' vagrant basebox define '' 'Debian-6.0.1a-amd64-netboot' vagrant basebox define '' 'Debian-6.0.1a-i386-netboot' vagrant basebox define '' 'Fedora-14-amd64' vagrant basebox define '' 'Fedora-14-amd64-netboot' vagrant basebox define '' 'Fedora-14-i386' vagrant basebox define '' 'Fedora-14-i386-netboot' vagrant basebox define '' 'freebsd-8.2-experimental' vagrant basebox define '' 'freebsd-8.2-pcbsd-i386' vagrant basebox define '' 'freebsd-8.2-pcbsd-i386-netboot' vagrant basebox define '' 'gentoo-latest-i386-experimental' vagrant basebox define '' 'opensuse-11.4-i386-experimental' vagrant basebox define '' 'solaris-11-express-i386' vagrant basebox define '' 'Sysrescuecd-2.0.0-experimental' vagrant basebox define '' 'ubuntu-10.04.2-amd64-netboot' vagrant basebox define '' 'ubuntu-10.04.2-server-amd64' vagrant basebox define '' 'ubuntu-10.04.2-server-i386' vagrant basebox define '' 'ubuntu-10.04.2-server-i386-netboot' vagrant basebox define '' 'ubuntu-10.10-server-amd64' vagrant basebox define '' 'ubuntu-10.10-server-amd64-netboot' vagrant basebox define '' 'ubuntu-10.10-server-i386' vagrant basebox define '' 'ubuntu-10.10-server-i386-netboot' vagrant basebox define '' 'ubuntu-11.04-server-amd64' vagrant basebox define '' 'ubuntu-11.04-server-i386' vagrant basebox define '' 'windows-2008R2-amd64-experimental'
This means that we can build a box based on any of the above templates. That’s awesome! Let’s say we want to build a debian squeeze box using veewee; we would have to run:
vagrant basebox define 'debian-60' 'Debian-6.0.1a-amd64-netboot'
and this will create a folder definitions/debian-60 with the following files (the content of the veewee template):
definition.rb postinstall.sh preseed.cfg
we can modify/tune any of those files based on our custom needs. The file definition.rb is the main definition of the template. Here you would define the memory size, disk size, iso file, etc. The content is very easy to understand, but you would normally not have to change many things here. preseed.cfg is just a standard preseed file where you would customize the actual install process (you could change here the partitions or their type, timezone setup, etc). And finally postinstall.sh that is a bash script that will run at the end of the installation process and it will install ruby, gems , chef and puppet and also the virtualbox guest additions (needed for shared folders).
If you have the iso already place it in ‘currentdir’/iso. If not, veewee will download it and place it in the appropriate folder before starting the install process:
vagrant basebox build 'debian-60'
this will start the installation and you can see all the steps it takes (the keystrokes as they are entered, etc.). This can take a while… Once it is done you can validate the build with:
vagrant basebox validate 'debian-60'
(this will run a few basic tests to see if it can connect to the vm as user vagrant, if chef and puppet were installed, if the shared folders are accessible, etc).
And finally you can export it as a vagrant box with:
vagrant basebox export 'debian-60'
and add it to vagrant:
vagrant box add 'debian-60' debian-60.box
and now you can use it in vagrant with:
vagrant init 'debian-60'
That’s it. Very simple and now we have our own box built from scratch. As a side note, I found this very useful to test and troubleshoot preseed configurations ;). As you can see there are plenty of templates available in veewee but if you create a new one please consider to share it with others and send it to Patrick on github. I’m sure he will be happy to include it in newer versions of veewee. And if you found this useful don’t forget to thank Patrick for his great work on this awesome tool.