Bundling CentOS image for OpenStack
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 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 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 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=”
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.
Verify whether the instance boots from the uploaded image.
euca-run-instances ami-00000001 -k mykey -t m1.tiny