From f107309c4867a6d762409ee3f47689b01fc379af Mon Sep 17 00:00:00 2001 From: Brian Candler Date: Sat, 14 May 2016 11:03:52 +0000 Subject: [PATCH] Add qcow2 extension. Disk and RAM options --- README.md | 24 ++++++++++++++++++++++-- vtp.json | 10 +++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index aa1b32d..31ec8fa 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,27 @@ You get more information if you run: PACKER_LOG=1 ./packer build foo.json ~~~ -## Ubuntu ISO installation +## Disk usage + +After an initial build of just the OS, the qcow2 file was around 2GB. +Examining the image showed that only 1.2GB was used for the root filesystem; +there may be temporary files which were deleted, or there may be data in the +swap space. + +The default install used 512MB of RAM and created 512MB of swap. This can be +increased with e.g. `"qemuargs": [ [ "-m", "768M" ] ]` + +TODO: minimise the image size by running zerofree on all filesystems (this +cannot be done while root is mounted read-write), and wiping the swap space. + +Normally packer runs a qemu-img convert pass to remove empty space in the image. +This can be disabled by `"skip_compaction": true`: this speeds up the build a +bit, but increases the qcow2 file size from 2GB to 2.8GB + +Adding `"disk_compression": true` reduces the size of the qcow2 image to +about 800MB, at the cost of slowing down the build. + +# 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) @@ -132,7 +152,7 @@ and to have compression on the root. QCOW2 images can be loopback-mounted with a bit of help from nbd: modprobe nbd - qemu-nbd -c /dev/nbd0 /path/to/image.qcow2 + qemu-nbd -c /dev/nbd0 output-qemu/vtp.qcow2 mount /dev/nbd0p1 /mnt ... umount /mnt diff --git a/vtp.json b/vtp.json index c969fe2..f8214d2 100644 --- a/vtp.json +++ b/vtp.json @@ -1,16 +1,24 @@ { + "_comment": "Based on https://github.com/puppetlabs/puppetlabs-packer/blob/master/templates/ubuntu-16.04/x86_64.vmware.base.json", + "variables": { "headless": "false" }, + "builders": [ { "type": "qemu", "format": "qcow2", "accelerator": "kvm", + "qemuargs": [ + [ "-m", "512M" ] + ], "net_device": "virtio-net", "disk_interface": "virtio", - "vm_name": "vtp", + "vm_name": "vtp.qcow2", + "skip_compaction": false, + "disk_compression": false, "floppy_files": [ "preseed.cfg" ], "boot_command": [ "", -- GitLab