It is time to look into build process of Debian Vagrant box, create one using packer utility for creating machine and container images and alter the whole process it a little bit.

I will be honest with you and say that I have underestimated this utility at first, but it is irreplaceable for this kind of operation.

Install packer utility

Install unzip utility.

$ sudo apt-get install -y unzip

Download packer utility.

$ curl -O https://releases.hashicorp.com/packer/0.10.1/packer_0.10.1_linux_amd64.zip

Extract it to /usr/local/bin directory for an easy access.

$ sudo unzip -d /usr/local/bin/ packer_0.10.1_linux_amd64.zip packer
Note that packer is statically linked, so it will work without additional dependencies.

Download source of vanilla Debian base box

Install qemu utility as it will be used during build process.

$ sudo apt-get install -y qemu

Install git utility to download source code.

$ sudo apt-get install -y git

Clone vanilla Debian base box debian-vm-templates repository.

$ git clone git://anonscm.debian.org/cloud/debian-vm-templates.git

Build an image using packer utility

Install qemu utility.

$ sudo apt-get install -y qemu

Change working directory to packer-virtualbox-vagrant inside downloaded earlier debian-vm-templates project.

packer-virtualbox-vagrant$ cd debian-vm-templates/packer-virtualbox-vagrant/

Verify that template is valid.

packer-virtualbox-vagrant$ packer validate jessie.json

Perform build process.

packer-virtualbox-vagrant$ make jessie.build

Create box file that can be used with Vagrant.

packer-virtualbox-vagrant$ make jessie.box

Apply custom modifications

Modify operating system installation process

Modify http/vanilla-debian-8-jessie-preseed.cfg to alter installation process.

It is good place to modify default timezone and basic package manager settings.

Modify initial Vagrantfile

Note that Vagrantfile.in file will be packaged with a box, so modify it to according to your needs. It will be loaded before other Vagrant files according to Load order and merging.

These steps will be included or performed later during Vagrant operations, not during build process.

You can use it to perform configuration steps (like nfs mounts and so on) shared across different Vagrant configurations.

Modify build process

Alter provisioners block inside jessie.json configuration file to add custom shell scripts that will be executed during build process.

You can use it to install puppet and perform other steps shared across different Vagrant configurations.

References

Teams – Cloud – Vagrant Base Boxes

Teams – Cloud – Rebuild Vagrant Base Boxes

Packer documentation

Vagrant – Vagrantfile

Vagrant – Package

Debian installer – Preseed