Bundling CentOS 6 Image for OpenStack


The following method was tested using CentOS 6.0 on Diablo version of OpenStack. The OpenStack cloud was setup using the procedure given in the following link.

http://cssoss.files.wordpress.com/2011/10/openstackbookv2-0_csscorp.pdf

Create a raw image which emulates the Hard Drive.

kvm-img create -f qcow2 centos.img 5G

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

kvm -m 512 -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 10.10.10.1 is the IP address of the host machine.

vncviewer 10.10.10.1 :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 the Virtual Machine. Start the Virtual Machine to boot from the Hard Drive using the following command.

kvm -m 512 -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 http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key | grep 'ssh-rsa' >> /root/.ssh/authorized_keys
echo "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=”

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.

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

Start the instance with the image that was uploaded.

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

2 thoughts on “Bundling CentOS 6 Image for OpenStack

  1. Hi Johnson,

    Did you know a way to create a tar.gz with this that I can use with uec-publish-tarball ? And also I see you have great howtos for Bundling Images for OpenStack can you give me a link to where I can download such Images. For example I will be glad if you can provide me a link to this CentOS 6 image ? I really find this articles usefull. Thanks for that !

  2. You should check out boxgrinder for building RH images. http://boxgrinder.org/. They have a meta-appliance which you can upload into openstack and use to bootstrap other images. You just create a profile and tell it to go and it does it. It’ll dump out a raw or qcow2 image that you can upload straight into OpenStack and have it run.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s