Skip to content
README.md 3.86 KiB
Newer Older
# TL;DR

~~~
# download packer_x.x.x_linux_amd64.zip from https://www.packer.io/downloads.html
unzip packer_x.x.x_linux_amd64.zip
./packer build -only=qemu vtp.json
~~~

# Overview

The VTP virtual machine is built using a scripted install process. This
results in an image which can be distributed to trainers and either run on
their local hardware or in a third-party cloud.

~~~~~~~~~~~~~~~~~~~~~~~~~~~
            |
            v
       Build Ubuntu
       16.04+ZFS image
            |
            v
          Local
       configuration
       (bridges, DNS,
        dynamips etc)
            |
            v
       Pull in LXD
       master image
            |
            v
     Make master clones
            |
            v
    Customise masters
   |        |        |
   v        v        v
 Nagios Smokeping  etc...
   |        |        |
   v        v        v
 Clones   Clones   Clones
       \    |    /
        v   v   v
    Bootable raw image
            |
            v
      Convert to:
        qcow2
        vmdk [vdi]
        ami [gce]
~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Packer

The build-from-ISO process is driven by [packer](https://www.packer.io/)

[Download](https://www.packer.io/downloads.html) the binary into the top
level of this repo and unzip it. Then run using:

~~~
./packer build [-only=qemu] vtp.json
~~~

(`-only=qemu` is if there are multiple [builders](https://www.packer.io/docs/templates/builders.html)
defined and you only want to run one. For example, in future we could include
configs for building images on EC2 and GCE)

The configuration consists of a json file which controls packer, and a
preseed file which controls the ubuntu installer. The files here are
derived from:

* The puppetlabs [ubuntu 16.04 templates](https://github.com/puppetlabs/puppetlabs-packer/tree/master/templates/ubuntu-16.04), in particular the vmware-iso one
* The packer [qemu builder](https://www.packer.io/docs/builders/qemu.html) example config
* The ubuntu [example preseed](https://help.ubuntu.com/lts/installation-guide/example-preseed.txt) file

## Viewing progress at the console

If you have an X11 environment (either you are working at a graphical console, or
you use ssh -X to enable X11 forwarding) then you can set `"headless": false` in the
JSON file. This will make qemu pop up a console window as it runs.

Otherwise, watch the output and look for this message:

~~~
==> qemu: Found available VNC port: 5915
~~~

(the number is dynamic), and then from a laptop run

~~~
vncviewer -Shared <hostname>:<display>
~~~

e.g. `vncviewer -Shared 10.10.0.241:15`.

## Debugging

If things go wrong with packer, see the [debugging guide](https://www.packer.io/docs/other/debugging.html)
You get more information if you run:

~~~
PACKER_LOG=1 ./packer build foo.json
~~~

## Ubuntu ISO installation

For an [automated Ubuntu install](https://help.ubuntu.com/lts/installation-guide/amd64/ch04s06.html)
there are two options: [preseeding](https://help.ubuntu.com/lts/installation-guide/amd64/apb.html)
or [kickstart](https://help.ubuntu.com/community/KickstartCompatibility)

The kickstart files are simpler and can be created using
[system-config-kickstart](http://packages.ubuntu.com/xenial/system-config-kickstart)
on an Ubuntu 16.04 desktop machine. However the Ubuntu kickstart implementation offers
only a subset of features and is really just a frontend to selected preseed variables.

Installing Ubuntu with zfs root filesystem is not yet supported by the installer:
[1](https://github.com/zfsonlinux/pkg-zfs/wiki/HOWTO-install-Ubuntu-16.04-to-a-Native-ZFS-Root-Filesystem)
[2](https://github.com/zfsonlinux/zfs/wiki/Ubuntu-16.04-Root-on-ZFS)
[3](http://dotfiles.tnetconsulting.net/articles/2016/0327/ubuntu-zfs-native-root.html)

For our purposes it's sufficient to have an ext4 root filesystem and create
a separate ZFS partition for LXD.  We lose the ability to snapshot the root
and to have compression on the root.