Wednesday, April 10, 2013

Importing an HVM image from EC2

I have recently taken a new role at Sales Engineer at Eucalyptus and one time consuming issue I keep running into with clients is image management - specifically being able to import an EBS backed image from EC2 into Eucalyptus.

The merits of this endeavor are open for debate: I would much prefer hybrid users use separate images on different clouds and simply use cloud-init scripts, or a similar mechanism, to pull up the same application stack on each of them.  That being said, customers want it, so we try to make it as easy as possible for them.

Another Sales Engineer here at Eucalyptus wrote a great guide on how to do this with HVM images on EC2:

https://github.com/eucalyptus/eucalyptus/wiki/Import-an-HVM-AMI

Important note: When using an EBS image in Eucalyptus, Eucalyptus assumes it to be an HVM (Hardware Virtual Machine) image.

I decided to take this a step further and automate it with a simple shell script.  You can grab it here:

https://github.com/iamfuzz/euca-image-tools/blob/master/fetch-hvm-image.sh

Please note that this isn't an officially supported tool and hasn't been tested by anyone other than yours truly. That being said, to test it out, the following pre-requisites must be met:

* An AWS account
* Obtaining the AMI ID of the HVM image you'd like to import
* An instance store AMI in your account to be used as a scratch instance with root access (some Ubuntu images may not work as they use user ubuntu instead)
* Enough disk space in the TEMPDIR on your local machine to store the image
* An ssh key setup on AWS and downloaded to your home directory as <key-name>.priv

Once you have downloaded the script, make sure you have your AWS secret key and access key exported in your shell environment, and then run it as follows:

./fetch-hvm-image ami-XXXXXXXX key-name [ami-XXXXXXXX]

The first AMI is the HVM AMI and is required.  The second AMI argument is optional and if left unspecified, the script will use the first instance-store AMI in your account that it finds.

If the script finishes successfully, it will display the image location in your TEMPDIR.  From there you can import it manually into your Eucalyptus setup or use the new, unofficial version of eustore mentioned in my previous blog post to do it for you.

Please note that many images will require modifications before importation.  For instance, the official SuSe images have startup scripts in them specific to AWS that can cause boot problems in Euca an must be disabled.  If you run into problems, feel free to post about it here, and I will do my best to help you out.

Enjoy!