3/11/09

Bundeling an existing linux server into a new AMI

Requirements:
- A running server to bundle
- Ec2 ami/api tools installed
- Amazon ec2 account

First you need to setup the amazon ec2 tools, follow the directions here:

http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/setting-up-your-tools.html


Some notes that I have for my local setup that may be useful:

sudo yum install ruby


wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.noarch.zip

go to http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&categoryID=88 for the API tools
go to http://java.sun.com/j2se/1.4.2/download.html to download and install the jre enviroment


---- tools ----
export EC2_HOME=/home/kylec/ec2-api-tools-1.3-26369
export EC2_AMITOOL_HOME=/home/kylec/ec2-ami-tools-1.3-26357

---- keys -----
export EC2_PRIVATE_KEY=~/.ec2/pk-$keynumber.pem #set $keynumber
export EC2_CERT=~/.ec2/cert-$keynumber.pem #set $keynumber

---- example .bash_profile -----
PATH=$PATH:$HOME/bin:/usr/bin/:/home/kylec/ec2-api-tools-1.3-26369/bin/:/usr/sbin:/usr/local/sbin

export PATH
unset USERNAME

export EC2_AMITOOL_HOME=/home/kylec/ec2-ami-tools-1.3-26357
export EC2_HOME=/home/kylec/ec2-api-tools-1.3-26369
export EC2_PRIVATE_KEY=~/.ec2/pk-*************.pem
export EC2_CERT=~/.ec2/cert-**************.pem
export JAVA_HOME=/usr
-------------------------------

----------------------------
There are a few things you want to do before you bundle your image, get it to how you want it as far as applications installed, updates applied, configurations set etc... After all the things kept on / are non-persistant after reboots.


#Once everything is setup for the tools, you can bundle the running physical machine with the following.

./ec2-bundle-vol -p amazonami1 -d /ami -c ~/.ec2/cert-*****.pem -k ~/.ec2/pk-******.pem -u 123456789 -s 10240 --no-inherit --generate-fstab -e /ami --kernel aki-9800e5f1 --ramdisk ari-a23adfcb

This will create a new image named "amazonami1", and will put it in /xen, at the max size of 10240, and will not inherit its meta data from the instance (duh), and will generate an ec2 fstab file... (note the exclude -e /ami)

Also a good idea is to specify the kernel you want to start the AMI with, as it will default to the oldest one. aki-9800e5f1 = 2.6.18-xenU-ec2-v1.0

So this should take a little while, it will mount a loop0 interface and write/compress and encrypt your instance into the specified /ami folder.

Now the next part is easy, all that is left is to upload your newly bundled image.

ec2-upload-bundle -b bucketname -m /ami/imageprefixname.manifest.xml -a ************ -s ********************

Pretty straight forward, just need to specify the bucket to upload to, and the path to the ami manifest.xml file. Just sit back and let it upload.

Once its compete all thats left is to register the AMI,

ec2-register /bucket/aminame.manifest.xml

Then, just login to the console and start your new AMI,

https://console.aws.amazon.com/

No comments:

Post a Comment