UEC: Bundling Linux Image
Creating a new disk Image
This will be the main HDD in the virtual image, so make sure to give it as much space as youll need. Since were building a kvm image, we can use a qcow2 format for disk images. Qcow2 is an expandable image format, so itll only take as much storage space as its actually used within the image.
$ kvm-img create -f qcow2 image.img 5G
Download the iso file of the Linux distribution you want installed in the image.
$ wget http://releases.ubuntu.com/karmic/ubuntu-9.04-server-amd64.iso
And start the installation process:
$ sudo kvm -m 256 -cdrom ubuntu-9.04-server-amd64.iso -drive file=image.img,if=scsi,index=0 \ -boot d -net nic,vlan=0,model=e1000,macaddr= 00:16:3e:de:ad:01 -net tap -nographic -vnc :0
If your installation process requires more than 256MB of RAM change the -m option, and if you need more processors available, you can use the -c option.
The command above will boot a new KVM instance, with the disk image youve created as the primary HDD and the iso as the first bootable device. Also the -nographic option will not display any graphical output. You can connect to the instance through VNC (use display number :0 ) and finish the installation.
For Ex: vncviewer A.B.C.D :0, where A.B.C.D is the IP address of the CC.
After finishing the installation, relaunch the VM by executing the following command.
$ sudo kvm -m 256 -drive file=image.img,if=scsi,index=0,boot=on -boot c \ -net nic,vlan=0,model=e1000,macaddr=00:16:e3:de:ad:01 -net tap -nographic -vnc :0
At this point you can add all the packages you want to have installed, update the installation, add users and any settings that need to be present in your new UEC instances.
$ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get install mediawiki
Integrating with UEC
The new image needs to know what IP it has when started in UEC and also, it needs to have the public key of the user allowed to do a passwordless access through SSH. The way its done in UEC is via a restful interface provided by the cloud. The interface is available under this URL: http://169.254.169.254/latest/meta-data.
First install curl on the VM.
$ sudo apt-get install curl
And add the following lines to /etc/rc.local of the image.
depmod -a modprobe acpiphp # simple attempt to get the user ssh key using the meta-data service # assuming user is the username of an account that has been created mkdir -p /home/user/.ssh echo >> /home/user/.ssh/authorized_keys curl -m 10 -s http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key | grep 'ssh-rsa' >> /home/user/.ssh/authorized_keys echo "AUTHORIZED_KEYS:" echo "************************" cat /home/user/.ssh/authorized_keys echo "************************"
Add the above lines before the exit 0 in /etc/rc.local.
Also remove persistent udev rules from /etc/udev/rules.d. This is needed because the interface name will change whenever the instance reboots and Eucalyptus expects the interface to be as eth0.
$ sudo rm -rf /etc/udev/rules.d/70-persistent-*
Registering with UEC
The last step would be to upload the images to UEC. The files that need to be uploaded are:
Copy the kernel and the initrd image from the VM image to some place outside. They will be used later for creating and uploading a complete virtual image to UEC.
$ scp /boot/initrd.img-2.6.28-11-server user@A.B.C.D: $ scp /boot/vmlinuz-2.6.28-11-server user@A.B.C.D:
Before starting the upload process shut down the VM.
Registering kernel image
Execute the following commands to bundle and register the kernel image (vmlinuz-2.6.28-11-server)
$ euca-bundle-image -i vmlinuz-2.6.28-11-server --kernel true $ euca-upload-bundle -b mybucket -m /tmp/vmlinuz-2.6.28-11-server.manifest.xml $ euca-register mybucket/vmlinuz-2.6.28-11-server.manifest.xml
Save the output produced by the last command above (eki-XXXXXXXX), which will be needed while registering the disk image.
Registering ramdisk image
Execute the following commands to bundle and register the ramdisk image (initrd.img-2.6.28-11-server)
$ euca-bundle-image -i initrd.img-2.6.28-11-server $ euca-upload-bundle -b mybucket -m /tmp/initrd.img-2.6.28-11-server.manifest.xml $ euca-register mybucket/initrd.img-2.6.28-11-server.manifest.xml
Save the output produced by the last command above (eri-XXXXXXXX), which will be needed while registering the disk image.
Registering disk image
Execute the following commands to bundle and register the ramdisk image (image.img)
$ euca-bundle-image -i image.img --kernel eki-XXXXXXXX --ramdisk eri-XXXXXXXX $ euca-upload-bundle -b mybucket -m /tmp/image.img.manifest.xml $ euca-register mybucket/image.img.manifest.xml
Replace eki-XXXXXXXX and eri-XXXXXXXX with the exact values as noted down earlier.
The new images that have been uploaded can be seen by using euca-describe-images command.
$ euca-describe-images IMAGE emi-70B70EC0 mybucket/image.img.manifest.xml admin available public x86_64 machine IMAGE eri-A2BE13EC mybucket/initrd.img-2.6.28-11-server.manifest.xml admin available public x86_64 ramdisk IMAGE eki-685F1306 mybucket/vmlinuz-2.6.28-11-server.manifest.xml adminavailable public x86_64 kernel
Running instance of custom image
To launch a new instance of the custom image, execute euca-run-instances command.
$ euca-run-instances emi-70B70EC0 -k mykey -t c1.xlarge