CSS Corp Open Source Services

[OpenStack Beginner’s Guide for Ubuntu 11.04] – Image Management

with 17 comments

Image management

There are several pre-built images for OpenStack available from  various sources. You can download such images and use them to get familiar with OpenStack. You can refer to  http://docs.openstack.org/cactus/openstack-compute/admin/content/starting-images.html for details on using such images.

For any production deployment,  you may like to have the ability to bundle custom images, with a custom set of applications or configuration. This chapter will guide you through the process of creating Linux images of Debian and Redhat based distributions from scratch. We have also covered an approach to bundling Windows images.

There are some minor differences in the way you would bundle a Linux image, based on the distribution. Ubuntu makes it very easy by providing cloud-init package, which can be used to take care of the instance configuration at the time of launch. cloud-init handles importing ssh keys for password-less login, setting hostname etc. The instance acquires the instance specific configuration from Nova-compute by connecting to a meta data interface running on

While creating the image of a distro that does not have cloud-init or an equivalent package, you may need to take care of importing the keys etc. by running a set of commands at boot time from rc.local.

The process used for Ubuntu and Fedora is largely the same with a few minor differences, which are explained below.

In both cases, the documentation below assumes that you have a working KVM installation to use for creating the images. We are using the machine called ‘client1’ as explained in the chapter on “Installation and Configuration” for this purpose.

The approach explained below will give you disk images that represent a disk without any partitions. Nova-compute can resize such disks ( including resizing the file system) based on the instance type chosen at the time of launching the instance. These images cannot have ‘bootable’ flag and hence it is mandatory to have associated kernel and ramdisk images. These kernel and ramdisk images need to be used by nova-compute at the time of launching the instance.

However, we have also added a small section towards the end of the chapter about creating bootable images with multiple partitions that can be be used by nova to launch an instance without the need for  kernel and ramdisk images. The caveat is that while nova-compute can re-size such disks at the time of launching the instance, the file system size is not altered and hence, for all practical purposes, such disks are not re-sizable.

Creating a Linux Image – Ubuntu & Fedora

The first step would be to create a raw image on Client1. This will represent the main HDD of the virtual machine, so make sure to give it as much space as you will need.

kvm-img create -f raw server.img 5G

OS Installation

Download the iso file of the Linux distribution you want installed in the image. The instructions below are tested on Ubuntu 11.04 Natty Narwhal 64-bit server and Fedora 14 64-bit. Most of the instructions refer to Ubuntu. The points of difference between Ubuntu and Fedora are mentioned wherever required.

wget http://releases.ubuntu.com/natty/ubuntu-11.04-server-amd64.iso

Boot a KVM Instance with the OS installer ISO in the virtual CD-ROM. This will start the installation process. The command below also sets up a VNC display at port 0

sudo kvm -m 256 -cdrom ubuntu-11.04-server-amd64.iso -drive   file=server.img,if=scsi,index=0 -boot d -net nic -net user -nographic  -vnc :0

Connect to the VM through VNC (use display number :0) and finish the installation.

For Example,  where is the IP address of client1:

 vncviewer :0

During the installation of Ubuntu, create a single ext4 partition mounted on ‘/’. Do not create a swap partition.

In the case of Fedora 14, the installation will not progress unless you create a swap partition. Please go ahead and create a swap partition.

After finishing the installation, relaunch the VM by executing the following command.

sudo kvm -m 256 -drive file=server.img,if=scsi,index=0,boot=on -boot c -net nic -net user -nographic -vnc :0

At this point, you can add all the packages you want to have installed, update the installation, add users and make any configuration changes you want in your image.

At the minimum, for Ubuntu you may run the following commands

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install openssh-server cloud-init

For Fedora run the following commands as root

yum update

yum install openssh-server

chkconfig sshd on

Also remove the network persistence rules from /etc/udev/rules.d as their presence will result in the network interface in the instance coming up as an interface other than eth0.

sudo rm -rf /etc/udev/rules.d/70-persistent-net.rules

Shutdown the Virtual machine and proceed with the next steps.

Extracting the EXT4 partition

The image that needs to be uploaded to OpenStack needs to be an ext4 filesystem image. Here are the steps to create a ext4 filesystem image from the raw image i.e server.img

sudo losetup  -f  server.img

sudo losetup -a

You should see an output like this:

/dev/loop0: [0801]:16908388 ($filepath)

Observe the name of the loop device ( /dev/loop0 in our setup) when $filepath is the path to the mounted .raw file.

Now we need to find out the starting sector of the partition. Run:

sudo fdisk -cul /dev/loop0

You should see an output like this:

Disk /dev/loop0: 5368 MB, 5368709120 bytes

149 heads, 8 sectors/track, 8796 cylinders, total 10485760 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00072bd4

Device Boot      Start         End      Blocks   Id  System

/dev/loop0p1   *        2048    10483711     5240832   83  Linux

Make a note of the starting sector of the /dev/loop0p1 partition i.e the partition whose ID is 83. This number should be multiplied by 512 to obtain the correct value. In this case: 2048 x 512 = 1048576

Unmount the loop0 device:

sudo losetup -d /dev/loop0

Now mount only the partition(/dev/loop0p1) of server.img which we had previously noted down, by adding the -o parameter with value previously calculated value

sudo losetup -f -o 1048576 server.img

sudo losetup -a

You’ll see a message like this:

/dev/loop0: [0801]:16908388 ($filepath) offset 1048576

Make a note of the mount point of our device(/dev/loop0 in our setup) when $filepath is the path to the mounted .raw file.

Copy the entire partition to a new .raw file

sudo dd if=/dev/loop0 of=serverfinal.img

Now we have our ext4 filesystem image i.e serverfinal.img

Unmount the loop0 device

sudo losetup -d /dev/loop0

Tweaking /etc/fstab

You will need to tweak /etc/fstab to make it suitable for a cloud instance. Nova-compute may resize the disk at the time of launch of instances based on the instance type chosen. This can make the UUID of the disk invalid. Hence we have to use File system label as the identifier for the partition instead of the UUID.

Loop mount the serverfinal.img, by running

sudo mount -o loop serverfinal.img /mnt

Edit /mnt/etc/fstab and modify the line for mounting root partition(which may look like the following)

UUID=e7f5af8d-5d96-45cc-a0fc-d0d1bde8f31c  /               ext4    errors=remount-ro  0       1


LABEL=uec-rootfs              /          ext4           defaults     0    0

Fetching Metadata in Fedora

Since, Fedora does not ship with cloud-init or an equivalent, you will need to take a few steps to have the instance  fetch the meta data like ssh keys etc.

Edit the /etc/rc.local file and add the following lines before the line “touch /var/lock/subsys/local”

depmod -a
modprobe acpiphp

# simple attempt to get the user ssh key using the meta-data service
mkdir -p /root/.ssh
echo >> /root/.ssh/authorized_keys
curl -m 10 -s | grep 'ssh-rsa' >> /root/.ssh/authorized_keys
echo "************************"
cat /root/.ssh/authorized_keys
echo "************************"

Kernel and Initrd for OpenStack

Copy the kernel and the initrd image from /mnt/boot to user home directory. These will be used later for creating and uploading a complete virtual image to OpenStack.

sudo cp /mnt/boot/vmlinuz-2.6.38-7-server /home/localadmin

sudo cp /mnt/boot/initrd.img-2.6.38-7-server /home/localadmin

Unmount the Loop partition

sudo umount  /mnt

Change the filesystem label of serverfinal.img to ‘uec-rootfs’

sudo tune2fs -L uec-rootfs serverfinal.img

Now, we have all the components of the image ready to be uploaded to OpenStack imaging server.

Registering with OpenStack

The last step would be to upload the images to Openstack Imaging Server glance. The files that need to be uploaded for the above sample setup of Ubuntu are: vmlinuz-2.6.38-7-server, initrd.img-2.6.38-7-server, serverfinal.img

Run the following command

uec-publish-image -t image --kernel-file vmlinuz-2.6.38-7-server --ramdisk-file initrd.img-2.6.38-7-server amd64 serverfinal.img bucket1

For Fedora, the process will be similar. Make sure that you use the right kernel and initrd files extracted above.

uec-publish-image, like  several other commands from euca2ools, returns the prompt back immediately. However,  the upload process takes some time and the images will be usable only after the process is complete. You can keep checking the status using the command ‘euca-describe-images’ as mentioned below.

Bootable Images

You can register bootable disk images without associating kernel and ramdisk images. When you do not want the flexibility of using the same disk image with different kernel/ramdisk images, you can go for bootable disk images. This greatly simplifies the process of bundling and registering the images. However, the caveats mentioned in the introduction to this chapter apply.  Please note that the instructions below use server.img and you can skip all the cumbersome steps related to extracting the single ext4 partition.

euca-bundle-image -i server.img
euca-upload-bundle -b mybucket -m /tmp/server.img.manifest.xml
euca-register mybucket/server.img.manifest.xml

Image Listing

The status of the images that have been uploaded can be viewed by using euca-describe-images command. The output should like this:

localadmin@client1:~$ euca-describe-images

IMAGE   ari-7bfac859    bucket1/initrd.img-2.6.38-7-server.manifest.xml  css     available           private         x86_64       ramdisk

IMAGE   ami-5e17eb9d    bucket1/serverfinal.img.manifest.xml       css     available               private         x86_64  machine      aki-3d0aeb08    ari-7bfac859

IMAGE   aki-3d0aeb08    bucket1/vmlinuz-2.6.38-7-server.manifest.xml     css     available           private         x86_64       kernel


Creating a Windows Image

The first step would be to create a raw image on Client1, this will represent the main HDD of the virtual machine, so make sure to give it as much space as you will need.

kvm-img create -f raw windowsserver.img 20G

OpenStack presents the disk using aVIRTIO interface while launching the instance. Hence the OS needs to have drivers for VIRTIO. By default, the Windows Server 2008 ISO does not have the drivers for VIRTIO. Sso download a virtual floppy drive containing VIRTIO drivers from the following location


and attach it during the installation

Start the installation by running

sudo kvm -m 1024 -cdrom win2k8_dvd.iso -drive file=windowsserver.img,if=virtio,boot=on -fda virtio-win-1.1.16.vfd -boot d -nographic -vnc :0

When the installation prompts you to choose  a hard disk device you won’t see any devices available. Click on “Load drivers” at the bottom left and load the drivers from A:\i386\Win2008

After the Installation is over, boot into it once and install any additional applications you need to install and make any configuration changes you need to make.  Also ensure that RDP is enabled as that would be the only way you can connect to a running instance of Windows. Windows firewall needs to be configured to allow incoming ICMP and RDP connections.

For OpenStack to allow incoming RDP Connections, use euca-authorize command to open up port 3389 as described in the chapter  on “Security”.

Shut-down the VM and upload the image to OpenStack

euca-bundle-image -i windowsserver.img
euca-upload-bundle -b mybucket -m /tmp/windowsserver.img.manifest.xml
euca-register mybucket/windowsserver.img.manifest.xml

17 Responses

Subscribe to comments with RSS.

  1. Thanks! this made my day !
    Excelent posting!


    May 26, 2011 at 3:51 am

  2. I can run win2008 instance, but I can not ping it’s ip successful


    May 27, 2011 at 9:16 am

  3. Hi,
    the “Bootable Images” doesn’t seem to work in a VLAN mode.
    While the image successfully register, and the instance seen as “running”, euca-get-console-output returns nothing, and the instance is unreacheable.

    To me it seems to be related to the fact that you don’t bundle the ari and aki with the image.


    June 15, 2011 at 2:08 pm

    • Hi Razique,

      The ‘Bootable Images’ topic is a hack to skip the steps related to extracting the ext4 partition. If you want an image that is similar to OpenStack pre-bulit images and one which works fine in different networking modes, please read all the topics mentioned above ‘Bootable Images’.


      July 4, 2011 at 4:15 pm

      • Hi, It’s finally working, I suspect the image-registering process went fubar due to and out-of-disk-space issue.
        Actually, I hadn’t sufficient space on the cloud-controller for the euca-register (which takes twice the size of the image, so I ended with a corrupted image)
        Thanks a lot for that great guide.


        September 12, 2011 at 9:48 pm

  4. I got to step “Tweaking /etc/fstab” and mounted serverfinal.img to /mnt, but I could not find /etc/fstab there.

    Some files/folders in the /mnt:


    How can I edit /mnt/etc/fstab ?

    BTW, thank you very much for the post

    Nhân Trần

    July 11, 2011 at 8:35 pm

    • Please ignore my previous comment. I have got the issue because I did not follow strictly the instruction:

      “During the installation of Ubuntu, create a single ext4 partition mounted on ‘/’. Do not create a swap partition.”


      Nhân Trần

      July 11, 2011 at 10:59 pm

  5. I am trying this command based on your guidelines:
    uec-publish-image -t image –kernel-file vmlinuz-2.6.38-8-server –ramdisk-file initrd.img-2.6.38-8-server amd64 ubuntu-114-svr-final.img bucket1

    I get back:
    failed to check for existing manifest
    failed to register vmlinuz-2.6.38-8-server

    All previous steps work fine. I also tried the Bootable Image option which did work.


    August 16, 2011 at 11:43 pm

    • Did you find any solution to this?

      I have the same problem!


      September 19, 2011 at 5:42 pm

    • It worked for using root account.


      February 1, 2012 at 6:19 am

  6. I’m trying to execute following command.
    sudo uec-publish-image -v -t image –kernel-file vmlinuz-2.6.38-8-server x86_64 serverfinal.img bucket1
    but I am getting the error like:
    failed to check for existing manifest
    failed to register vmlinuz-2.6.38-8-server

    Any Suggestion Please. I executed all the steps on client1.


    September 20, 2011 at 7:24 pm

  7. Hi. I was faced with the same error message and did this to resolve.

    source /home/localadmin/creds/novarc


    October 4, 2011 at 9:45 am

  8. I got the same error as above “failed to check for existing manifest”


    October 20, 2011 at 2:06 am

Leave a Reply to Nhân Trần Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: