<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>My AWS Musings &#187; s3 image</title>
	<atom:link href="http://aws-musings.com/tag/s3-image/feed/" rel="self" type="application/rss+xml" />
	<link>http://aws-musings.com</link>
	<description>Cloud computing, EC2, RDS, SQS, S3, Java...</description>
	<lastBuildDate>Mon, 30 May 2011 18:13:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to create an ebs image from an existing ec2 instance</title>
		<link>http://aws-musings.com/how-to-create-an-ebs-image-from-an-existing-ec2-instance/</link>
		<comments>http://aws-musings.com/how-to-create-an-ebs-image-from-an-existing-ec2-instance/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 02:11:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[EBS]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[ebs backed instance]]></category>
		<category><![CDATA[ec2 image]]></category>
		<category><![CDATA[s3 image]]></category>
		<guid isPermaLink="false">http://aws-musings.com/?p=63</guid>
		<description><![CDATA[Amazon recently announced a new feature which allows you to boot from an ebs volume. But it doesn&#8217;t provide any tools to convert your existing AMIs to this new type of image. There is no easy way to create an ebs image from scratch. There are some posts that explain how to convert your existing [...]]]></description>
			<content:encoded><![CDATA[<p>Amazon recently announced a <a href="http://aws.amazon.com/about-aws/whats-new/2009/12/03/amazon-ec2-instances-now-can-boot-from-amazon-ebs/">new feature which allows you to boot from an ebs volume</a>.  But it doesn&#8217;t provide any tools to convert your existing AMIs to this new type of image. There is no easy way to create an ebs image from scratch. There are some posts that explain how to convert your existing AMI into this new type of image using ec2-unbundle and <a href="http://en.wikipedia.org/wiki/Dd_%28Unix%29">dd (a linux utility)</a>.  I am going to take a little different route and explain how we can create an ebs image from an existing instance. It&#8217;s fairly simple to create a new image using dd from an existing instance. </p>
<p><span id="more-63"></span><br />
Make sure that you have the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351">latest ec2 api tools</a> before you start creating and ebs type of image. Support for some of the commands (such as to register a snapshot as an image) is only available in the version 46266 onwards.</p>
<p>1) <a href="http://docs.amazonwebservices.com/AmazonEC2/dg/2006-10-01/CLTRG-run-instances.html">Launch an ec2 instance</a> from the image you want to convert to an ebs image. Make the changes (if any) you want to make to this instance. Let&#8217;s say that your instance id is i-xxxxxxxx</p>
<p>2) Launch an 10G ebs volume and attach it to this instance. You can create a bigger volume too. But currently the default size of Amazon&#8217;s ephemeral storage is 10G and hence a 10G volume should be sufficient for most of the people.<br />
The following code will launch an ebs volume and attach it to your instance. The code assumes that us-east-1a is the availability zone of your instance.<br />
<code><br />
ec2-create-volume --size 10 --availability-zone us-east-1a<br />
</code><br />
The command should give you an volume id in the form of  vol-yyyyyyyy. Note it down and use it in the next command to attach this volume to your instance.<br />
<code><br />
ec2-attach-volume vol-yyyyyyyy --instance i-xxxxxxxx --device /dev/sdh<br />
</code><br />
Create ext3 filesystem on this volume and mount the volume<br />
<code><br />
yes | mkfs -t ext3 /dev/sdh<br />
mkdir /mnt/ebsimage<br />
echo '/dev/sdh /mnt/ebsimage ext3 defaults,noatime 0 0' >> /etc/fstab<br />
mount /mnt/ebsimage<br />
</code><br />
3) Now that the volume is ready and mounted at /mnt/ebsimage, we are going to copy your entire disk to this volume using <a href="http://wiki.linuxquestions.org/wiki/Dd">dd (a linux disc imaging utility)</a>.<br />
<code><br />
nohup dd if=/dev/sda1 of=/dev/sdh &#038;<br />
</code><br />
The command above will start copying the disc to the ebs volume in background. This could take really long time (e.g. 20 minutes) depending upon your data. To check status of copying you will first need to get pid of the dd process by executing<br />
<code><br />
ps -aef | grep dd<br />
</code><br />
And then use the pid obtained in the following command<br />
<code><br />
kill -SIGUSR1 pid<br />
</code><br />
The above command will clearly print a message similar to<br />
<code><br />
531694080 bytes (532 MB) copied, 11.6338 seconds, 45.7 MB/s<br />
</code><br />
Please note that the message is printed by the dd process and not by the kill process. This means if you have your output redirected to somewhere else, the message will be printed there instead of your screen.</p>
<p>3) Once dd finishes, do a spot check on the data copied in /mnt/ebsimage. If you find everything ok, unmount the volume and detach the volume from the ec2 instance. You can use the following commands to do so:<br />
<code><br />
umount /mnt/ebsimage<br />
ec2-detach-volume vol-yyyyyyyy --instance i-xxxxxxxx<br />
</code></p>
<p>4) Now take the snapshot of the ebs volume.<br />
<code><br />
ec2-create-snapshot vol-yyyyyyyy<br />
</code></p>
<p>5) Register this snapshot as an image. Use the snapshot id obtained from the output of the above command.<br />
<code><br />
ec2reg -s snap-zzzzzzzz -a <em>x86_64</em> -d <em>Description</em> -n <em>imagename</em><br />
</code><br />
Make sure that you replace the snapshot id, image name, description and the image type (x86_86 or x86_64) in the command above.</p>
<p>That&#8217;s it! Your ebs image is ready. Simply launch your instance from this image exactly the same way you launch any other ec2 instance!</p>
]]></content:encoded>
			<wfw:commentRss>http://aws-musings.com/how-to-create-an-ebs-image-from-an-existing-ec2-instance/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

