Tools to automate image creation

İmaj oluşturmayı otomatikleştirmek için çeşitli araçlar tasarlanmıştır.

OpenStack tools

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.

Bir imaj inşa etmek için, aşağıdaki betikleri çağırın:

# disk-image-create ubuntu vm

Bu örnek genel, ön yüklenebilir bir son sürüm Ubuntu imajı oluşturur.

Daha ince özelleştirme ortam değişkenleri ayarlayarak veya komut satırı elemanları ekleyerek yapılabilir:

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

External tools

image-bootstrap

image-bootstrap is a command line tool that generates bootable virtual machine images with support for Arch, Debian, Gentoo and Ubuntu, and is prepared for use with OpenStack.

KIWI

The KIWI appliance 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 KIWI NG Documentation explains how to use it.

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.

Oz

Oz sanal makine imaj dosyası oluşturmak sürecini otomatikleştiren bir komut satırı aracıdır. Oz bir sanal makine kurulumu sürecinden adım adım geçmek için KVM ile etkileşime geçen bir Python uygulamasıdır.

Destekleyen işletim sistemlerinde öntanımlı bir kickstart (Red Hat tabanlı sistemler) ve preseed dosyaları (Debian tabanlı sistemler) kümesini kullanır, ayrca Microsoft Windows imajları oluşturmak için de kullanılabilir.

Oz’u tamamen anlatmak bu belgenin kapsamı dışındadır, ama bir örnek vereceğiz. Github rcbops/oz-image-build/tree/master/templates adresinde örnek ek Oz şablonları bulabilirsiniz.

centos64.tdl isimli ve aşağıdaki içeriğe sahip bir şablon dosya oluşturun. Değiştirmeniz gereken tek girdi <rootpw> içeriğidir.

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

Bu Oz şablonu Centos 6.4 kurulum ISO’sunun nereye indirileceğini belirtir. Oz sürüm bilgisini kullanarak hangi kickstart dosyasını kullanacağını tanımlar. Bu durumda, RHEL6.auto. EPEL’i bir depo olarak ekler ve epel-release, cloud-utils, ve cloud-init paketlerini, dosyanın packages kısmında belirtildiği gibi kurar.

Oz kickstart dosyasını kullanarak ilk OS kurulumunu bitirdikten sonra, imajı bir güncellemeyle özelleştirir. Ayrıca Oz özelleştirme yaparken libvirt’in oluşturduğu eth0 aygıtına başvuruları da XML dosyasının command kısmında belirtildiği gibi kaldırır.

Bunu çalıştırmak için:

# oz-install -d3 -u centos64.tdl -x centos64-libvirt.xml
  • -d3 bayrağı Oz’a çalışırken durum bilgisi göstermesini söyler.

  • -u Oz’a ilk kurulumu bitirdikten sonra özelleştirmeyi yapmasını söyler (ek paketleri yüklemek, komutları çalıştırmak).

  • -x bayrağı Oz’a libvirt XML dosyası yazmak için hangi dosya ismini kullanması gerektiğini söyler (aksi halde öntanımlı bir dosya olacaktır, örneğin centos64Apr_03_2013-12:39:42).

-u bayrağını kullanmazsanız, veya dosyayı düzenleyerek ek özelleştirmeler yapmak isterseniz, oz-install komutunun oluşturduğu libvirt XML dosyasını kullanarak oz-customize komutunu kullanabilirsiniz. Örneğin:

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

Oz libvirt’i imajı KVM içinde ön yükleyecek şekilde başlatır, ardından Oz sunucuya ssh çekerek özelleştirmeleri gerçekleştirir.

Packer

Packer tek bir kaynak yapılandırmadan birden çok platform için makine imajları oluşturmak için bir araçtır.

virt-builder

Virt-builder hızlıca yeni sanal makineler inşa etmek için bir araçtır. Yerel veya bulut kullanımı amacıyla çeşitli sanal makineler inşa edebilirsiniz, genellikle yalnızca dakikalar alır. Virt-builder ayrıca bu sanal makineleri özelleştirmek için bir çok yol sunar. Her şey komut satırından çalıştırılır ve hiçbir şey root yetkisi istemez, yani otomasyon ve betikleme basittir.

Bir imaj inşa etmek için, aşağıdaki betikleri çağırın:

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

Kurulabilir işletim sistemlerini listelemek için:

$ virt-builder --list

virsh ile libvirt’e aktarmak için:

# virt-install --name fedora --ram 2048 \
  --disk path=image.qcow2,format=qcow2 --import

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.