<?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>Cognizant Transmutaion &#187; Sysadmin</title>
	<atom:link href="http://blog.ibd.com/tag/sysadmin/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ibd.com</link>
	<description>Internet Bandwidth Development: Composting the Internet for over Two Decades</description>
	<lastBuildDate>Fri, 18 Jun 2010 02:00:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Modyfying Jets3t S3 GUI tool to work with Walrus (Eucalyptus S3)</title>
		<link>http://blog.ibd.com/scalable-deployment/getting-the-jet3t-s3-gui-tool-to-work-with-walrus-eucalyptus-s3/</link>
		<comments>http://blog.ibd.com/scalable-deployment/getting-the-jet3t-s3-gui-tool-to-work-with-walrus-eucalyptus-s3/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 01:37:18 +0000</pubDate>
		<dc:creator>Robert J Berger</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Scalable Deployment]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Eucalyptus]]></category>
		<category><![CDATA[S3]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[Walrus]]></category>

		<guid isPermaLink="false">http://blog.ibd.com/?p=582</guid>
		<description><![CDATA[<p>Jets3t (pronounced &#8220;jet-set&#8221;) is a free, open-source Java toolkit and application suite for the Amazon Simple Storage Service (Amazon S3) and Amazon CloudFront content delivery network. For some reason almost all the standard tools for accessing S3 will not easily work with the Eucalyptus equivalent to S3 called Walrus. I am use to using the excellent [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jets3t.s3.amazonaws.com/index.html" target="_blank">Jets3t</a> (pronounced &#8220;jet-set&#8221;) is a free, open-source Java toolkit and application suite for the <a href="http://www.amazon.com/s3" target="_blank">Amazon Simple Storage Service (Amazon S3)</a> and <a href="http://www.amazon.com/cloudfront" target="_blank">Amazon CloudFront</a> content delivery network. For some reason almost all the standard tools for accessing S3 will not easily work with the <a href="http://open.eucalyptus.com/" target="_blank">Eucalyptus</a> equivalent to S3 called <a href="http://open.eucalyptus.com/wiki/EucalyptusWalrusInteracting_v1.6" target="_blank">Walrus</a>. I am use to using the excellent S3Fox add-on for Firefox and wanted some GUI tool that had similar capabilities. I was able to piece together how to get Jets3t to work with Eucalyptus Walrus. This article puts it all together in one place.</p>
<p>The basic build procedure is based on the <a href="http://bitbucket.org/jmurty/jets3t/wiki/Build_Instructions" target="_blank">instructions</a> for downloading and building Jet3t from Source. I got the hints for what to change to make things work with Walrus from the <a href="http://groups.google.com/group/jets3t-users/browse_thread/thread/49e1296ed110f0ab/6872154bfd96e8b8" target="_blank">Jets3t Users Forum article <em>eucalyptus walrus</em></a>. And an almost unrelated <a href="http://getsatisfaction.com/cloudera/topics/hadoop_in_eucalyptus_private_cloud" target="_blank">article <em>hadoop in eucalyptus private cloud</em></a> in the Cloudera Support Forum. Search on the page for the section that says <em>my jets3t file has these values</em>.</p>
<h2>Prerequisites</h2>
<p>These instructions assume you are on Ubuntu (I had 10.4 Lucid) though it should be easily modifiable to work on any platform that supports Java.</p>
<p>You&#8217;ll need to install</p>
<ul>
<li>Mercurial (hg)</li>
<li>Sun Java 6 (I couldn&#8217;t get it to work with openjdk-6)</li>
<li>Ant</li>
</ul>
<p>You can use the command:</p>
<pre><code>sudo apt-get install mercurial sun-java6-jdk ant1.8</code></pre>
<h2>Get the Source of Jets3t with Mercurial</h2>
<p>cd to where you want to create the directory that will contain the source. Then use the following command to create a local mercurial repository of the source. Then cd into the repository directory jets3t</p>
<pre><code>hg clone http://bitbucket.org/jmurty/jets3t/
cd jets3t
</code></pre>
<h2>Edit files to make jets3t work with Walrus</h2>
<p>Use your favorite editor (emacs of course <img src='http://blog.ibd.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  to make the following edits.</p>
<h3>Edit <code>LoginCredentialsPanel.java</code> to not check the length of login credentials</h3>
<p>Jets3t enforces the length of the Access Key and Access Secret Key. But some newer versions of Walrus do not fit the assumptions. This edit eliminates the checks.</p>
<p>This should be around line 230 of <code>src/org/jets3t/apps/cockpit/gui/LoginCredentialsPanel.java</code>. Comment out the lines that have <code>errors.add</code>. It should look something like the following after you comment out the two lines with <code>errors.add</code>.</p>
<pre><code>    if (getAWSAccessKey().length() == 20) {
        // Correct length for AWS Access Key
    } else if (getAWSAccessKey().length() == 22) {
        // Correct length for Eucalyptus ID
    } else {
        // errors.add("Access Key must have 20 or 22 characters");
	}

    if (getAWSSecretKey().length() == 40) {
        // Correct length for AWS Access Key
	} else if (getAWSSecretKey().length() == 38) {
        // Correct length for Eucalyptus Secret Key
	} else {
        //  errors.add("Secret Key must have 40 or 38 characters");
    }
</code></pre>
<h3>Edit <code>jets3t.properties</code> to use parameters for accessing Walrus instead of AWS S3</h3>
<p>You&#8217;ll want to set the following for Walrus access in <code>jets3t/configs/jets3t.properties</code>. The following are the values you need to change. s3service.s3-endpoint should be set to the fully qualified domain name of the host that runs Walrus (you could use an ip address I believe). I had to set s3service.https-only to false since I don&#8217;t know what it would take to set up SSL/TLS between the Java environment and the Walrus environment. If you do, let me know!</p>
<pre><code>
s3service.https-only=false
s3service.s3-endpoint=your_walrus_host_name
s3service.s3-endpoint-http-port=8773
s3service.s3-endpoint-https-port=8443
s3service.disable-dns-buckets=true
s3service.s3-endpoint-virtual-path=/services/Walrus
</code></pre>
<h3>Optionally edit <code>build.properties</code></h3>
<p>If you want to mark the build version in a way that distinguishes from the standard version and or change the debug level.<br />
I changed the version to <code>version=0.7.4-runa</code>.</p>
<h2>Build Jets3t with your changes to work with Walrus</h2>
<p>The following use the default target of <em>dist</em> which will create a target tree in the top level directory <em>dist</em>.</p>
<pre><code>ant
</code></pre>
<p>If that works (it will say <em>BUILD SUCCESSFUL</em> at the end if it was) then there will be a director <em>dist/jets3t-0.7.4-runa</em> (or whatever you set the version value to in build.properties). You should be able to:</p>
<pre><code>cd dist/jets3t-0.7.4-runa/bin
bash cockpit.sh &amp;
</code></pre>
<p>This should start up an application window and a window for you to enter your Eucalyptus credentials. Select the <em>Direct Login</em> tab and enter you Eucalyptus Access Key and Access Secret Key.</p>
<p><a href="http://blog.ibd.com/wp-content/uploads/2010/06/Cockpit-Login-1.jpg"></a><a href="http://blog.ibd.com/wp-content/uploads/2010/06/Cockpit-Login-2.jpg"><img class="aligncenter size-full wp-image-586" title="Jets3t Cockpit Login" src="http://blog.ibd.com/wp-content/uploads/2010/06/Cockpit-Login-2.jpg" alt="Jets3t Cockpit Login" width="499" height="399" /></a></p>
<p>After you click ok, you should see your Walrus buckets!</p>
<p><a href="http://blog.ibd.com/wp-content/uploads/2010/06/JetS3t-Cockpit-_-admin.jpg"><img class="aligncenter size-full wp-image-585" title="JetS3t Cockpit" src="http://blog.ibd.com/wp-content/uploads/2010/06/JetS3t-Cockpit-_-admin.jpg" alt="JetS3t Cockpit" width="799" height="555" /></a></p>
<p>Once it all works you can use the &lt;i&gt;Store Credentials&lt;/i&gt; option on the login window to store your credentials on Walrus and use a login/password to access Walrus. But that is optional.</p>
<div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ibd.com/scalable-deployment/getting-the-jet3t-s3-gui-tool-to-work-with-walrus-eucalyptus-s3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bonjour / AVAHI &amp; Netatalk to share files files between Ubuntu 10.4 &amp; Mac OS X</title>
		<link>http://blog.ibd.com/sysadmin/bonjour-avahi-netatalk-to-share-files-files-between-ubuntu-10-4-mac-os-x/</link>
		<comments>http://blog.ibd.com/sysadmin/bonjour-avahi-netatalk-to-share-files-files-between-ubuntu-10-4-mac-os-x/#comments</comments>
		<pubDate>Sun, 09 May 2010 05:57:08 +0000</pubDate>
		<dc:creator>Robert J Berger</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Macintosh]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.ibd.com/?p=574</guid>
		<description><![CDATA[<p>It use to be somewhat difficult to have Filesystems on an Ubuntu system show up on the Mac Finder the same way that other Mac Filesystems would show up. There has been the Open Source Unix implementation of the Apple File System (afp) but for a long time the Ubuntu packages were not properly configured to [...]]]></description>
			<content:encoded><![CDATA[<p>It use to be somewhat difficult to have Filesystems on an Ubuntu system show up on the Mac Finder the same way that other Mac Filesystems would show up. There has been the Open Source Unix implementation of the Apple File System (afp) but for a long time the Ubuntu packages were not properly configured to work transparently with modern (Snow Leopard) Mac OS X.</p>
<p>One blog post, <a href="http://www.kremalicious.com/2008/06/ubuntu-as-mac-file-server-and-time-machine-volume/" target="_blank">HowTo: Make Ubuntu A Perfect Mac File Server And Time Machine Volume</a> did a great job going through all the steps needed to build Netatalk from source and configure it to work very transparently with Ubuntu releases of the past. But with the Ubuntu 10.4 Lucid release, the Netatalk that is in the Ubuntu repository is built and configure to support transparent Apple File Protocol based file sharing.</p>
<p>But there are a few configuration issues, mainly with the Unix implementation of Bonjour resource discovery protocol, that still needs to be done to make it so you can see your Ubuntu Filesystems on your Mac&#8217;s Finder like other Macintosh instances. Also we&#8217;ll see how to make it so that the Ubuntu instance will show up as an ssh server as well.</p>
<h2>Installing Packages</h2>
<p>You will need to install the following packages onto your Ubuntu 10.4 instance. This assumes that you already did a clean install of Ubuntu 10.4 and used the update manager to bring it up to date. If you have already installed some of these, it should not be a problem.</p>
<h3>Install ssh server</h3>
<p>I can&#8217;t believe that ubuntu doesn&#8217;t install an ssh server by default. But in any case its pretty easy. This is not needed to use netatalk but I wanted to make ssh and netatalk to work and be available via bonjour.</p>
<pre><code>sudo apt-get install openssh-server</code></pre>
<p>Then you&#8217;ll need to set up your authorized keys on the ubuntu server. In your home directory do the following:</p>
<pre><code>mkdir -p .ssh
# Copy your public key[s] to .ssh/authorized_keys (not shown here)
# Set the permissions to only allow your user to access the .ssh directory and files in there
chmod -R og-rwx .ssh</code></pre>
<h3>Install Netatalk</h3>
<pre><code>sudo apt-get install netatalk</code></pre>
<h4>Configure Netatalk</h4>
<p>You don&#8217;t need to change any of the configuration files for netatalk. The defaults will enable the sharing of your home directory. If you want to share any additional filesystems from your Ubuntu instance to your Macs, you can add them to the <em>/etc/netatalk/AppleVolumes.default</em>. That file has explanations of al the options.</p>
<p>You may want to change the default last item in /etc/netatalk/AppleVolumes.default from:</p>
<pre>~/			"Home Directory"</pre>
<p>to something like:</p>
<pre>~/ "$h_$u Home Directory" options:upriv,usedots</pre>
<p>This will change the name that shows up in listing to be &#8220;<em>hostname_username Home Directory</em>&#8221; and will use Unix Privilages. Most importantly the usedots says to not do Hex translation of dot files. If you don&#8217;t do this, you&#8217;ll see things like<br />
<code>:2e_somefilename</code> instead of <code>.somefilename</code> where filenames start with &#8220;dot&#8221;.</p>
<h3>Configure AVAHI</h3>
<p>AVAHI is probably already installed if you did a standard installation.</p>
<p>Copy the avahi ssh service configuration into <em>/etc/avahi/services</em></p>
<pre><code>sudo cp /usr/share/doc/avahi-daemon/examples/ssh.service /etc/avahi/services/</code></pre>
<p>Create an avahi afpd service configuration by creating a file <em>/etc/avahi/services/afpd.service</em> with the following content:</p>
<pre><code>&lt;?xml version="1.0" standalone='no'?&gt;&lt;!--*-nxml-*--&gt;
&lt;!DOCTYPE service-group SYSTEM "avahi-service.dtd"&gt;
&lt;service-group&gt;
  &lt;name replace-wildcards="yes"&gt;%h&lt;/name&gt;
  &lt;service&gt;
    &lt;type&gt;_afpovertcp._tcp&lt;/type&gt;
    &lt;port&gt;548&lt;/port&gt;
  &lt;/service&gt;
  &lt;service&gt;
    &lt;type&gt;_device-info._tcp&lt;/type&gt;
    &lt;port&gt;0&lt;/port&gt;
    &lt;txt-record&gt;model=Xserve&lt;/txt-record&gt;
  &lt;/service&gt;
&lt;/service-group&gt;
</code></pre>
<p>You should now be able to see the Ubuntu host in your Finder under the SHARED section on the left side of the Finder. You should also see your Ubuntu host in the &#8220;New Remote Connection&#8221; window of the Mac Terminal app (CMD-SHIFT-K) if you select the &#8220;Secure Shell (ssh)&#8221; Service.</p>
<p>If you don&#8217;t see the Ubuntu hostname in the FInder or in the Terminal New Remote Connection service,  restart the avahi-daemon service:</p>
<pre><code>sudo restart avahi-daemon</code></pre>
<h2>TimeMachine Support</h2>
<p>The new Ubuntu Netatalk package is supposed to also support TimeMachine storage. You can enable this in <em>/etc/netatalk/AppleVolumes.default</em> and add <em>tm</em> as an option to the filesystems that is published in this file. I have not tried this and many sources consider this a risky way to store Time Machine backups.</p>
<h2>Troubleshooting</h2>
<p>You should make sure that there is at least one afpd process running on the Ubuntu instance. You can see the log info in <em>/var/log/daemon.log</em>.</p>
<p>That&#8217;s it!</p>
<div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ibd.com/sysadmin/bonjour-avahi-netatalk-to-share-files-files-between-ubuntu-10-4-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Copy an EBS AMI image to another Amazon EC2 Region</title>
		<link>http://blog.ibd.com/scalable-deployment/copy-an-ebs-ami-image-to-another-amazon-ec2-region/</link>
		<comments>http://blog.ibd.com/scalable-deployment/copy-an-ebs-ami-image-to-another-amazon-ec2-region/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 08:45:24 +0000</pubDate>
		<dc:creator>Robert J Berger</dc:creator>
				<category><![CDATA[Scalable Deployment]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.ibd.com/?p=551</guid>
		<description><![CDATA[<p>Since I&#8217;ve already created an image I liked in the us-west-1 region, I would like to reuse it in other regions. Turns out there is no mechanism within Amazon EC2 to do that. (See How do I launch an Amazon EBS volume from a snapshot across Regions?). I did find one post that talked a bit [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;ve already created an image I liked in the us-west-1 region, I would like to reuse it in other regions. Turns out there is no mechanism within Amazon EC2 to do that. (See <a href="http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/index.html?FAQ_Regions_Availability_Zones.html" target="_self">How do I launch an Amazon EBS volume from a snapshot across Regions?</a>). I did find <a href="http://citizen428.net/archives/420-Move-EC2-AMIs-between-regions.html" target="_self">one post</a> that talked a bit about how it can be done &#8220;out of band&#8221;. So I figured I would give that a try instead of doing a full recreation in the new region.</p>
<h2>Prepare the Source Instance and Volume</h2>
<h3>Start an instance in the source region</h3>
<p>Here I&#8217;ll start an instance in us-west-1a where I have the EBS image I want to copy. In this case I&#8217;ll use the image I want to copy, but it could be any image as long as its in the same region as the EBS AMI image that is to be copied. Though we are going to use the instance info to figure out some parameters for creating the new AMI. So if you don&#8217;t make the source instance the same AMI as the one you are copying you will need to supply some of the parameters yourself.</p>
<p>You can use a tool like ElasticFox to do the following creating of instances. Here we&#8217;ll do it with command line tools.</p>
<h3>Set some Shell source variables on host machine</h3>
<p>Just to make using these instructions as a cookbook, we&#8217;ll have some shell variables that you can set once and then all the instructions will use the variables so you can just cut and paste the instructions into your shell.</p>
<pre>src_keypair=id_runa-staging-us-west
src_fullpath_keypair=~/.ssh/runa/id_runa-staging-us-west
src_availability_zone=us-west-1a
src_instance_type=m1.large
src_region=us-west-1
src_origin_ami=ami-1f4e1f5a
src_device=/dev/sdh
src_dir=/src
src_user=ubuntu</pre>
<h3>Start up the source instance and capture the instanceid</h3>
<pre>src_instanceid=$(ec2-run-instances \
  --key $src_keypair \
  --availability-zone $src_availability_zone \
  --instance-type $src_instance_type \
  $src_origin_ami \
  --region $src_region  | \
  egrep ^INSTANCE | cut -f2)
echo "src_instanceid=$src_instanceid"

# Wait for the instance to move to the “running” state
while src_public_fqdn=$(ec2-describe-instances --region $src_region "$src_instanceid" | \
  egrep ^INSTANCE | cut -f4) &amp;&amp; test -z $src_public_fqdn; do echo -n .; sleep 1; done
echo src_public_fqdn=$src_public_fqdn</pre>
<p>This should loop till you see something like:</p>
<pre>$ echo src_public_fqdn=$src_public_fqdn
src_public_fqdn=ec2-184-72-2-93.us-west-1.compute.amazonaws.com</pre>
<h3>Create a volume from the EBS AMI snapshot</h3>
<p>Normally when starting an EBS AMI instance, it automatically created a volume from the snapshot associated with the AMI. Here we create the volume from the snapshot ourselves</p>
<pre># Get the volume id
ec2-describe-instances --region $src_region "$src_instanceid" &gt; /tmp/src_instance_info
src_volumeid=$(egrep ^BLOCKDEVICE /tmp/src_instance_info | cut -f3); echo $src_volumeid
# Now get the snapshot id from the volume id
ec2-describe-volumes --region $src_region $src_volumeid | egrep ^VOLUME &gt; /tmp/volume_info
src_snapshotid=$(cut /tmp/volume_info | cut -f2)
echo $src_snapshotid
src_size=$(cut /tmp/volume_info | cut -f2)
echo $src_size
# Create a new volume from the snapshot
src_volumeid=$(ec2-create-volume --region $src_region --snapshot $src_snapshotid -z $src_availability_zone | egrep ^VOLUME | cut -f2)
echo $src_volumeid</pre>
<h3>Mount the EBS Image of the AMI you want to copy</h3>
<p>Now we&#8217;ll mount the EBS AMI image as a plain mount on the running source instance. In this case we&#8217;re going to use the same image as we launched, but it doesn&#8217;t have to be the same image or even the same architecture.</p>
<pre>ec2-attach-volume --region $src_region $src_volumeid -i $src_instanceid -d $src_device</pre>
<p>You should see something like:</p>
<pre>ATTACHMENT	vol-6e7fee06	i-fb0804be	/dev/sdh	attaching	2010-03-14T09:02:58+0000</pre>
<h2>Prepare the Destination Instance and Volume</h2>
<h3>Set some Shell destination variables on host machine</h3>
<p>You&#8217;ll want to tune these to your needs. This example makes the destination size the same as the source. You could make the destination an arbitrary size as long as it fits the source data.</p>
<pre>dst_keypair=runa-production-us-east
dst_fullpath_keypair=~/.ssh/runa/id_runa-production-us-east
dst_availability_zone=us-east-1b
dst_instance_type=m1.large
dst_region=us-east-1
dst_origin_ami=ami-7d43ae14
dst_size=$src_size
dst_device=/dev/sdh
dst_dir=/dst
dst_user=ubuntu</pre>
<h3>Start up the destination instance and capture the dst_instanceid</h3>
<pre>dst_instanceid=$(ec2-run-instances \
  --key $dst_keypair \
  --availability-zone $dst_availability_zone \
  --instance-type $dst_instance_type \
  $dst_origin_ami \
  --region $dst_region  | \
  egrep ^INSTANCE | cut -f2)
echo "dst_instanceid=$dst_instanceid"

# Wait for the instance to move to the “running” state
while dst_public_fqdn=$(ec2-describe-instances --region $dst_region "$dst_instanceid" | \
  egrep ^INSTANCE | cut -f4) &amp;&amp; test -z $dst_public_fqdn; do echo -n .; sleep 1; done
echo dst_public_fqdn=$dst_public_fqdn</pre>
<p>This should loop till you see something like:</p>
<pre>$ echo dst_public_fqdn=$dst_public_fqdn
dst_public_fqdn=ec2-184-73-71-160.compute-1.amazonaws.com</pre>
<h3>Create an empty destination volume</h3>
<pre>dst_volumeid=$(ec2-create-volume --region $dst_region --size $dst_size -z $dst_availability_zone | egrep ^VOLUME | cut -f2)
echo $dst_volumeid</pre>
<h3>Mount the EBS Image of the AMI you want to copy</h3>
<p>Now we&#8217;ll mount the EBS AMI image as a plain mount on the running source instance. In this case we&#8217;re going to use the same image as we launched, but it doesn&#8217;t have to be the same image or even the same architecture.</p>
<pre>ec2-attach-volume --region $dst_region $dst_volumeid -i $dst_instanceid -d $dst_device</pre>
<p>You should see something like:</p>
<pre>ATTACHMENT	vol-450ed02c	i-65be1f0e	/dev/sdh	attaching	2010-03-14T09:39:20+0000</pre>
<h2>Copy the data from the Source Volume to the Destination Volume</h2>
<h3>Copy your credentials to the source machine</h3>
<p>We&#8217;re going to use rsync to copy from the source to the destination tunneled thru ssh. This eliminates any issues with EC2 security groups. But it does mean you have to copy an ssh private key to the source machine that will then be able to access the destination machine via ssh.</p>
<pre>scp -i $src_fullpath_keypair $dst_fullpath_keypair ${src_user}@${src_public_fqdn}:.ssh</pre>
<h3>Mount the source and destination volumes on their instances</h3>
<pre>ssh -i $src_fullpath_keypair ${src_user}@${src_public_fqdn} sudo mkdir -p $src_dir
ssh -i $src_fullpath_keypair ${src_user}@${src_public_fqdn} sudo mount $src_device $src_dir
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo mkfs.ext3 -F $dst_device
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo mkdir -p $dst_dir
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo mount $dst_device $dst_dir</pre>
<h3>Get the FQDN of the Amazon internal address of the destination machine</h3>
<p>We&#8217;re assuming that the dst instance is the us-east equivalent base AMI of the us-west source base AMI so we can use these kernel and ramdisk to build the new AMI later.</p>
<pre>ec2-describe-instances --region $dst_region "$dst_instanceid" &gt; /tmp/dst_instance_info
dst_internal_fqdn=$(egrep ^INSTANCE /tmp/dst_instance_info | cut -f5); echo $dst_internal_fqdn
dst_kernel=$(egrep ^INSTANCE /tmp/dst_instance_info | cut -f13); echo $dst_kernel
dst_ramdisk=$(egrep ^INSTANCE /tmp/dst_instance_info | cut -f14) ;echo $dst_ramdisk</pre>
<h2>Commands to run on the source machine</h2>
<p>You could do the rsync by logging into the source machine and do the following. I tried to do this by using ssh commands, but the fact that the first ssh from source to destination has to be authenticated was a blocker for me. You could log into the source machine and then sudo ssh to the destination machine (you have to do sudo ssh since the rsync has to be run with sudo and the keys are stored separately for the sudo user and the regular user).<br />
I&#8217;ll show both ways.<br />
Here&#8217;s how you can ssh to the source machine:</p>
<pre>ssh -i $src_fullpath_keypair ${src_user}@${src_public_fqdn}</pre>
<h3>Set up some shell variables on the source machine shell environment</h3>
<pre># This is the key you just copied over
dst_fullpath_keypair=~/.ssh/id_runa-production-us-east
# You need to use the Public FQDN of the destination since its cross region
dst_keypair=runa-production-us-east
src_public_fqdn=ec2-184-72-2-93.us-west-1.compute.amazonaws.com
dst_public_fqdn=ec2-184-73-71-160.compute-1.amazonaws.com
dst_user=ubuntu
src_user=ubuntu
src_dir=/src
dst_dir=/dst</pre>
<h3>Do the rsync</h3>
<p>We are using the rsync options</p>
<ul>
<li><strong>P</strong> Keep partial transferred files and Show Progress</li>
<li><strong>H</strong> Preserve Hard Links</li>
<li><strong>A</strong> Preserve ACLs</li>
<li><strong>X</strong> Preserve extended attributes</li>
<li><strong>a</strong> Archive mode</li>
<li><strong>z</strong> Compress files for transfer</li>
</ul>
<pre>rsync -PHAXaz --rsh "ssh -i /home/${src_user}/.ssh/id_${dst_keypair}" --rsync-path "sudo rsync" ${src_dir}/ ${dst_user}@${dst_public_fqdn}:${dst_dir}/</pre>
<h2>If you want to do the rsync from your local host</h2>
<p>I found that I still had to log into the source instance</p>
<pre>ssh -i $src_fullpath_keypair ${src_user}@${src_public_fqdn}</pre>
<p>and then on the source instance do:</p>
<pre>sudo ssh -i /home/${src_user}/.ssh/id_${dst_keypair} ${dst_user}@${dst_public_fqdn}</pre>
<p>and accept &#8220;<em>The authenticity of host</em>&#8221; for the first time so the destination host is in the known keys of the sudo user<br />
Then back on your local host you can issue the remote command that will run on the source instance and rsync to the destination host:</p>
<pre>ssh -i $src_fullpath_keypair ${src_user}@${src_public_fqdn} sudo "rsync -PHAXaz --rsh \"ssh -i /home/${src_user}/.ssh/id_${dst_keypair}\" --rsync-path \"sudo rsync\" ${src_dir}/ ${dst_user}@${dst_public_fqdn}:${dst_dir}/"</pre>
<h2>Complete the new AMI from your Local Host</h2>
<p>The remaining steps will be done back on your local host. This assumes that the shell variables we set up earlier are still there.</p>
<h3>Some Cleanup for new Region</h3>
<p>Ubuntu has their apt sources tied to the region you are in. So we have to update the apt sources for the new region.<br />
We&#8217;ll do this by chrooting to the mount /dst directory and running some commands as if they were being run on an ami with the /dst image. We might as well update things at the same time to the latest packages.</p>
<pre># Allow network access from chroot environment
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo cp /etc/resolv.conf $dst_dir/etc/

# Upgrade the system and install packages
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo -E chroot $dst_dir mount -t proc none /proc
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo -E chroot $dst_dir mount -t devpts none /dev/pts

cat &lt;&lt;EOF &gt; /tmp/policy-rc.d
#!/bin/sh
exit 101
EOF
scp -i $dst_fullpath_keypair /tmp/policy-rc.d ${dst_user}@${dst_public_fqdn}:/tmp
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo mv /tmp/policy-rc.d $dst_dir/usr/sbin/policy-rc.d

ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} chmod 755 $dst_dir/usr/sbin/policy-rc.d

# This has to be done to set up the Locale &amp; apt sources
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} DEBIAN_FRONTEND=noninteractive sudo -E chroot $dst_dir /usr/bin/ec2-set-defaults

# Update the apt sources
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} DEBIAN_FRONTEND=noninteractive sudo -E chroot $dst_dir apt-get update

# Optionally update the packages
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} DEBIAN_FRONTEND=noninteractive sudo -E chroot $dst_dir apt-get dist-upgrade -y

# Optionally update your gems
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo -E chroot $dst_dir gem update --system
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo -E chroot $dst_dir gem update</pre>
<h4>Clean up from the building of the image</h4>
<pre>ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo chroot $dst_dir umount /proc
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo -E chroot $dst_dir umount /dev/pts
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo -E rm -f $dst_dir/usr/sbin/policy-rc.d</pre>
<h3>There are a few more shell variables we&#8217;ll need</h3>
<p>I got the kernel and ramdisk from the destination instance since it has the alestic.com us-east-1 equivalent base AMI to the us-west-1 one that we are copying from.</p>
<pre># Some info for creating the name and description
codename=karmic
release=9.10
tag=server

# Make sure you set this as appropriate
# 64bit
arch=x86_64

# You will need to set the aki and ari values base on the actual base AMI you used
# It will be different for different regions.  These are set for x86_64 and us-east-1
ebsopts="--kernel=${dst_kernel} --ramdisk=${dst_ramdisk}"
ebsopts="$ebsopts --block-device-mapping /dev/sdb=ephemeral0"

now=$(date +%Y%m%d-%H%M)
# Make this specific to what you are making
chef_version="0.8.6"
prefix=runa-chef-${chef_version}-ubuntu-${release}-${codename}-${tag}-${arch}-${now}
description="Runa Chef ${chef_version} Ubuntu $release $codename $tag $arch $now"</pre>
<h3>Snapshot the Destination Volume and register the new AMI in the destination region</h3>
<pre># Unmount the destination filesystem
ssh -i $dst_fullpath_keypair ${dst_user}@${dst_public_fqdn} sudo umount $dst_dir

# Detach the Destination Volume (it may speed up the snapshot)
ec2-detach-volume --region $dst_region "$dst_volumeid"

# Make the snapshot
dst_snapshotid=$(ec2-create-snapshot -region $dst_region -d "$description" $dst_volumeid | cut -f2)

# Wait for snapshot to complete. This can take a while
while ec2-describe-snapshots --region $dst_region "$dst_snapshotid" | grep -q pending
  do echo -n .; sleep 1; done

# Register the Destination Snapshot as a new AMI in the Destination Region
new_ami=$(ec2-register \
  --region $dst_region \
  --architecture $arch \
  --name "$prefix" \
  --description "$description" \
  $ebsopts \
  --snapshot "$dst_snapshotid")
echo $new_ami</pre>
<h2>Conclusion</h2>
<p>You should now have a shiny new ami in your destination region. Use the value of $new_ami to start a new instance in your destination region using your favorite tool or technique.</p>
<div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ibd.com/scalable-deployment/copy-an-ebs-ami-image-to-another-amazon-ec2-region/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple update and clone an Amazon EC2 EBS Boot image</title>
		<link>http://blog.ibd.com/scalable-deployment/simple-update-and-clone-an-amazon-ec2-ebs-boot-image/</link>
		<comments>http://blog.ibd.com/scalable-deployment/simple-update-and-clone-an-amazon-ec2-ebs-boot-image/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 07:54:41 +0000</pubDate>
		<dc:creator>Robert J Berger</dc:creator>
				<category><![CDATA[Scalable Deployment]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.ibd.com/?p=533</guid>
		<description><![CDATA[Introduction
<p>Well there is already an update to Chef&#8217;s Ohai library. At first I thought, &#8220;Oh no, I have to generate another EC2 image&#8221;. But then I remember reading that you can update and clone a running EBS boot image.</p>
<p>One of the cool features of using an Amazon EC2 instance that boots from an EBS Snapshot is [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Well there is already an update to Chef&#8217;s Ohai library. At first I thought, &#8220;Oh no, I have to generate another EC2 image&#8221;. But then I remember reading that you can update and clone a running EBS boot image.</p>
<p>One of the cool features of using an Amazon EC2 instance that boots from an EBS Snapshot is that its easy to create new boot images from an existing running EC2 instance, assuming that you are running an EC2 instance that is itself bootable from an EBS Image.</p>
<h2>Prerequisites</h2>
<p>The following expects that you have a recent copy of the Amazon ec2-api-tools on the instance and that you have recent version of the ec2-api-tools on your host development system.</p>
<h2>Start up an instance, make changes</h2>
<p>Start up an instance you can use as a base, for instance the one we created in Using the Official Opscode 0.8.x Gems to build EC2 AMI Chef Client and Server</p>
<h3>Get the name of the instance</h3>
<p>First you will need the instance name of your instance you want to copy. You can use Elasticfox or other tool. Or run the following command on the instance:</p>
<pre>wget -qO- http://instance-data/latest/meta-data/instance-id</pre>
<h2>On another host</h2>
<p>The rest of the instructions will be run on your host development system (not the system you are copying). This makes it so you don&#8217;t have to put your Amazon Certs onto the machine you are cloning (you don&#8217;t want those keys to end up on the cloned image)</p>
<h3>Create some shell defines</h3>
<p>To make the instructions easier make some defines we&#8217;ll use in commands. Tune them for your environment.</p>
<pre># This will be the instance id of the running instance you want to clone
instanceid=i-07202042

# Some info for creating the name and description
codename=karmic
release=9.10
tag=server
region=us-west-1
availability_zone=us-west-1a

# Make sure you set this as appropriate
# 64bit
arch=x86_64
arch2=amd64
#32bit
arch=i386
arch2=i386
now=$(date +%Y%m%d-%H%M)

# Make this specific to what you are making
prefix=runa-chef-0.8.4-ubuntu-$release-$codename-$tag-$arch-$now
description="Runa Chef 0.8.4 Ubuntu $release $codename $tag $arch $now"</pre>
<h3>Get the info  about your running instance</h3>
<p>Use Elasticfox or your favorite tool or the following command to get the volume id of the instance</p>
<pre>ec2-describe-instances --region $region "$instanceid" &gt; /tmp/instance_info
volumeid=$(egrep ^BLOCKDEVICE /tmp/instance_info | cut -f3); echo $volumeid
kernel=$(egrep ^INSTANCE /tmp/instance_info | cut -f13); echo $kernel
ramdisk=$(egrep ^INSTANCE /tmp/instance_info | cut -f14) ;echo $ramdisk</pre>
<h3>Shutdown  the instance</h3>
<p>Its not clear if you really need to do this. But when I first tried doing it without shuting down the instance, the snapshots took forever.</p>
<h3>Create a new snapshot</h3>
<pre>snapshotid=$(ec2-create-snapshot -region $region -d "$description" $volumeid | cut -f2)</pre>
<h3>Register the new image</h3>
<pre>ec2reg --region $region -s $snapshotid -a $arch --kernel $kernel --ramdisk $ramdisk -d "$description" -n "$prefix"</pre>
<p>The result of this command will be the ami image name. After this completes, the image and snapshot can be used to create new instances.</p>
<div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ibd.com/scalable-deployment/simple-update-and-clone-an-amazon-ec2-ebs-boot-image/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
