This is a Packer template to help you generate a custom Vagrant / VirtualBox box image based on the latest release of Ubuntu LTS. It starts with a minimal Ubuntu Server install, enables OpenSSH for remote shell access and then uses provisioning scripts to build up required box templates from leaving minimal Ubuntu server minimal, to installing some useful tooling, to setting up a desktop environment. lubuntu-datadev-vm uses this Packer project as a starting point.
The code has been tested and working using Packer 1.6.2 and VirtualBox 6.1.12 on a Windows 10 machine with Ubuntu Server 20.04.1 LTS ISO.
Rolling your own base box gives you full control and transparency over what goes into it - you can optimise your template to your specific needs. It is also an opportunity to lock down your box template from security perspective by not using insecure accounts and secrets used in publicly available downloads.
-
Make sure you have a recent version of Packer and VirtualBox installed and working on your system. Command examples provided in the project documentation also assume you are using PowerShell with script execution enabled and have Git installed and configured to work on Windows Command Prompt. You can easily adapt these to your CLI and most will work without any modifications.
-
Clone or download this repository.
git clone git://github.com/artislismanis/packer-template.git
-
Download the relevant Ubuntu Server ISO installation media into the
iso
folder, make note of the related checksums. -
Review the Packer template you want to use (this example uses
ubuntu-20.04-server-base.json
):- Modify VM specification in
vboxmanage
section to match your available system resources. These are standard VirtualBox VBoxManage commands - see VirtualBox manual for full reference. - Review user variables in
variables
section. Make surevm_iso_image
,vm_iso_image_checksum
andvm_iso_image_checksum_type
have the correct values assigned. Make other adjustments as required. Variables can be set in the template file or managed through runtime overrides like described in these Packer examples. See project wiki for further details on available user variables.
- Modify VM specification in
-
Run packer build in the root of the repository folder.
packer build ubuntu-20.04-server-base.json
Check out override-examples for different ways to override default user variables.
-
Wait for the build to finish. End to end build of minimal Ubuntu Server box using the specified VM configuration takes under 15 minutes, Lubuntu Desktop under 50 minutes. The output is saved in
box/virtualbox/
folder and can be used withvagrant box add
as described in Vagrant CLI documentation.
The project provides two templates ubuntu-20.04-server-base.json
and lubuntu-20.04.json
. lubuntu-20.04.json
includes Vagrant Cloud post-processor and will fail if used without specifying valid Vagrant Cloud details & key in user variables section. You can exclude the post-processor form running by triggering build like so:
packer build --except=publish-vc lubuntu-20.04.json
If you do want to build and publish your box to Vagrant Cloud, the template expects you to specify tag, token and version in VC_TAG
, VC_TOKEN
and VC_VERSION
environmental variables respectively.
The project has some rudimentary test build scripts and brief documentation to help with testing - check out the notes on testing for more details.
Over time project wiki will be evolved to include more detail and troubleshooting information. In the meantime check out 'Useful Resources' section below if you get stuck.