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:
- starting guide
- installation happens after installing Oracle’s VirtualBox
- guide
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+ groupadmin+ sudo config - To get the correct keymap under Macbook Pro:
Terminal
|
- Install the other required elements:
Terminal
|
-
Customize it
- in our puppet infrasctructure, assuming
/vagranthosts the modules / manifest, you can run puppet inside the VM as follows:
- in our puppet infrasctructure, assuming
Terminal
|
- Also remember to upgrade the Virtualbox Guest Additions (see above)
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_1342049820in 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, selectSettings / Storage / CD DVD Driveto mount theVBoxGuestAdditions.isoimages.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
- for linux :
in the VMs:
$> vagrant ssh
$> mount /media/cdrom
$> cd /media/cdrom/
$> sudo sh ./VBoxLinuxAdditions.run
