Ubuntu and Debian AMIs for Amazon EC2

United States
Ubuntu Release server
32-bit
server
64-bit
desktop
32-bit
desktop
64-bit
Ubuntu 9.04 Jaunty ami-0d729464 ami-1f749276 ami-0b729462 ami-1d749274
Ubuntu 8.10 Intrepid ami-0372946a ami-1374927a ami-01729468 ami-11749278
Ubuntu 8.04 Hardy ami-0772946e ami-1774927e ami-0572946c ami-1574927c
Ubuntu 6.06 Dapper ami-19729470 ami-e9749280
Ubuntu Karmic (Alpha) ami-19a34270 ami-87a243ee ami-85a243ec
Debian Release server
32-bit
server
64-bit
desktop
32-bit
desktop
64-bit
Debian Squeeze ami-e048af89 ami-6f729406 ami-0256b16b ami-61729408
Debian 5.0 Lenny ami-1d729474 ami-ed749284 ami-1b729472 ami-eb749282
Debian 4.0 Etch ami-1f729476 ami-ef749286 ami-fe57b097


Amazon Elastic Compute Cloud (EC2) provides self-serve, on-demand servers where you pay for the capacity you use.

The Ubuntu and Debian images listed above are built for Amazon EC2 using a collection of best practices collected from the EC2, Ubuntu, and Debian communities.

Canonical Images for Amazon EC2

The Ubuntu images listed below are built by Canonical:


United States
Ubuntu Release Canonical server
32-bit
Canonical server
64-bit
Ubuntu 8.10 Intrepid ami-5059be39 ami-255bbc4c
Ubuntu 8.04 Hardy ami-5d59be34 ami-2959be40

When you start up an instance (server) on Amazon EC2, you need to pick the image or AMI (Amazon Machine Image) to run. This determines the Linux distribution and version as well as the initial software installed and how it is configured.

There are a number of public images to choose from with EC2 including the Ubuntu and Debian image published on http://alestic.com but sometimes it is appropriate to create your own private or public images. There are two primary ways to create an image for EC2:

  1. Create an EC2 image from scratch. This process lets you control every detail of what goes into the image and is the easiest way to automate image creation.

  2. Rebundle a running EC2 instance into a new image. This approach is the topic of the rest of this article.

After you rebundle a running instance to create a new image, you can then run new EC2 instances of that image. Each instance starts off looking exactly like the original instance as far as the files on the disk go (with a few exceptions).

This guide is primarily written in the context of running Ubuntu on EC2, but the concepts should apply without too much changing on Debian and other Linux distributions.

To use this rebundling approach, you start by running an instance of an image that (1) is as close as possible to the image you want to create, and (2) is published by a source you trust. You then proceed to install software and configure that instance so that it contains exactly what you want to be available on new instances right down to the startup scripts.

The next step is to bundle the instance’s disk image into a new AMI, but before we get to that, it is important to understand a few things about security.

Security

If you are creating a new EC2 image, you need to be very careful what pieces of information you inadvertently leave on the image, especially if you have the goal of publishing it as a public AMI. Anybody who runs an instance of that AMI will have access to the files you included in the bundle, and there is no way to modify an AMI after it has been created (though you can delete it).

For example, you don’t want to leave your AWS certificate or private key on the disk. You’ll even want to clear out the shell history file in case you had typed secret information in commands or in setting environment variables.

You also want to consider the security concerns from the perspective of the people who run the new image. For example, you don’t want to leave any passwords active on accounts. You should also make sure you don’t include your public ssh key in authorized_keys files. Leaving a back door into other people’s servers is in poor taste even if you have no intention of ever using it.

Here are some sample commands, but only you can decide if this wipes out too much or what other files you need to exclude depending on how you set up and used the instance you are bundling:

sudo rm -f /root/.*hist*
sudo rm -f /var/log/*.gz
sudo find /var/log -name mysql -prune -o -type f -print | 
  while read i; do sudo cp /dev/null $i; done

Whole directories can be excluded from the image using the --exclude option of the ec2-bundle-vol command (see below).

Rebundling

Now we’re ready to bundle the actual EC2 image (AMI). To start, you need to copy your certificate and key to the instance ephemeral storage. Adjust the sample command to use the appropriate keypair file for authentication and the appropriate location of your certification and private key files. If you are running an Ubuntu image from Canonical change remoteuser to “ubuntu”.

remotehost=<ec2-instance-hostname>
remoteuser=root

scp -i KEYPAIR.pem   <path-to-keys>/{cert,pk}-*.pem   $remoteuser@$remotehost:/tmp

Set up some environment variables for convenience in the following commands. A single S3 bucket can be used for multiple AMIs. The manifest prefix should be descriptive, especially if you plan to publish the AMI publicly, as it is the only piece of documentation many users will see when they look through AMI lists. At a minimum, I recommend including the Linux distribution (e.g, “ubuntu”), the architecture (e.g., “i386” or “32”), and the date (e.g., “20090621”), as well as some tag that indicates the special nature of the image (e.g., “desktop” or “lamp”).

bucket=<your-bucket-name>
prefix=<descriptive-image-title>

On the EC2 instance itself, you also set up some environment variables to help the bundle and upload commands. You can find these values in your EC2 account.

export AWS_USER_ID=<your-value>
export AWS_ACCESS_KEY_ID=<your-value>
export AWS_SECRET_ACCESS_KEY=<your-value>

if [ $(uname -m) = 'x86_64' ]; then
  arch=x86_64
else
  arch=i386
fi

Bundle the files on the current instance into a copy of the image under /mnt:

sudo -E ec2-bundle-vol             -r $arch                         -d /mnt                          -p $prefix                       -u $AWS_USER_ID                  -k /tmp/pk-*.pem                 -c /tmp/cert-*.pem               -s 10240                         -e /mnt,/tmp,/root/.ssh,/home/ubuntu/.ssh

Upload the bundle to a bucket on S3:

ec2-upload-bundle                    -b $bucket                       -m /mnt/$prefix.manifest.xml     -a $AWS_ACCESS_KEY_ID            -s $AWS_SECRET_ACCESS_KEY

Now that the AMI files have been uploaded to S3, you register the image as a new AMI. This is done back on your local system (with the API tools installed):

ec2-register $bucket/$prefix.manifest.xml

The output of this command is the new AMI id which is used to run new instances of that image.

It is important to use the same account access information for the ec2-bundle-vol and ec2-register commands even though they are run on different systems. If you don’t you’ll get an error indicating you don’t have the rights to register the image.

Public Images

By default, the new EC2 image is private, which means it can only be seen and run by the user who created it. You can share access with another individual account or with the public.

To let another EC2 user run the image without giving access to the world:

ec2-modify-image-attribute -l -a <other-user-id> <ami-id>

To let all other EC2 users run instances of your image:

ec2-modify-image-attribute -l -a all <ami-id>

Cost

AWS will charge you standard S3 charges for the stored AMI files which comes out to $0.15 per GB per month. Note, however, that the bundling process uses sparse files and compression, so the final storage size is generally very small and your resulting cost may only be pennies per month.

The AMI owner incurs no charge when users run the image in new instances. The users who run the AMI are responsible for the standard hourly instance charges.

Cleanup

Before removing any public image, please consider the impact this might have on people who depend on that image to run their business. Once you publish an AMI, there is no way to tell how many users are regularly creating instances of that AMI and expecting it to stay available. There is also no way to communicate with these users to let them know that the image is going away.

If you decide you want to remove an image anyway, here are the steps to take.

Deregister the AMI

ec2-deregister ami-XXX

Delete the AMI bundle in S3:

ec2-delete-bundle   --access-key $AWS_ACCESS_KEY_ID   --secret-key $AWS_SECRET_ACCESS_KEY   --bucket $bucket   --prefix $prefix

Ubuntu Karmic Koala Alpha is being developed and will be released as Ubuntu 9.10 in October. If you want to play around with Karmic Alpha on Amazon EC2, I have published new AMIs in the US and EU regions for 32- and 64-bit:

http://alestic.com

A Karmic desktop image for EC2 is also available if you wish to monitor progress in that area.

Warning! Karmic is an unstable alpha developer version and is not intended for use in anything resembling a production environment.

Please note that we are still defaulting to Amazon’s 2.6.21fc8 kernel which, though functional and stable, is getting older and older for each new release of Ubuntu. One effect of this is that AppArmor will not be enabled, though this should not affect the functionality of any software.

Enjoy!

Amazon EC2 currently has a limit of 1,000 GB (1 TB) for EBS volumes (Elastic Block Store). It is possible to create file systems larger than this limit using RAID 0 across multiple EBS volumes. Using RAID 0 can also improve the performance of the file system reducing total IO wait as demonstrated in a number of published EBS performance tests.

The following instructions walk through one way to set up RAID 0 across multiple EBS volumes. Note that there is a limit on the size of a file system on 32-bit instances, but 64-bit instances can get unreasonably large. This test was run with 40 EBS volumes of 1,000 GB each for a total of 40,000 GB (40 TB) in the resulting file system.

Actual command line output showing the size of the RAID:

# df /vol
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/md0             41942906368      1312 41942905056   1% /vol

# df -h /vol
Filesystem            Size  Used Avail Use% Mounted on
/dev/md0               40T  1.3M   40T   1% /vol

These commands can run in less than 10 minutes and this could probably be reduced further by parallelizing the creation and attaching of the EBS volumes.

Note that the default limit is 20 EBS volumes per EC2 account. You can request an increase from Amazon if you need more.

Caution: 40 TB of EBS storage on EC2 will cost $4,000 per month plus usage charges.

Instructions

Start a 64-bit instance (say, Ubuntu 8.04 Hardy from http://alestic.com). Use your own KEYPAIR:

ec2-run-instances                  --key KEYPAIR                    --instance-type c1.xlarge        --availability-zone us-east-1a   ami-0772946e

Configurable parameters (set on both local host and on EC2 instance):

instanceid=i-XXXXXXXX
volumes=40
size=1000
mountpoint=/vol

On the local host (with EC2 API tools installed)…

Create and attach EBS volumes:

devices=$(perl -e 'for$i("h".."k"){for$j("",1..15){print"/dev/sd$i$j\n"}}'|
           head -$volumes)
devicearray=($devices)
volumeids=
i=1
while [ $i -le $volumes ]; do
  volumeid=$(ec2-create-volume -z us-east-1a --size $size | cut -f2)
  echo "$i: created  $volumeid"
  device=${devicearray[$(($i-1))]}
  ec2-attach-volume -d $device -i $instanceid $volumeid
  volumeids="$volumeids $volumeid"
  let i=i+1
done
echo "volumeids='$volumeids'"

On the EC2 instance (after setting parameters as above)…

Install software:

sudo apt-get update &&
sudo apt-get install -y mdadm xfsprogs

Set up the RAID 0 device:

devices=$(perl -e 'for$i("h".."k"){for$j("",1..15){print"/dev/sd$i$j\n"}}'|
           head -$volumes)

yes | sudo mdadm            --create /dev/md0         --level 0                 --metadata=1.1            --raid-devices $volumes   $devices

echo DEVICE $devices       | sudo tee    /etc/mdadm.conf
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm.conf

Create the file system (pick your preferred file system type)

sudo mkfs.xfs /dev/md0

Mount:

echo "/dev/md0 $mountpoint xfs noatime 0 0" | sudo tee -a /etc/fstab
sudo mkdir $mountpoint
sudo mount $mountpoint

Check it out:

df -h $mountpoint

When you’re done with it and want to destroy the data and stop paying for storage, tear it down:

sudo umount $mountpoint
sudo mdadm --stop /dev/md0

Terminate the instance:

sudo shutdown -h now

On the local host (with EC2 API tools installed)…

Detach and delete volumes:

for volumeid in $volumeids; do
  ec2-detach-volume $volumeid
done

for volumeid in $volumeids; do
  ec2-delete-volume $volumeid
done

Credits

This article was originally posted on the EC2 Ubuntu group.

Thanks to M. David Peterson for the basic mdadm instructions:

New updates have been released for the Ubuntu and Debian AMIs (EC2 images) published on:

http://alestic.com

The following improvements are included in this release:

  • Ubuntu 9.04 Jaunty now uses an Ubuntu mirror inside of EC2 hosted by RightScale. This dramatically improves the performance of updates and upgrades. Hardy and Intrepid were already using the mirrors inside EC2.

  • The Hardy, Intrepid, and Jaunty images have been enhanced to add failover for Ubuntu archive mirror hosts across availability zones (data centers). This change lets an Ubuntu instance perform package updates and upgrades even if one or two of the EC2 availability zones are completely unavailable.

  • The denyhosts package is now installed on desktop images for improved security. The Amazon abuse team has identified the Ubuntu desktop images as a source of compromised systems. The cause for this is believed to be insecure passwords set by users, since the desktop images have PasswordAuthentication enabled by default so that the NX client can connect. The denyhosts package blocks ssh attacks by adding remote systems to /etc/hosts.deny if they keep failing password logins.

    The published Ubuntu and Debian server images continue to have PasswordAuthentication turned off by default for improved security. If you choose to turn this on, I recommend installing a package like denyhosts and using software like the following to generate secure passwords:

    sudo apt-get install pwgen
    pwgen -s 10 1
    
  • The EC2 AMI tools have been upgraded to version 1.3-31780.

  • All software packages have been updated to versions current as of 2009-06-14.

Community support for Ubuntu on EC2 is available in this group:

http://groups.google.com/group/ec2ubuntu

Community support for Debian on EC2 is available in this group:

http://groups.google.com/group/ec2debian

The 32-bit Debian squeeze images and the 32-bit Debian etch desktop image have not been updated yet due to problems with initial package installation. Images will be released when these issues are resolved.

The following enhancements have been made to the ec2ubuntu-build-ami software which is used to build Ubuntu and Debian images for EC2.

  • New --kernel and --ramdisk options have been added to specify AKI and ARI. If you specify a different kernel, you should also specify kernel modules with --package or install them with the --script option.

  • Support has been removed for Ubuntu Edgy, Feisty, and Gutsy. These releases have reached their end of life. To improve the clarity of the code this software no longer supports building these images.

  • There has been a typo fix for $originaldir for folks who were using the --script option.

  • There has been a typo fix for /dev/ptmx though it apparently had no effect given how these images are built.

Thanks to Stephen Parkes and Paul Dowman for submitting patches.

Enjoy!

Reposting a response I wrote to a user on Amazon’s EC2 forum who is having a hard time finding good engineers with AWS experience:

If there aren’t enough talented engineers who already know AWS, consider hiring talented engineers who can learn AWS.

You might find that there are existing AWS experts who aren’t looking for a full time job, but who are willing to be consulting resources to help bring your talent quickly up to speed with the ins and outs of building systems appropriately on AWS and to help answer questions and solve problems as they arise.

You should be aware that given the current growth of AWS, your engineers will be in high demand once they have AWS experience, so treat them well :)

Please do encourage your new talent to be active in the community too. It not only helps others, but it also significantly improves their own skills and expertise. I learned a lot of what I know about AWS by trying to solve other people’s problems.

Stay Updated

Subscribe with email address:
 Subscribe with a reader
Join the EC2 Ubuntu Google Group
Follow Eric Hammond on Twitter

More Entries

Opinion: EC2 Outage Was Not an Outage
The Twitter wires are aflame with cute quotes on how lightning from a “cloud” took down Amazon’s EC2 “cloud” service.…
Using Elastic IP to Identify Internal Instances on Amazon EC2
Elastic IP Amazon EC2 supports Elastic IP Addresses to implement the effect of having a static IP address for public…
Switching apt sources Mirror Repositories in Ubuntu on EC2
UPDATE-3: As of 2009-06-16 02:35a, Canonical has restored the Ubuntu mirror for EC2 in the US region. It looks like…
Keeping File Ownership (UIDs) Consistent when Using EBS on EC2
Persistent storage on Amazon EC2 is accomplished through the use of Elastic Block Store (EBS) volumes. EBS is basically a…
Tip: Get Startup Time of EC2 Instance from meta-data
Dmitriy Samovskiy discovered that the startup time of an EC2 instance (not the latest boot time) is hidden in the…
Automate EC2 Instance Setup with user-data Scripts
user-data Scripts The Ubuntu and Debian EC2 images published on http://alestic.com allow you to send in a startup script using…
Updated Tutorial: Running MySQL on Amazon EC2 with EBS (now supports AppArmor)
The following tutorial (originally published in Aug ‘08) has been extensively updated today: Running MySQL on Amazon EC2 with Elastic…
Amazon Launches CloudWatch Monitoring Service for EC2
A few hours ago, Amazon launched a monitoring service for EC2 instances which they are calling CloudWatch. The service costs…
Credits and ThankYou's
With the conversion of the web site format for Alestic.com from a single page to more of a blog, the…
Escaping Restrictive/Untrusted Networks with OpenVPN on EC2
Perhaps you are behind a corporate firewall which does not allow you to access certain types of resources on the…
Using sudo, ssh, rsync on the Official Ubuntu Images for EC2
The official Ubuntu images for EC2 do not allow ssh directly to the root account, but instead provide access through…
Official Ubuntu Images for Amazon EC2 from Canonical
Canonical has released official Ubuntu images for EC2 including the releases 8.04 Hardy and 8.10 Intrepid. The primary technical benefit…
New releases of Ubuntu AMIs for Amazon EC2 2009-04-23 (Jaunty released)
As you may have heard, Ubuntu 9.04 Jaunty has been officially released by Ubuntu today, right on schedule: http://ubuntu.com Matching…
New releases of Ubuntu AMIs for Amazon EC2 2009-04-18 (XFS fixes)
New updates have been released for all* of the Ubuntu and Debian AMIs listed on: http://alestic.com The primary enhancements in…
New releases of Ubuntu Jaunty AMIs for Amazon EC2 2009-03-29
New updates have been released for the Ubuntu Jaunty AMIs on http://alestic.com Jaunty recently moved from “alpha” to “beta” in…
New releases of Ubuntu AMIs for Amazon EC2 2009-02-16 (EC2 mirrors)
New updates have been released for all* of the Ubuntu and Debian AMIs listed on: http://alestic.com The primary enhancements in…
New releases of Ubuntu AMIs for Amazon EC2 2008-12-22
New updates have been released for all* of the Ubuntu and Debian AMIs listed on: http://alestic.com The primary enhancements in…
Ubuntu AMIs available in Europe (eu-west-1)
The Ubuntu and Debian images listed on http://alestic.com are now available in both the US (us-east-1) and Europe (eu-west-1) EC2…
New releases of Ubuntu AMIs for Amazon EC2 2008-11-30
New updates have been released for all* of the Ubuntu and Debian AMIs listed on: http://alestic.com The primary enhancements in…
Ubuntu 8.10 Intrepid Ibex AMIs released for Amazon EC2 2008-10-30
The big news in the Ubuntu community today is that Ubuntu 8.10 Intrepid Ibex has been released right on schedule:…