Create EBS Boot AMI
After the release of New Amazon EC2 Feature: Boot from Elastic Block Store , there are folks asking on AWS forum on how to create an EBS Boot AMI and so I’m posting another way to do it. I hope this will be plain and simple to follow.
Note that I’m using Create EBS Boot AMI scripts courtesy of fairchild.
To be able to register EBS Boot AMI, make sure you install the latest EC2 API Tools, you can check that using:
prompt> ec2-version 1.3-45772 2009-10-31
And be sure you set the the EC2 private and cert:
prompt> export EC2_PRIVATE_KEY=/home/tim/ec2-keys/pk.pem prompt> export EC2_CERT=/home/tim/ec2-keys/cert.pem
I will be using the Canonical Hardy AMI: ami-7e28ca17
The first thing is to get the AKI and ARI of the AMI using ec2-describe-images command or using ElasticFox.
prompt> ec2-describe-images ami-7e28ca17 IMAGE ami-7e28ca17 ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml 099720109477 available public i386 machine aki-92ba58fb ari-94ba58fd instance-store
Here are the AKI: aki-92ba58fb and ARI: ari-94ba58fd information.
Launch the AMI and set the keypair and availability zone:
prompt> ec2-run-instances ami-7e28ca17 -k yourkeypair -z us-east-1a RESERVATION r-237fed4a 853279305000 default INSTANCE i-d9add0b0 ami-7e28ca17 pending 0 m1.small 2009-11-14T12:38:24+0000 us-east-1a aki-92ba58fb ari-94ba58fd monitoring-disabled
Create the volume and attached it to the instance. Make sure the volume has the same availability zone with the current running instance.
prompt> ec2-create-volume --size 20 --availability-zone us-east-1a VOLUME vol-4d826724 20 us-east-1a creating 2009-11-14T12:39:24+0000 prompt> ec2-attach-volume vol-4d826724 -i i-d9add0b0 -d /dev/sdh ATTACHMENT vol-4d826724 i-6058a509 /dev/sdh attaching 2009-11-14T12:43:24+0000
Make sure the volume has status “attached” before doing the next step.
Now we need to get a copy of instance-to-ebs-ami.sh script and execute it inside the running instance.
prompt> ssh -k yourkeypair ubuntu@public-dns-of-my-instance prompt> wget http://gist.github.com/raw/249915/68e4c4c2b59dbda1be00e8e33fbe392f24834a49/instance-to-ebs-ami.sh -O /tmp/instance-to-ebs-ami.sh prompt> chmod +x /tmp/instance-to-ebs-ami.sh prompt> sudo /tmp/instance-to-ebs-ami.sh (...output truncated...assuming the script was executed successfuly) prompt> exit
Now we are back to our machine’s xterm, let’s detach the volume, make snapshot and register as new EBS Boot AMI:
prompt> ec2-detach-volume vol-4d826724 ATTACHMENT vol-4d826724 i-6058a509 /dev/sdh detaching 2009-11-15T00:55:24+0000 prompt> ec2-create-snapshot vol-4d826724 --description "EBS Ubuntu Hardy" SNAPSHOT snap-c070c5a9 vol-4d826724 pending 2009-11-15T1:31:29+0000 111111111111 1 EBS Ubuntu Hardy prompt> ec2-register --snapshot snap-c070c5a9 --kernel aki-92ba58fb --ramdisk ari-94ba58fd --description "EBS Ubuntu Hardy" --name "ebs-ubuntu-hardy-8.04-i386-server-20091130" --architecture i386 --root-device-name /dev/sda1
Yes of course you can make use the scripts provided on the github link above. But I’m sure now you get the idea. Now start to convert the remaining non-EBS AMI you may have.
By default EBS Boot AMI does not attached the ephemeral storage. See these links for reference:
Attached Ephemeral Storage on EBS Boot AMI
Ephemeral Storage Capacity
There’s also a question of “Can you resize the EBS boot AMI?”. I believe, yes. Will give it a try and post the results here.
Update:
I have posted before how to increase or enlarge the resize EBS volumes.
And about my question of resizing the EBS AMI, I found Eric Hammond’s post which is very helpful:Increasing Root Disk Size of an “EBS Boot” AMI on EC2
Update 01-28-2010:
If your looking for Public EBS Boot AMIs for Ubuntu on Amazon EC2, Eric Hammond have provided them in his site. Thanks Eric.
References:
http://coderslike.us/2009/12/07/amazon-ec2-boot-from-ebs-and-ami-conversion/
AWS EC2 Thread: Booting from EBS Image Creation
There are 26 responses to this post. Join the discussion:
Great guide!
This got it working for me.
Made a standard ubuntu intrepid ami based on ebs
Hi, nice update, you might want to update your link to the instance-to-ebs-ami.sh script, http://gist.github.com/249915?file=instance-to-ebs-ami.sh There have been a few updates to the script. The link you have is to a specific, earlier version
Hi Michael,
Thanks for pointing to updated version and of course thank you for your Create EBS Boot AMI scripts.
Youri,
Great that it work for you. As pointed by Michael, I’ve updated the new instance-to-ebs-ami.sh.
Thanks for a clear and concise writeup. My question is – what does one do when there is no identified ARI associated with a particular AMI that we are using?
Rodney, is this correct? It seems you are downloading bundle-to-ebs.sh but saving as /tmp/instance-to-ebs-ami.sh ? Should you instead download instance-to-ebs-ami.sh?
Cheers
Hi Radek,
Thanks for pointing that out. Seems my update changed the link. Fixed.
Rodney
Hey Rodney, thanks a lot! I managed to create the EBS bootable image thanks to your post! I based it on offical canonical ubuntu-hardy-9.10-i386. One thing which is kind of weird is that whenever I terminate the instance the EBS volume attached to that instance is deleted as well… Do you have any idea why this may be happening?
Hi Michael,
You might be using a kernel that does not require ramdisk.
See this post for reference:
Thread: What is the point of the ArI images?
2.6.18 Xen 3.1.0 kernel
Radek,
On EBS AMI, if you terminate the instance it will delete the volume. If you want to make a point in time copy of your EBS AMI, you can stop it using AWS Management console and use Create Image(EBS AMI). Or just create a new snapshot of the volume then you can register it using the command line tools.
Rodney
As posted here by Ton:
http://groups.google.com/group/ec2ubuntu/browse_thread/thread/11b9c0ff3e477a53
Hi Rodney,
After a small change Michael’s scripts worked fine for me in eu-west
zone. The ec2- commands in the script did not have the –region
directive set. In that case they default to ‘us-east-1′, so the script
works out-of-the-box for all people in that region, but in other
regions like ‘eu-west-1′ and ‘us-west-1′ the –region directive must
be explicitly set to that region.
Best regards, Ton
Radek,
Please check the deleteOnTerminate attribute when you run the instance. This will not delete the volumes as describe on the BootFromEBSGuide manual.
Michael,
I’ve built multiple EBS based AMI’s all working great!
But i think I’ve found some minor security issues.
The script doesn’t exclude the authorization_keys found in .ssh which get created on instance initialization.
Also, the file ec2-init-user-data gets chmodded.
But the same file could be named ec2-init like i found on other distributions, so you should check it manually after mounting the volume.
Hope this helps a bit
When I run the following command (filling in my info where appropriate) I just get the help menu for the command. Does anyone see anything wrong? I’m not the most advanced command line person but everything else seemed to go fine.
ec2-register –snapshot snap-c070c5a9 –kernel aki-92ba58fb –ramdisk ari-94ba58fd –description=”EBS Ubuntu Hardy” –name=”–name=”ebs-ubuntu-hardy-8.04-i386-server-20091130″” –architecture i386 –root-device-name /dev/sda1
Ron,
It seems your command contains “-name” twice. Please recheck and let us know how it goes.
Good luck.
Ron – also it could be that you’re running the old version of the ec2 tools without support for boot from EBS.
I’ve tried this over and over again, I’ve got my volume and snapshot dialed, i can’t register the ami from it, whenever I run
ec2-register –snapshot snap-98bb4cf1 –kernel aki-7e0d250a –ramdisk ari-7d0d2509 –description=”my image” –name=”gentoo-stage3″ –architecture i386 –root-device-name /dev/sda1 –region eu-west-1
I get ec2reg/ec2-register usage information, no debugging info, no sign of success or reason of failure… it simply won’t work…
I’ve tried everything, including:
ec2-cmd RegisterImage -n my_image -s snap-98bb4cf1
Thanks for your response. So I took out the double name and ran this. I’ve looked at a lot of examples and tried some of them but…same result. This makes sense anyway. All of the other commands went well so I think my environment is good. Do I need an s3 bucket for this? Do I need to include a manifest? I’ve included the response output. Thanks for your help.
ec2-register –snapshot snap-6db3f004 –kernel aki-5f15f636 –ramdisk ari-0915f660 –description=”ebs based ami” –name=”abc-ami-ebs1″ –architecture i386 –root-device-name /dev/sda1 –region us-east-1d
SYNOPSIS
ec2reg (ec2-register)
ec2reg [GENERAL OPTIONS] MANIFEST
GENERAL NOTES
Any command option/parameter may be passed a value of ‘-’ to indicate
that values for that option should be read from stdin.
DESCRIPTION
Register an AMI manifest for use with EC2.
The MANIFEST parameter is the manifest (in S3) to register.
e.g. mybucketname/image.manifest
GENERAL OPTIONS
-K, –private-key KEY
Specify KEY as the private key to use. Defaults to the value of the
EC2_PRIVATE_KEY environment variable (if set). Overrides the default.
-C, –cert CERT
Specify CERT as the X509 certificate to use. Defaults to the value
of the EC2_CERT environment variable (if set). Overrides the default.
-U, –url URL
Specify URL as the web service URL to use. Defaults to the value of
‘https://ec2.amazonaws.com’ or to that of the EC2_URL environment
variable (if set). Overrides the default.
–region REGION
Specify REGION as the web service region to use.
This option will override the URL specified by the “-U URL” option and EC2_URL environment variable.
-v, –verbose
Verbose output.
-?, –help
Display this help.
-H, –headers
Display column headers.
–debug
Display additional debugging information.
–show-empty-fields
Indicate empty fields.
–connection-timeout TIMEOUT
Specify a connection timeout TIMEOUT (in seconds).
–request-timeout TIMEOUT
Specify a request timeout TIMEOUT (in seconds).
Rares,
Please run the command to check the ec2 tools version you have on your machines. It might be older version without support to EBS boot images as Mark stated above.
You can download the updated API tools here http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip
Hey you may be right.
When I run: ec2-version
I get: 1.3-36506 2009-04-04
I downloaded the latest (46266) and put it in /usr/local/ec2-api-tools-1.3-46266. I made that its home.If I run:
$EC2_HOME/bin/ec2-version
I get: 1.3-46266 2009-11-30
As I am just moving to Linux and trying to remember Unix commands from yesteryear I may be doing this wrong. Did I not install the latest ec2 api tools properly? Thanks…
All I needed was a nudge in the right direction. Worked great without the user malfunctions. Thanks….
Great article, helped plenty in moving images to EBS.
Some gotcha’s I faced: firstly the links to the script seemed to miss the instance-to-ebs (only grabbed the bundle-to-ebs). The rsync should also have –exclude=”exclude” with the inverts, otherwise get a nice mess in the target. also exclude “/sys/*”
Before the ec2-register phase, you need to wait for the snapshot to complete. You can hang around and watch, or stick it in:
while ! ec2-describe-snapshots $SNAP | grep -q completed; do
echo “Snapshot is `ec2-describe-snapshots $SNAP | awk ‘{print $6}’` complete”
done
Hi Brett,
Thanks for pointing that out.:)
Thanks for the quick rundown! Worked like a charm. Just wanted to clarify a point made above, which is that there are two typos in this line:
ec2-register –snapshot snap-c070c5a9 –kernel aki-92ba58fb –ramdisk ari-94ba58fd –description=”EBS Ubuntu Hardy” –name=”–name=”ebs-ubuntu-hardy-8.04-i386-server-20091130″” –architecture i386 –root-device-name /dev/sda1
The first is the ‘–name=”–name’ thing, and the second is that for –name and –description, you shouldn’t use equal signs, I don’t think. Anyway, thank you!
Thanks Jonah. Fixed.
[...] to create an EBS image from an existing AMI By cynikh A very good post on how to create an EBS Image from an existing AMI with inputs from developer forums. The rsync method worked for me than the dd method. For the DD [...]
Leave a comment