Logo

HPC @ Uni.lu

High Performance Computing in Luxembourg

Tips on Vagrant Boxes

Vagrant uses Oracle’s VirtualBox to build configurable, lightweight, and portable virtual machines dynamically. More and more to test the various workflow we implement in an isolated and repeated way, we rely on this solution: most of our developments (Puppet, Modules etc.) can be tested locally using Vagrant VMs.

This post is just to share some notes on the advanced usage of Vagrant, such as:

  • the creation of new Vagrant boxes;
  • reducing the size of created boxes;
  • the installation of the Guest Additions

Resources:

Interesting plugins

  • Vbguest: A Vagrant plugin to keep your VirtualBox Guest Additions up to date

Creation of a new Box

In general you wish to customize one of the Vagrant box available on the Internet

Special notes for setting a Debian host:

Conventions: 
	Hostname: vagrant-[os-name], e.g. vagrant-debian-lenny
	Domain: vagrantup.com
	Root Password: vagrant
	Main account login: vagrant
	Main account password: vagrant
  • [eventually] create a user vagrant + group admin + sudo config
  • To get the correct keymap under Macbook Pro:

Terminal

$> apt-get install console-data
   ...
$> dpkg-reconfigure console-data
   ...
   Policy for handling keymaps:
       Select keymap from full list
   Configuring console-data
       mac / Unknown / French / Standard / MacBook
  • Install the other required elements:

Terminal

$> apt-get install puppet
  • Customize it

    • in our puppet infrasctructure, assuming /vagrant hosts the modules / manifest, you can run puppet inside the VM as follows:

Terminal

$> sudo puppet apply  --modulepath=/vagrant/modules --manifestdir=/vagrant/manifests/ /vagrant/manifests/site.pp

Once you have a version that satisfies you so that you wish to commit the changes you applied, you can package again the box (assuming the box is still up and running and configure to suit your tastes) via vagrant package

  • locate the name of the running VM by opening VirtualBox (puppet-repo_1342049820 in the below example). Use the following command for that:

      $> VBoxManage list runningvms
    

Create the box (which will generate the file package.box) that you can then rename and share

	(local)$> vagrant package --base puppet-repo_1342049820 # change to whatever suffix Virtualbox provided
    (local)$> mv package.box ~/Dropbox/Public/Vagrant/debian-squeeze-amd64_puppet-repo.box        

Reducing the size of the box

Resources:

Inside the VM:

	sudo aptitude install zerofree
	sudo apt-get clean
	sudo rm -rf /usr/src/vboxguest*
	sudo rm -rf /usr/share/doc
	sudo find /var/cache -type f -exec rm -rf {} \;

Then halt the VM with vagrant halt

Restart the VM with VirtualBox and log in as root (the root password is set to vagrant normally):

	init 1

	mount -o remount,ro /dev/sda1
	zerofree /dev/sda1

Installing the latest Guests addition

  • Install Vbguest

      $> vagrant vbguest --status
    

To manually install it:

  • open VirtualBox, select Settings / Storage / CD DVD Drive to mount the VBoxGuestAdditions.iso images.

    Guess by your host operating system:

    • for linux : /usr/share/virtualbox/VBoxGuestAdditions.iso
    • for Mac : /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso
    • for Windows : %PROGRAMFILES%/Oracle/VirtualBox/VBoxGuestAdditions.iso

in the VMs:

 $> vagrant ssh
 $> mount /media/cdrom
 $> cd /media/cdrom/
 $> sudo sh ./VBoxLinuxAdditions.run