For my current project, I'm using Amazon's Elastic Compute Cloud (EC2). I've chosen Ubuntu as my OS, and so I started with the Ubuntu EC2 Starters Guide, and the UEC images therein. Those are a good base, but I need my own configuration on first boot of the VM.
Naturally, I looked around to see how Ubuntu built their EC2 images, and found in the EC2 FAQ that they build them using python-vm-builder-ec2. Sweet! That seems easy. Oh wait, the EC2 part of vmbuilder has been broken since Lucid. Oh, there's a patch in that bug report. Darn, that doesn't work either.
Fine, let's look up UEC (Ubuntu Enterprise Cloud) stuff and see if that provides successful information. Oh look! How to make your own UEC image, with different instructions! Maybe that will work? Oh no, the part file provided doesn't work with vmbuilder, and the instructions don't port over to EC2 that well. Grrrrr.
Well, looks like I need to provide my own instructions (and eventually fix the wiki). So here I go:
Start by creating a part file that will work. As per the vmbuilder man page, each line in the part file can have four fields: mountpoint size (device) (filename). In the man page, it says the third and fourth fields are optional. They're not. So a valid part file is:
root 400 /dev/sda1 rootfs /mnt/ephemeral 2000 /dev/sda2 instance
Next, build an Ubuntu vm image. This works as long as you don't use any of the ec2 options:
$ sudo vmbuilder xen ubuntu --suite=natty \ --firstboot=/usr/share/doc/python-vm-builder-ec2/examples/ec2-firstboot.sh \ --part=./part
Bundle and upload your newly created image:
$ mkdir image $ ec2-bundle-image --image ubuntu-xen/rootfs --destination ./image --cert $EC2CERT \ --privatekey $EC2PRIVATEKEY --user $EC2USER --arch i386 $ ec2-upload-bundle --access-key $EC2ACCESSKEY --secret-key $EC2SECRETKEY \ --bucket $EC2IMAGESBUCKET --manifest ./image/roofs.manifest.xml $ ec2-register --cert $EC2CERT --private-key $EC2PRIVATEKEY \ $EC2IMAGES_BUCKET/rootfs.manifest.xml
The last line of that step will return "IMAGE ami-xxxxxxxx" where the "ami-xxxxxxxx" part is your AMI ID to use when launching instances.
- You could specify a different --kernel and --ramdisk when you ec2-bundle-image, but the defaults work well. I couldn't find a list of AKIs and ARIs with descriptions. If someone could help me out on that it would be awesome.
- You need to set up the environment variables (the things that start with $) to make this work. The names should be self-explanatory.
- You may want to customize your first boot script from the ec2 default.
- You can use the --addpkg parameter to add packages to your vm in the vmbuilder step (one package name per --addpkg). That's from the old JeOSVMBuilder docs. Lots of "hidden" info about vmbuilder there.