Community

Discussions  |  Feature Requests  |  Tips and Tricks

Guidelines for building Nimbula Director machine images

#1March 8, 2011 08:05:14

Quinton Hoole
Registered: 2010-08-23
Posts: 1

Guidelines for building Nimbula Director machine images

Format

The image itself is a full disk image, i.e. including a partition table and installed bootloader. It is stored in a tar archive with support for sparse filesystems and compressed with gzip.


Size

The image should be as small as possible since it will be copied around and extracted numerous times. It should therefore only contain what is actually needed in order to perform its task. Unless it will be used as a desktop system, it should not contain a graphical environment (GNOME, KDE, Xfce, Xorg) or any other extraneous system and application files. Maintaining a small image will significantly decrease the time to launch instances. Most Linux distributions have a server/CLI/minimal disk or installation option. The other approach is to use debootstrap (see http://wiki.debian.org/Debootstrap) or rinse (see http://xen-tools.org/software/rinse/) to create the system.


Access

The image must provide an access mechanism if access is desired. This means that an SSH server should probably be installed and user accounts and passwords or keys configured.


Virtio drivers

Virtualization performance can be improved if virtio devices can be used. This requires that the image contain drivers for virtio disk and network devices. Most modern Linux distributions already support virtio.


Virtio drivers required for Windows guests

Virtio drivers need to be installed on all Nimbula Director Windows guest images to enable access to the virtual hardware.


Device Names

Device names for disks may differ depending on whether virtio drivers are enabled or not. All references to filesystems should therefore use UUIDs instead of device names (bootloader, kernel, /etc/fstab).


Bundling Tools

The Nimbula Director Bundling Tools, available as part of the CLI, automate the actual bundling process and can also install the kernel and bootloader and enable serial console access. The input to the bundling tools is either an unpacked root filesystem, or a filesystem image.


Bundling Amazon EC2 AMIs for Nimbula Director

An Amazon EC2 AMI can be bundled for Nimbula Director by first downloading and unbundling it using Amazon's AMI tools, and then bundling the resulting filesystem image.


Use the following commands to download, unbundle and rebundle an Amazon EC2 AMI for Nimbula Director:


$ec2-download-bundle -a <access key> -s <secret key> -k <path to private key>
-b <bucket> -p <image prefix>

$ ec2-unbundle -k <path to private key> -m <path to manifest>

$ nimbula-bundle -p <output prefix> <path to image>



Example commands:



$ec2-download-bundle -a DTDIUK0HAFZOPDGVHUN9 -s s6b421nAnM7YUCyupulDSrAxEFSFMipNkvoukrD0 
-k ~/ec2/pk-PDJDUN14JA8WGPYBUD0KF8DQBUDF9GDC.pem 
-b nimbula-amis -p webserver01

$ec2-unbundle -k ~/ec2/pk-PDJDUN14JA8WGPYBUD0KF8DQBUDF9GDC.pem -m webserver01.manifest.xml

$nimbula-bundle -p webserver01 webserver01



For instructions on how to upload a machine image into the Nimbula Director system once it has been prepared, consult the Using Nimbula Director → Step 2b Adding a Machine Image section of the Nimbula Director User Guide.


Building Nimbula Director machine images from scratch

The steps below describe how you can create and bundle machine images to be uploaded to Nimbula Director via the web based console, CLI or HTTP API.


Initial machine images created outside the Nimbula Director environment

Initial machine images created for upload to a fresh Nimbula Director installation will need to be created from a physical or virtual installation outside the Nimbula Director environment


Step 1: Install the qemu-kvm package

On any Linux host, install the qemu-kvm package using your favourite package management mechanism (aptitude, yum, etc) or simply download and install the RPM file for – qemu-kvm.


Step 2: Create a virtual disk image

Create a virtual disk image using the following commands:


$ mkdir ~/images

$ cd ~/images

$ dd if=/dev/zero of=ubuntu.img bs=1M count=0 seek=6000



Step 3: Fire up a virtual machine

Fire up a virtual machine on the local host using the following command:



$ sudo kvm -m 512 -hda ubuntu.img -cdrom your-cd-converted-to-iso.iso -boot order=d


This will present and walk you through the operating system install.


Step 4: Customize your image

When the virtual machine reboots, you will be able to log in and add the various applications you want onto your image and edit the configuration files needed to customize the image to your preferred setup. Remember, this will become the initial boot state of all your instances in the cluster, so be sure to check that all the applications launch as needed after reboot.


Step 5: Tidy up the virtual machine

Once you have a clean, ready-to-freeze image, tidy up the virtual machine.

For Linux, you can run the following commands to clear the command line history and shut down the virtual machine.



$ > ~/.bash_history
$ sudo rm /etc/udev/rules.d/70-persistent-net.rules
$ sudo init 0


For Windows, simply shut down using the standard methods.


Step 6: Package

You now need to convert your machine image into a Nimbula Director bootable machine image using the tar command.

Return to the gateway machine and still in ~/images use the following command to package your image.


$ tar -Szcf ubuntu.tar.gz ubuntu.img


This command will take a while to complete, but the resultant ubuntu.tar.gz will be ready to be added to the cluster using the nimbula-api add machineimage command.


The machine image you have just created must now be added to Nimbula Director as a machine image and added to an image list, before it can be used to launch a VM.


Building Nimbula Director machine images from a root filesystem or partition image


The Nimbula Director bundling tools take a directory containing a root filesystem OR partition image as a parameter as shown in the following examples:


$ nimbula-bundle --root 5120 --swap 1024 --prefix webserver01 /

$ nimbula-bundle --root 5120 --swap 1024 --prefix webserver01 /mnt/mountedimage

$ nimbula-bundle --root 5120 --swap 1024 --prefix webserver01 ~/partition.img



Where the --root parameter specifies the size of the root filesystem in MiB, the –-swap parameter specifies the size of the swap partition in MiB and the –-prefix parameter specifies the filename prefix of the output image.


The machine image you have just created must now be added to Nimbula Director as a machine image and added to an image list, before it can be used to launch a VM.

Edited jeremy (Feb. 10, 2012 12:51:28)

 

#2April 19, 2011 19:09:22

Scott Damron
Registered: 2011-03-04
Posts: 3

Guidelines for building Nimbula Director machine images

This doesn't work so well. I omitted the -boot order=d and it worked.

Edited jacqui (April 22, 2011 01:35:14)

 

#3April 22, 2011 01:53:18

Jacqui Latimer
Registered: 2010-09-13
Posts: 13

Guidelines for building Nimbula Director machine images

HI Scott

Thanks for this observation. You are possibly using a version of KVM that does not support the order option. -boot d should work on all versions and makes it boot from CD.

Jacqui

Edited jacqui (April 22, 2011 01:53:40)