How to build Vagrant Debian base box using VirtualBox

I have already presented an easy way to build Vagrant Debian base box using qemu, but on some platforms it is better to use VitrualBox as it is not possible to use kvm accelerator.

I have prepared a simple set of differences against current debian-vm-templates repository that can be easily integrated into your own solution.

Replace |& control operators if you use older bash version. Otherwise skip it.

$ git diff packer-virtualbox-vagrant/Makefile
diff --git a/packer-virtualbox-vagrant/Makefile b/packer-virtualbox-vagrant/Makefile
index 539ec79..8cf8505 100644
--- a/packer-virtualbox-vagrant/Makefile
+++ b/packer-virtualbox-vagrant/Makefile
@@ -5,7 +5,7 @@ TESTED = wheezy.tested jessie.tested contrib-jessie.tested
 SHELL = /bin/bash # needed for |&
 # exit on undefined variables, pipeline fails if one command fails
 .SHELLFLAGS = -u -o pipefail -c
-TEE = |& tee --append $*.log # log every command
+TEE =  2>&1 | tee -a $*.log # log every command

 include ../helpers/vagrantBoxTesting.mk

Modify build process for Debian Jessie to use VirtualBox.

$ git diff packer-virtualbox-vagrant/jessie.json
diff --git a/packer-virtualbox-vagrant/jessie.json b/packer-virtualbox-vagrant/jessie.json
index 1f5d438..d4e3af0 100644
--- a/packer-virtualbox-vagrant/jessie.json
+++ b/packer-virtualbox-vagrant/jessie.json
@@ -25,7 +25,6 @@
         ""
       ],
       "disk_size": "10140",
-      "disk_interface": "virtio",
       "headless": true,
       "http_directory": "http",
       "iso_checksum": "9479c5c2df72ae3878116c43fb42eefae53d1fe363ce514a6afc8289064b9f5f",
@@ -36,12 +35,12 @@
       "ssh_username": "vagrant",
       "ssh_port": "22",
       "ssh_wait_timeout": "10000s",
-      "type": "qemu",
-      "qemuargs": [[ "-m", "1024M" ],[ "-smp", "2" ]],
-      "accelerator": "kvm",
-      "vm_name": "jessie.raw",
-      "output_directory": "jessie.build",
-      "format": "raw"
+      "type": "virtualbox-iso",
+      "guest_os_type": "Debian_64",
+      "vboxmanage": [["modifyvm", "", "--memory", "1024"]],
+      "vm_name": "jessie-template",
+      "format": "ova",
+      "output_directory": "jessie.build"
     }
   ],
   "provisioners": [

Build system image.

$ make jessie.build

Add new box build process for Debian Jessie.

$ git diff packer-virtualbox-vagrant/Makefile
git diff packer-virtualbox-vagrant/Makefile
diff --git a/packer-virtualbox-vagrant/Makefile b/packer-virtualbox-vagrant/Makefile
index 539ec79..dd2d895 100644
--- a/packer-virtualbox-vagrant/Makefile
+++ b/packer-virtualbox-vagrant/Makefile
@@ -35,6 +35,11 @@ contrib-%.box: PACKAGE_FLAGS =
        $(RM) vbox/$*/$*.vbox vbox/$*/$*.vbox-prev $(TEE)
        rmdir vbox/$* $(TEE)

+jessie.box:
+       vboxmanage import jessie.build/jessie-template.ova
+       vagrant package --base jessie-template --output jessie.box $(PACKAGE_FLAGS) $(TEE)
+       VBoxManage unregistervm jessie-template --delete $(TEE)
+
 %.vmdk: %.build
        qemu-img convert -O vmdk $</$*.raw $*.vmdk $(TEE)

Build the box.

$ make jessie.box

Use created jessie.box file.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu