Packer templates for OpenSLX
Packer-based generation of reference systems using distro's ISOs.
Dependencies
Packer => 0.12.2
Download: https://www.packer.io/downloads.html
Usage
The file 'base.json' contains default variables (VM, SSH) common to all templates,
and must always be included using packer's '-var-file' option.
The root password is expected to be in the ROOTPW environment variable.
The installation procedure will fail without it!
Basic usage:
ROOTPW=<password> packer build -var-file=base.json <template>
For the rest of the examples, ROOTPW is assumed to be set in the environment.
Usage: Creating base images
Example - Build Ubuntu 16.04.2 LTS template using qemu builder
packer build -var-file=base.json -only=qemu ubuntu-16.04-amd64.json
Debug:
PACKER_LOG=1 PACKER_LOG_FILE=/var/log/packer.log \
packer build -debug -only=qemu -var-file=base.json ubuntu-16.04-amd64.json
A successful build process would produce a disk image under:
/, e.g. qemu/centos-7.3-x86_64
Additionally, the manifest post-processor creates a manifest.json file in
the working directory containing various information about the generated
artifact, in particular the path to the disk file.
Usage: Provisioning base images
The packer templates provided by the main repository only create very basic
disk images. These are meant to be very minimal installations only. Further
customizations on the base images should be done separately by a provisioner.
Only the software needed for the provisioners to work should be directly
installed and configured during the packer build process. Since we focus on
ansible, only a SSH server and the ansible packages are currently installed.
The ansible-roles
repository provides ansible roles and a sample playbook, to build the stage3
initramfs using systemd-init.
Refer to those repos for more information. The simpliest way to initialize
the submodule is by cloning this repository with '--recursive'.
Build initramfs inside a previously created image:
packer build -var-file=base.json \
-var='image_path='"$(jq -r '.builds[0].files[0].name' < manifest.json)"'' \
ansible-roles/run-playbook-only.json
(This expects 'manifest.json' to contain only one packer artifact.)
The path to the existing image is extracted using the jq tool and given as
'image_path' to the packer provisioning template run-playbook-only.json.
A successful build would provide the stage3 initramfs and the VM's kernel
in the ansible-roles/boot_files/ directory. Refer to systemd-init for more
information on how to setup a boot environment.
The packer artifact is created in 'output-'. This artifact
contains all the development packages needed to build the initramfs, which
can be discarded. Instead, the base image can be used as the main boot image.
Makefile
A simple Makefile to build packer templates is provided for convenience.
See a list of targets with make list
.
Example - Build CentOS 7.3 with qemu:
make qemu/centos-7.3-x86_64
Notes
Variables set in base.json can be overriden using packer's '-var' options, e.g.:
packer build -var-file=base.json -var='headless=true' <template>
Make sure you first include base.json before overriding a variable!
The partitioning of the virtual disk is done via kickstart/preseed files. Currently,
a simple partition scheme is used: separate boot partition, rest a the main system
partition labeled as SLX_SYS, using ext4 as filesystem. Other filesystems are also
supported, tested were currently xfs and btrfs. If you change the filesystem to use
you need to adapt your boot configuration file (SLX_MOUNT_ROOT_OPTIONS).
While the qemu builder produces a qcow2 image, it can be further compressed using:
virt-sparsify --compress <qcow2_file> <output_qcow2_file>
TL;DR
0) git clone --recursive git://git.openslx.org/openslx-ng/packer-templates
or if already cloned
0) git submodule init && git submodule update
1) Build base:
packer build -var-file=base.json -only=qemu ubuntu-16.04-amd64.json
2) Build initramfs:
packer build -var-file=base.json -only=qemu -var='image_path='"$(jq -r '.builds[0].files[0].name' < manifest.json)"'' ansible-roles/run-playbook-only.json
Produces:
- kernel & initramfs in ansible-roles/boot_files/
- main qcow2 image under output-ubuntu.../packer-ubuntu-amd64
To boot:
- qocw2 image -> dnbd3 server
- kernel, initramfs and config pointing to the above image on http server