packer-ubuntu-2004
This repository contains Packer templates for creating, and publishing, Ubuntu 20.04 Vagrant boxes based on Virtualbox.
Goals
There are a good number of public vagrant boxes, however each one has some issue that made them unsuitable for my out of box usage. I wanted to experiment freely, and iterate rapidly, so decided to build and publish my own with the following goals:
- English GB localisation. (Locale and keyboard)
- Ubuntu LTS OOB experience to mimic a locally installed server.
- All Updates applied.
- Travis to build and publish.
- Ubuntu-mate-core desktop
-
Github actions to auto build and publish up to date boxes.(No VM support)
Credits
- Jeff Geerling's excellent geerlingguy/packer-boxes repository.
- boxcutter/ubuntu repository.
Published Boxes
Requirements
The versions of software I used are in parenthesis. YMMV.
- Packer (1.6.x)
- Virtualbox (6.1.x)
- Optional: Hashicorp Vagrant Cloud Account, should you want to publish your builds.
- Optional: Vagrant (2.2.x) for local development and usage.
Local development
To experiment locally, without uploading to Vagrant cloud, provide the packer argument -except=
.
- Run:
packer build -except=vagrant-cloud ubuntu.json
.
After a few minutes a ready to use box will be in the builds directory. - Edit the provided Vagrantfile to point to the local box.
- Run:
vagrant up
Publishing a Box to Vagrant Cloud
-
Log in to your Vagrant Cloud Account
-
Create an Authentication Token
- Save the long string somewhere safe. Later, this will be exported as the env variable
VAGRANT_CLOUD_TOKEN
.
- Save the long string somewhere safe. Later, this will be exported as the env variable
-
Create a new Vagrant Box
- Tip: Enter the Name as
ubuntu2004
In the next step, the value for"vm_name":
will not need editing.
- Tip: Enter the Name as
-
Edit ubuntu.json, changing the values for:
"vagrantcloud_username": "neil_kidd"
"vm_name": "ubuntu2004"
. -
Paste your Auth Token into the following command and run:
VAGRANT_CLOUD_TOKEN={REPLACE_THIS} packer build ubuntu.json
-
Sometime later the terminal should have output similar to:
... virtualbox-iso (vagrant-cloud): Box successfully uploaded ==> virtualbox-iso (vagrant-cloud): Releasing version: 2004.20200628.082705 virtualbox-iso (vagrant-cloud): Version successfully released and available Build 'virtualbox-iso' finished.
-
Edit the provided Vagrantfile to point to your cloud release.
-
To import the box and experiment, run:
vagrant up
Notes
Version Numbers
Version numbers are generated incrementally using a combination of ubuntu release number + UTC date-time.
e.g: 2004.20200618.203713
Where:
2004
= the Ubuntu release 20.0420200618
= the 18th of June 2020203713
= 8 PM, 37 minutes, 13 seconds
Flexible Configuration
It is possible to re-use the templates without editing the provided templates directly. Many of the variables, in ubuntu.json, can be overridden on the command line or using a secondary json file.
Example Publishing to Specified Cloud Account
This example will build as is and publish to your pre configured Vagrant Cloud account ( you/myvm
):
VAGRANT_CLOUD_TOKEN={your_token} \
packer build \
-var 'vagrantcloud_username=you' \
-var 'vm_name=myvm' \
ubuntu.json
Example Building a Local Box for the US
This example will build a local box, in US configuration with a 50GB hdd, 2 cpus and 4gb of Ram.
packer build \
-except=vagrant-cloud \
-var 'keyboard_country=US' \
-var 'locale=en_US.UTF-8' \
-var 'cpus=2' \
-var 'disk_size=50000' \
-var 'memory=4096' \
ubuntu.json