Thursday, June 18, 2009

Bundling a Linux/UNIX instance

A root file system image needs to be bundled as an AMI in order to be used with the Amazon EC2 service. The bundling process first compresses the image to minimize bandwidth usage and storage requirements. The compressed image is then encrypted and signed to ensure confidentiality of the data, and authentication against the creator. The encrypted image is finally split into manageable parts for upload. A manifest file is created containing a list of the image parts with their checksums. This chapter provides an overview of the AMI tools that automate this process and some examples of their use.
The AMI tools are three command-line utilities:
1. ec2-bundle-image bundles an existing AMI
2. ec2-bundle-vol creates an AMI from an existing machine or installed volume
3. ec2-upload-bundle uploads a bundled AMI to S3 storage






Attaching an Elastic Block Store(EBS):

Creating a EBS & attaching to running instance:

1)Launch Server
2)Click on the “Volumes and Snapshots” tab in Elasticfox.
3)Press the green (+) symbol in the “Volumes” box.
4)Type in the size in gigabytes (GB) of the volume you would like between 1 and 1000. For the purposes of this demo, please use “50” to specify a 50 GB drive.
*Note: A volume must be in the same availability zone as an instance.
5)Click the OK button, and your Amazon EBS volume will be created. Take note of the volume id of the Amazon EBS volume you just created, because we will use it later.

After Few Minutes:

6)Login to Server
7)Select Start and click Run.
8)Type diskmgmt.msc and click OK. The Disk Management utility opens.
9)Right-click the Amazon EBS volume, select Initialize, and follow the on-screen prompts.
10)Format and use as local drive.





Installing the AMI Tools
The AMI tools are packaged as an RPM suitable for running on Fedora Core 3/4 with Ruby 1.8.2 (or greater) installed. On Fedora Core 4 Ruby can be installed by following the steps below. You will need root privileges to install the software. You can find the AMI tools RPM from our public S3 downloads bucket.
First install Ruby using the yum package manager.
# yum install ruby
Install the AMI tools RPM.
# rpm -i ec2-ami-tools-x.x-xxxx.i386.rpm
Installation Issues
The AMI tools libraries install under /usr/lib/site_ruby. Ruby should pick up this path automatically, but if you see a load error when running one of the AMI utilities, it may be because Ruby isn't looking there. To fix this, add /usr/lib/site_ruby to Ruby's library path, which is set in the RUBYLIB environment variable.

Documentation
The manual describing the operation of each utility can be displayed by invoking it with the --manual parameter. For example:
# ec2-bundle-image --manual
Invoking a utility with the --help parameter displays a summary and list of command line parameters. For example:
# ec2-bundle-image --help
Using the AMI Tools
Once a machine image has been created it must be bundled as an AMI for use with Amazon EC2, as follows. Use ec2-bundle-image to bundle an image that you have prepared in a loopback file, as described in the previous section.
# ec2-bundle-image -i my-image.img -k my-private-key.key -u 12345678
This will create the bundle files:
image.part.00
image.part.01
...
image.part.NN
image.manifest
Alternatively an AMI could be created by snapshotting the local machine root file system and bundling it all at once by using ec2-bundle-vol. (note: you will need to have root privileges to do this and SELinux must be disabled). Use ec2-bundle-vol to re-bundle a (modified) running instance of an existing AMI, as described in the previous section.
# ec2-bundle-vol -k my-private-key.key -s 1000 -u 495219933132
As with ec2-bundle-image, ec2-bundle-vol will create image parts files and a manifest file.
Note: If selinux is enabled when ec2-bundle-vol is run, the filesystem creation step may fail. Selinux should be disabled while this is done.

Uploading a Bundled AMI
The bundled AMI needs to be uploaded for storage in Amazon S3 before it can be accessed by Amazon EC2. Use ec2-upload-bundle to upload the bundled AMI that you created as described above. S3 stores data objects in buckets, which are similar in concept to directories. Buckets must have globally unique names. The ec2-upload-bundle utility will upload the bundled AMI to a specified bucket. If the specified bucket does not exist it will be created. However, if the specified bucket already exists, and belongs to another user, then ec2-upload-bundle will fail.
# ec2-upload-bundle -b my-bucket -m image.manifest -a my-aws-access-key-id -s my-secret-key-id
The AMI manifest file and all image parts are uploaded to S3. The manifest file is encrypted with the Amazon EC2 public key before being uploaded.

No comments:

Post a Comment