CSS Corp Open Source Services

Bundling CentOS image for OpenStack

with 4 comments

This article explains how to create a CentOS 6 image on KVM for uploading it to the image store on OpenStack Diablo.  I have used KVM running on Ubuntu 11.10 64-bit server for creation of the image.

The first step would be to create a qcow2 image. 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 qcow2 centos.img 5G

Start the Virtual Machine booting from the CD using the following command.

kvm -m 1024 -cdrom CentOS-6.0-i386-bin-DVD.iso -drive file=centos.img,if=virtio,index=0 -boot d -net nic -net user -nographic -vnc :1

Connect to the Virtual Machine through VNC (use display number :1).For Example, where is the IP address of the host machine.

vncviewer :1

Select SSH server  and curl from the package list. Also select the other packages needed, during the  installation. Once the installation is over shutdown and boot the Virtual Machine  from Hard Drive.

kvm -m 1024 -drive file=centos.img,if=virtio,index=0,boot=on -boot c -net nic -net user -nographic -vnc :1

Do the necessary changes needed for the image.

For SSH key injection add the following lines before ‘exit 0’ in the file /etc/rc.local.

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

Edit the file /etc/sysconfig/network-scripts/ifcfg-eth0 and remove the line that contains “HWADDR=”

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.

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

Shutdown the Virtual Machine. Upload the image to OpenStack using the following command

cloud-publish-image amd64 centos.img centosbucket

The following output shows that the image has been successfully uploaded.

ami-00000001 centosbucket/centos.img.manifest.xml

Verify whether the instance boots from the uploaded image.

euca-run-instances ami-00000001 -k mykey -t m1.tiny

4 Responses

Subscribe to comments with RSS.

  1. It didn’t work for me. In the installation process, what kind of installation must be chosen? minimal ? basic server?


    December 7, 2011 at 7:52 pm

    • A standard hands-off installation of Ubuntu Server.


      September 13, 2013 at 4:56 pm

  2. I am using openstack Diablo release. I did follow step listed and create CentOS5.7 images.

    However Openstack is not able to inject hostname or IP Address into images. any idea what I need to look into


    January 20, 2012 at 11:24 pm

    • Hi, have you figured it out? Please try a later version of OpenStack and tell me how it goes.



      September 13, 2013 at 4:56 pm

Leave a 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: