イメージ作成のサポートツール

イメージ作成を自動化するために設計されたツールがいくつかあります。

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.

以下のスクリプトを実行し、イメージを構築します。

# disk-image-create ubuntu vm

この例は、最新リリースの Ubuntu の汎用的なブート可能なイメージを作成します。

環境変数を設定したり、コマンドラインでエレメントを追加で指定することで、さらにカスタマイズできます。

# 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 は、仮想マシンイメージファイルの作成手順を自動化するコマンドラインツールです。 Oz は 、KVM とやり取りを行う Python アプリケーションで、仮想マシンのインストール手順を順に行います。

サポートするオペレーティングシステム用の事前定義された kickstart (Red Hat 系システム)、preseed ファイル (Debian 系システム) を使用します。Microsoft Windows イメージを作成するためにも使用できます。

Oz の詳細は、このドキュメントの範囲を超えていますが、例を挙げておきます。GitHub の rcbops/oz-image-build/tree/master/templates にも Oz テンプレートの例があります。以下は、Oz を用いて CentOS 6.4 イメージを作成する方法です。

以下の内容で centos64.tdl という名前のテンプレートファイルを作成します。変更する必要がある項目は、<rootpw> の内容だけです。

<template>
  <name>centos64</name>
  <os>
    <name>CentOS-6</name>
    <version>4</version>
    <arch>x86_64</arch>
    <install type='iso'>
      <iso>http://mirror.rackspace.com/CentOS/6/isos/x86_64/CentOS-6.4-x86_64-bin-DVD1.iso</iso>
    </install>
    <rootpw>CHANGE THIS TO YOUR ROOT PASSWORD</rootpw>
  </os>
  <description>CentOS 6.4 x86_64</description>
  <repositories>
    <repository name='epel-6'>
      <url>http://download.fedoraproject.org/pub/epel/6/$basearch</url>
      <signed>no</signed>
    </repository>
  </repositories>
  <packages>
    <package name='epel-release'/>
    <package name='cloud-utils'/>
    <package name='cloud-init'/>
  </packages>
  <commands>
    <command name='update'>
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
    </command>
  </commands>
</template>

この Oz テンプレートでは、Centos 6.4 インストール ISO のダウンロード場所を指定します。Oz は、バージョン情報を使って、使用する kickstart ファイルを識別します。この場合は、RHEL6.auto になります。リポジトリーとして EPEL を追加し、このファイルの packages セクションに指定されている epel-releasecloud-utilscloud-init パッケージをインストールします。

kickstart ファイルを使用して OS の初期インストールを終えると、Oz はアップデートと行うとともにイメージをカスタマイズします。Oz は libvirt が作成する eth0 デバイスへの参照をすべて削除します。また、XML ファイルの command セクションの指定にもとづいてカスタマイズを行います。

以下を実行します。

# oz-install -d3 -u centos64.tdl -x centos64-libvirt.xml
  • -d3 フラグにより、Oz が実行中の状態を表示するように指定します。

  • -u により、初期インストール完了後に、Oz がカスタマイズ (追加パッケージのインストール、コマンドの実行) を行うように指定します。

  • -x フラグにより、Oz が libvirt XML ファイルを書き出すのに使用するファイル名を指定します (指定しない場合、デフォルトでは centos64Apr_03_2013-12:39:42 のようなファイル名になります)。

-u フラグを使用しない場合、またはファイルを編集して追加カスタマイズしたい場合、oz-install が作成した libvirt XML ファイルを用いて、oz-customize コマンドを実行できます。例:

# oz-customize -d3 centos64.tdl centos64-libvirt.xml

Oz は libvirt を呼び出して KVM 内でイメージを起動してから、Oz はインスタンスに SSH でログインし、カスタマイズを実行します。

VeeWee

VeeWee は、よく Vagrant ボックスを構築するのに使用されますが、KVM イメージを構築するためにも使用できます。

Packer

Packer は、単一の設定ファイルから複数のプラットフォーム向けのマシンイメージを作成するツールです。

image-bootstrap

image-bootstrap は、ブート可能な仮想マシンイメージを生成するコマンドラインツールです。 Arch、 Debian、 Gentoo、 Ubuntu に対応しており、 OpenStack で利用できるイメージを生成できます。

imagefactory

imagefactory は、さまざまなクラウドプロバイダー向けのイメージの構築、変換、アップロードを自動化するために設計された、比較的新しいツールです。バックエンドとして Oz を使用し、OpenStack ベースのクラウドに対応しています。

KIWI

KIWI OS image builder は、オペレーティングシステムイメージ作成ツールで、 Linux をサポートするハードウェアプラットフォーム向けのイメージや、仮想化システム、クラウドシステム向けのイメージを作成できます。 openSUSE、 SUSE Linux Enterprise、 Red Hat Enterprise Linux ベースのイメージ作成が可能です。 KIWI の使い方は openSUSE Documentation で説明されています

virt-builder

virt-builder は、新規の仮想マシンを素早く作成するためのツールです。ローカルやクラウドで使用するための様々な VM を、普通は数分で作成できます。virt-builder ではこれらの VM をカスタマイズする様々な方法が提供されています。すべてコマンドラインから実行でき、ルート権限が必要なものはないため、簡単に自動化やスクリプト化ができます。

以下のスクリプトを実行し、イメージを構築します。

# virt-builder fedora-23 -o image.qcow2 --format qcow2 \
  --update --selinux-relabel --size 20G

インストール可能なオペレーティングシステムの一覧を表示するには、以下のようにします。

$ virt-builder --list

作成したイメージを virsh で libvirt に取り込みます。

# 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:

# build-openstack-debian-image --release stretch

More parameters can be added to further customize the image:

# 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:

# #!/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:

# 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.