Tibor's Musings

Building Vagrant Boxes with Veewee

Veewee is a useful tool helping to build Vagrant boxes for virtualised development. Here is how I build Debian, Scientific Linux, CentOS, and FreeBSD boxes.

Installing prerequisites

If you do not have Vagrant installed yet, you should start with that:

sudo apt-get install vagrant

You may also need to enable VT-x virtualisation in BIOS in order to be able to run Vagrant with VirtualBox on your laptop.

Let's now install veewee:

sudo apt-get install ruby-dev
sudo gem install veewee

Building Debian-7 box

Debian box type is already available:

veewee vbox templates | grep Debian

so let's clone it:

veewee vbox define debian7-amd64 'Debian-7.2.0-amd64-netboot'

Now I've edited the template, because I had already downloaded Debian ISO image file previously; so I opened definitions:

vim definitions/debian7-amd64/definition.rb

and replaced ISO image name debian-7.2.0-amd64-netinst.iso by the one I downloaded debian-7.2.0-amd64-i386-netinst.iso and placed in iso subdirectory.

Optionally, one can also download VirtualBox guest additions:

sudo aptitude install virtualbox-guest-additions-iso
wget http://download.virtualbox.org/virtualbox/4.2.16/VBoxGuestAdditions_4.2.16.iso

and again place it in the iso subdirectory.

Now let's build the base box:

veewee vbox build 'debian7-amd64'

Depending on the laptop specs and the network speed, the box will be built in about twenty minutes.

Export it for vagrant via:

vagrant package --base debian7-amd64 --output debian7-amd64.box

Now it can be used with vagrant in the usual manner; we can add it via:

vagrant box add debian7-amd64 ./debian7-amd64.box

and test it out by creating and connecting to a new Debian virtual machine:

mkdir -p ~/private/vagrant/test-vm-debian7
cd ~/private/vagrant/test-vm-debian7
vagrant init
cat > Vagrantfile <<EOF1
Vagrant.configure("2") do |config|
  config.vm.box = "precise64"
  config.vm.hostname = 'localhost.localdomain'
  config.vm.network :forwarded_port, host: 8080, guest: 8080
  config.vm.network :forwarded_port, host: 8443, guest: 8443
vagrant up
vagrant ssh

We are done.

Building ScientificLinux-6.4 box

Here is a complete compact recipe on how to build a Scientific Linux box:

veewee vbox templates | grep scientificlinux
veewee vbox define sl6-x86_64 'scientificlinux-6.4-x86_64-netboot'
curl -C - -L 'http://ftp.heanet.ie/pub/rsync.scientificlinux.org/6.4/x86_64/iso/SL-64-x86_64-2013-03-18-boot.iso' -o 'iso/SL-64-x86_64-2013-03-18-boot.iso'
md5sum 'iso/SL-64-x86_64-2013-03-18-boot.iso'
veewee vbox build 'sl6-x86_64'
# fails at the very end due to chef needing ruby >= 1.9.2 so let's remove chef/puppet and restart...
vim definitions/sl6-x86_64/definition.rb # edit :postinstall_files to comment out chef and puppet loading
veewee vbox build 'sl6-x86_64' --force # restart vbox creation
# now it succeeded
vagrant package --base sl6-x86_64 --output sl6-x86_64.box
vagrant box add sl6-x86_64 ./sl6-x86_64.box

Building CentOS-6.4 box

The same recipe obviously works to build CentOS too, since they both stem from RHEL:

veewee vbox define centos6-x86_64 'CentOS-6.4-x86_64-netboot'
vim definitions/centos6-x86_64/definition.rb # comment away chef and puppet
veewee vbox build 'centos6-x86_64' # press `No' so that we download manually
curl -C - -L 'http://www.mirrorservice.org/sites/mirror.centos.org/6.4/isos/x86_64/CentOS-6.4-x86_64-netinstall.iso' -o 'iso/CentOS-6.4-x86_64-netinstall.iso'
md5sum 'iso/CentOS-6.4-x86_64-netinstall.iso'
veewee vbox build 'centos6-x86_64' # now go on
vagrant package --base centos6-x86_64 --output centos6-x86_64.box
vagrant box add centos6-x86_64 ./centos6-x86_64.box

Building FreeBSD-9.1 box

I've also build FreeBSD box using the same approach. When doing so, the installation was timing out; so I had to add more Wait statements in the box definition:

$ vim definitions/freebsd-9.1/definition.rb
$ less definitions/freebsd-9.1/definition.rb
    'mdmfs -s 100m md1 /tmp<Enter>',

after which the build succeeded.

unix vagrant