Quantcast
Channel: AWS | Phil Chen
Viewing all articles
Browse latest Browse all 20

How to Save a Snapshot of your Amazon EC2 Instance

$
0
0

This how to article will go over saving a snapshot of your Amazon Elastic Compute Cloud (EC2) Machine Image (AMI). This is very useful for taking an existing AMI and modifying it to customize your needs into a new separate AMI.

For my intents and purposes I have a base CentOS 5.3 AMI with only the bare essentials. I then use this snapshot method to create different class AMI’s for different server functions ie. (webserver, memcached server, etc)

First thing is first you are going to need to have an existing AMI created, you can read how to do so in my other blog article How to create an Amazon Elastic Compute Cloud EC2 Machine Image (AMI). Once you have this AMI created and you launch the instance the fun begins to modify it and then take a snapshot for a new AMI based on the original AMI.

So once you launch your instance off your base AMI, you simply connect to your Amazon EC2 instance and install all the software you need to serve your purpose as you would any other server. After you have completed all the software installs and customizations, you then can begin the snapshot process.

The first step is to create a directory and download the Amazon EC2 Tools

[root@ec2instance]$ mkdir /mnt/EC2TOOLS
[root@ec2instance]$ cd /mnt/EC2TOOLS
[root@ec2instance]$ wget http://3.84.23.23/wp-content/uploads/2009/05/ec2-ami-tools.zip
[root@ec2instance]$ unzip ec2-ami-tools.zip
[root@ec2instance]$ cd ec2-ami-tools-1.3-31780
[root@ec2instance]$ mv * ../
[root@ec2instance]$ cd ../
[root@ec2instance]$ rmdir ec2-ami-tools-1.3-31780/

Now scp over your AWS private and public certificate

/mnt/EC2TOOLS/pk-yourprivatekey.pem
/mnt/EC2TOOLS/cert-yourcertificate.pem

You want to setup your .bashrc to know where your tools are

[root@ec2instance]$ vi ~/.bashrc
export PATH=$PATH:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
export EC2_HOME=/mnt/EC2TOOLS

[root@ec2instance]$ source ~/.bashrc

Now you will want to download the correct kernel modules:

If your creating a snapshot of a 32bit AMI and don’t have the proper xen kernel modules do the following:

[root@ec2instance]$ mkdir /mnt/MOD
[root@ec2instance]$ cd /mnt/MOD
[root@ec2instance]$ wget http://3.84.23.23/wp-content/uploads/2009/05/kernel-modules2616-xenu.tgz
[root@ec2instance]$ gunzip -c kernel-modules2616-xenu.tgz | tar -xvf -
[root@ec2instance]$ cd /mnt/MOD/lib/modules
[root@ec2instance]$ mv 2.6.16-xenU /lib/modules
[root@ec2instance]$ depmod -ae 2.6.16-xenU

If your creating a snapshot of a 64bit AMI and don’t have the proper xen kernel modules do the following:

[root@ec2instance]$ mkdir /mnt/MOD
[root@ec2instance]$ cd /mnt/MOD
[root@ec2instance]$ wget http://3.84.23.23/wp-content/uploads/2009/05/kernel-modules-261633-xenu.tgz
[root@ec2instance]$ gunzip -c kernel-modules-261633-xenu.tgz | tar -xvf -
[root@ec2instance]$ cd /mnt/MOD/
[root@ec2instance]$ mv 2.6.16.33-xenU /lib/modules
[root@ec2instance]$ depmod -ae 2.6.16.33-xenU

Now you will want to create a location to store the image files

[root@ec2instance]$ mkdir /mnt/EC2IMAGE

At this step you are ready to create the EC2 image files and upload them to S3

[root@ec2instance]$ cd /mnt/EC2TOOLS
[root@ec2instance]$ bin/ec2-bundle-vol -d /mnt/EC2IMAGE --privatekey pk-yourprivatekey.pem --cert cert-yourcertificate.pem -u amazonaccountnumber -r i386 or x86_64 -p imagename
[root@ec2instance]$ bin/ec2-upload-bundle -b yours3bucketname -m /mnt/EC2IMAGE/whatever.manifest.xml -a accesskeyid -s secretaccesskey

Now on your local machine that you start instances from register the new AWS AMI

[phil@client]$ /Users/phil/EC2/bin/ec2-register yourbucketname/thenameofthenewami.manifest.xml

At this point you are done, and ready to fire up your new AMI instance whenever you like with your changes. Note the below directories have been excluded during the bundle process so your certs and secret info will be excluded, but also note anything you installed in these directories will not be kept though as well.

Excluding:
/sys
/proc
/dev/pts
/proc/sys/fs/binfmt_misc
/dev
/media
/mnt
/proc
/sys
/mnt

Happy snapshotting your AMI 🙂

Also a great resource for free Realtime AWS uptime data is Systems Watch

The post How to Save a Snapshot of your Amazon EC2 Instance first appeared on Phil Chen.

Viewing all articles
Browse latest Browse all 20

Trending Articles