===============================
Tool support for image creation
===============================
There are several tools that are designed to automate image creation.
Diskimage-builder
~~~~~~~~~~~~~~~~~
`Diskimage-builder `_
is an automated disk image creation tool that supports a variety
of distributions and architectures.
Diskimage-builder (DIB) can build images for Fedora, Red Hat
Enterprise Linux, Ubuntu, Debian, CentOS, and openSUSE.
DIB is organized in a series of elements that build on top of
each other to create specific images.
To build an image, call the following script:
.. code-block:: console
# disk-image-create ubuntu vm
This example creates a generic, bootable Ubuntu image of the latest release.
Further customization could be accomplished by setting environment
variables or adding elements to the command-line:
.. code-block:: console
# disk-image-create -a armhf ubuntu vm
This example creates the image as before, but for arm architecture.
More elements are available in the `git source directory
`_
and documented in the `diskimage-builder elements documentation
`_.
Oz
~~
`Oz `_ is a command-line tool
that automates the process of creating a virtual machine image file.
Oz is a Python app that interacts with KVM to step through the process
of installing a virtual machine.
It uses a predefined set of kickstart (Red Hat-based systems) and
preseed files (Debian-based systems) for operating systems that it
supports, and it can also be used to create Microsoft Windows images.
A full treatment of Oz is beyond the scope of this document,
but we will provide an example. You can find additional examples of
Oz template files on GitHub at `rcbops/oz-image-build/tree/master/templates
`_.
Here's how you would create a CentOS 6.4 image with Oz.
Create a template file called ``centos64.tdl`` with
the following contents. The only entry you will need to
change is the ```` contents.
.. code-block:: xml
centos64
CentOS-6
4
x86_64
http://mirror.rackspace.com/CentOS/6/isos/x86_64/CentOS-6.4-x86_64-bin-DVD1.iso
CHANGE THIS TO YOUR ROOT PASSWORD
CentOS 6.4 x86_64
http://download.fedoraproject.org/pub/epel/6/$basearch
no
yum -y update
yum clean all
sed -i '/^HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0
echo -n > /etc/udev/rules.d/70-persistent-net.rules
echo -n > /lib/udev/rules.d/75-persistent-net-generator.rules
This Oz template specifies where to download the Centos 6.4 install ISO.
Oz will use the version information to identify which kickstart file to use.
In this case, it will be `RHEL6.auto
`_.
It adds EPEL as a repository and install the ``epel-release``,
``cloud-utils``, and ``cloud-init`` packages, as specified in the
``packages`` section of the file.
After Oz completes the initial OS install using the kickstart file,
it customizes the image with an update. It also removes any reference
to the eth0 device that libvirt creates while Oz does the customizing,
as specified in the ``command`` section of the XML file.
To run this:
.. code-block:: console
# oz-install -d3 -u centos64.tdl -x centos64-libvirt.xml
* The ``-d3`` flag tells Oz to show status information as it runs.
* The ``-u`` tells Oz to do the customization (install extra packages,
run the commands) once it does the initial install.
* The ``-x`` flag tells Oz what filename to use to write out
a libvirt XML file (otherwise it will default to something
like ``centos64Apr_03_2013-12:39:42``).
If you leave out the ``-u`` flag, or you want to edit the file
to do additional customizations, you can use the :command:`oz-customize`
command, using the libvirt XML file that :command:`oz-install` creates.
For example:
.. code-block:: console
# oz-customize -d3 centos64.tdl centos64-libvirt.xml
Oz will invoke libvirt to boot the image inside of KVM,
then Oz will ssh into the instance and perform the customizations.
VeeWee
~~~~~~
`VeeWee `_ is often used
to build `Vagrant `_ boxes,
but it can also be used to build the KVM images.
Packer
~~~~~~
`Packer `_ is a tool for creating machine
images for multiple platforms from a single source configuration.
image-bootstrap
~~~~~~~~~~~~~~~
`image-bootstrap `_
is a command line tool that generates bootable virtual machine images
with support of Arch, Debian, Gentoo, Ubuntu, and is prepared for use
with OpenStack.
imagefactory
~~~~~~~~~~~~
`imagefactory `_ is a newer tool designed
to automate the building, converting, and uploading images
to different cloud providers. It uses Oz as its back-end and
includes support for OpenStack-based clouds.
KIWI
~~~~
The `KIWI OS image builder `_
provides an operating system image builder for various Linux supported
hardware platforms as well as for virtualization and cloud systems. It
allows building of images based on openSUSE, SUSE Linux Enterprise,
and Red Hat Enterprise Linux. The `openSUSE Documentation
`_ explains how to use KIWI.
virt-builder
~~~~~~~~~~~~
`Virt-builder `_ is a tool for
quickly building new virtual machines. You can build a variety of VMs for
local or cloud use, usually within a few minutes or less. Virt-builder also
has many ways to customize these VMs. Everything is run from the command line
and nothing requires root privileges, so automation and scripting is simple.
To build an image, call the following script:
.. code-block:: console
# virt-builder fedora-23 -o image.qcow2 --format qcow2 \
--update --selinux-relabel --size 20G
To list the operating systems available to install:
.. code-block:: console
$ virt-builder --list
To import it into libvirt with :command:`virsh`:
.. code-block:: console
# virt-install --name fedora --ram 2048 \
--disk path=image.qcow2,format=qcow2 --import
openstack-debian-images
~~~~~~~~~~~~~~~~~~~~~~~
`openstack-debian-images `_
is the tool Debian uses to create its official OpenStack image. It is made of
a single very simple shell script that is easy to understand and modify.
It supports Grub and Syslinux, BIOS or EFI, amd64 and arm64 arch.
openstack-debian-images can also be used to create a bootable image directly
on a hard disk, instead of using the Debian installer.
To build an image, type this:
.. code-block:: console
# build-openstack-debian-image --release stretch
More parameters can be added to further customize the image:
.. code-block:: console
# build-openstack-debian-image --release stretch \
--hook-script /root/my-hook-script.sh \
--debootstrap-url http://ftp.fr.debian.org/debian \
--sources.list-mirror http://ftp.fr.debian.org/debian \
--login myusername \
--extra-packages vim,emacs
The file ``/root/my-hook-script.sh`` will recieve 2 environment variable:
``BODI_CHROOT_PATH`` path where the image is mounted, and ``BODI_RELEASE``
which is the name of the Debian release that is being bootstraped. Here's
an example for customizing the motd:
.. code-block:: console
# #!/bin/sh
set -e
echo "My message" >${BODI_CHROOT_PATH}/etc/motd
This hook script will conveniently be called at the correct moment of the
build process, when everything is installed, but before unmounting the
partition.
windows-openstack-imaging-tools
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`windows-openstack-imaging-tools
`_
is a PowerShell module that automates the Windows image creation for
OpenStack and supports building VHDX, QCOW2, RAW and VMDK image types.
For easier installation, the tool is published as a PowerShellGallery module
`WindowsImageBuilder
`_.
Windows image build example:
.. code-block:: powershell
# Install and import WindowsImageBuilder module from PowerShellGallery
Install-Module WindowsImageBuilder -Force
Import-Module WindowsImageBuilder
New-WindowsImageConfig -ConfigFilePath ".\windows-image-config.ini"
# Update the configuration file to fit your specific use case
# Extensive information for all the configuration can be found here:
# https://github.com/cloudbase/windows-openstack-imaging-tools/blob/master/Config.psm1#L21
# Generate the Windows image
New-WindowsOnlineImage -ConfigFilePath ".\windows-image-config.ini"
Requirements:
* A Windows host, with Hyper-V virtualization enabled, PowerShell >=v4
support and Windows Assessment and Deployment Kit (ADK).
* A Windows installation ISO or DVD.
* Windows compatible drivers, if required by the target environment.
For example, `VirtIO
`_,
network card, or storage adapter drivers.
* Git environment.