<?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>IONCANNON &#187; ec2</title>
	<atom:link href="http://www.ioncannon.net/tag/ec2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ioncannon.net</link>
	<description>Thoughts on Software Development and Engineering</description>
	<lastBuildDate>Tue, 03 Jan 2012 13:59:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<atom:link rel='hub' href='http://www.ioncannon.net/?pushpress=hub'/>
		<item>
		<title>Minimal EC2 Linux Install Using TTYLinux</title>
		<link>http://www.ioncannon.net/system-administration/1310/minimal_ec2_linux_install_using_ttylinux/</link>
		<comments>http://www.ioncannon.net/system-administration/1310/minimal_ec2_linux_install_using_ttylinux/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 17:22:10 +0000</pubDate>
		<dc:creator>carson</dc:creator>
				<category><![CDATA[system administration]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ttylinux]]></category>

		<guid isPermaLink="false">http://www.ioncannon.net/?p=1310</guid>
		<description><![CDATA[If you have ever wondered how to get a Linux EC2 node down to the bare minimum this post is for you. I have been wanting to do this for a long time but it wasn&#039;t possible until pv-grub support that was added recently. To make this even more exciting Amazon now offers EC2 micro [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever wondered how to get a Linux EC2 node down to the bare minimum this post is for you. I have been wanting to do this for a long time but it wasn&#039;t possible until pv-grub support that was added recently. To make this even more exciting Amazon now offers <a href="http://aws.typepad.com/aws/2010/09/new-amazon-ec2-micro-instances.html">EC2 micro instances</a> that will go well with this type of bare bones system.</p>
<p>You may wonder why you would want to do this. I&#039;ll give you at least two reasons. First there is speed. The configuration I ended up with will boot in about 14 seconds. Almost all of that time is spent waiting on the AWS DHCP server for an IP address. The second reason is security. There is little on this system that you don&#039;t need. The majority of what you need is provided by a single application that you can easily monitor for patches. That leaves you to worry about only the tools you must have to get your job done. I&#039;ll also include a couple downsides. First this isn&#039;t going to be easy for everyone and it can be fairly complicated. The second issue you will run into is that there is nothing in this distribution. If you need something like PHP you might spend a long time building all the support you need. There isn&#039;t much to be done about the complexity if you want to do this all yourself. Selection of tools can help you lessen the impact of the bare nature of the system, more on that in a future post.</p>
<p><span id="more-1310"></span></p>
<p>I picked <a href="http://minimalinux.org/ttylinux/">TTYLinux</a> because that is what I&#039;m most familiar with. I have used it a number of times and I believe it may be the most basic of all the small Linux distros. It really is bare and the large majority of the features are provided by <a href="http://www.busybox.net/">BusyBox</a>. Before attempting to build your own instance it may help to read some of the TTYLinux documentation. Although I haven&#039;t tried I assume that other small distros like DSL would probably work with the same general instructions.</p>
<p>A couple important prerequisites are needed before starting this. First look at the How_To_Build_ttylinux.txt file that comes with the TTYLinux source. It contains a lot of information about how you go about building the system. Next look at my post on <a href="http://www.ioncannon.net/system-administration/1290/how-to-build-compile-a-custom-linux-kernel-for-ec2/">compiling the Linux kernel for EC2</a> because you will need to do that for this TTYLinux instance. Finally you need to have to have gcc, g++ and yacc available on the machine you are going to use to build on.</p>
<p>I have also created a public AMI that anyone can use with the name TTYLinuxBase and AMI ID of ami-0cfe0b65. Be sure to boot it with the correct hd0 kernel for your region. The password for root on this AMI is just password so be sure to change it when you fire it up. I have created the AMI so that the EBS volume gets deleted when it is terminated.</p>
<ol>
<li>Grab the source from <a href="http://minimalinux.org/ttylinux/source.html">the TTYLinux source page</a>:
<pre class="brush: plain; title: ; notranslate">
wget http://minimalinux.org/ttylinux/Download/ttylinux-src-mp3.tar.bz2
tar xvjf ttylinux-src-mp3.tar.bz2
</pre>
</li>
<li>The kernel that comes with the current version of TTYLinux isn&#039;t new enough to work on EC2 so the configuration and build scripts need to be changed to get a more recent version that will. The first step is to create a kernel configuration and put it in the correct location:
<pre class="brush: plain; title: ; notranslate">
ttylinux-src-mp3/config/platform_pc/kernel-2.6.35.4-i686.cfg
</pre>
<p>You can create this configuration by doing a make menuconfig on the kernel you want to use and then saving the kernel configuration to a file. You may also download the <a href="http://www.ioncannon.net/examples/ec2ttylinux/kernel-2.6.35.4-i686.cfg">kernel config</a> I used:</p>
<pre class="brush: plain; title: ; notranslate">
wget http://www.ioncannon.net/examples/ec2ttylinux/kernel-2.6.35.4-i686.cfg
cp kernel-2.6.35.4-i686.cfg ttylinux-src-mp3/config/platform_pc/kernel-2.6.35.4-i686.cfg
</pre>
<p>There is a lot of the kernel that can be pruned from the kernel configuration so if you do this by hand take time to turn things off that you won&#039;t need. Doing so will speed up the kernel compile and make the system boot faster. The above kernel configuration is pruned down quite a bit.
</li>
<li>Copy the packages configuration to one that matches the kernel version:
<pre class="brush: plain; title: ; notranslate">
cp ttylinux-src-mp3/config/platform_pc/packages-2.11-2.6.30.5.txt ttylinux-src-mp3/config/platform_pc/packages-2.11-2.6.35.4.txt
</pre>
</li>
<li>Modify the kernel build script to apply the XSAVE patch. Start by adding the following line to line 132 of the ttylinux-src-mp3/scripts/build-kernel.sh build script:
<pre class="brush: plain; title: ; notranslate">
patch -p1 &lt; /tmp/kernel.patch
</pre>
<p>You should end up with the following around it:</p>
<pre class="brush: plain; title: ; notranslate">
echo -n &quot;b.&quot; &gt;&amp;${CONSOLE_FD}
cp &quot;${kcfg}&quot; &quot;linux-${kver}/.config&quot;
cd &quot;linux-${kver}&quot;
patch -p1 &lt; /tmp/kernel.patch
sed --in-place scripts/mod/sumversion.c \
        --expression=&quot;s|&lt;string.h&gt;| &lt;limits.h&gt;\n#include &lt;string.h&gt;|&quot;
source &quot;${TTYLINUX_XTOOL_DIR}/_xbt_env_set&quot;
</pre>
<p>Create the patch file /tmp/kernel.patch with the following in it:</p>
<pre class="brush: plain; title: ; notranslate">
--- a/arch/x86/xen/enlighten.c  2010-08-05 20:35:13.000000000 -0400
+++ b/arch/x86/xen/enlighten.c  2010-08-05 20:35:22.000000000 -0400
@@ -776,6 +776,7 @@
 {
 	cr4 &amp;= ~X86_CR4_PGE;
 	cr4 &amp;= ~X86_CR4_PSE;
+	cr4 &amp;= ~X86_CR4_OSXSAVE;

 	native_write_cr4(cr4);
 }
</pre>
<p>Note that the above patch file has tabs in it. Make sure there is a tab before each cr4 line and the native_write_cr4 line or download the <a href="http://www.ioncannon.net/examples/ec2ttylinux/kernel.patch">kernel patch</a> file I created.
</li>
<li>Select the correct build target in the ttylinux-src-mp3/ttylinux.dist-config.sh file. Find the TTYLINUX_TARGET lines, comment them all out and then add the following line:
<pre class="brush: plain; title: ; notranslate">
TTYLINUX_TARGET=&quot;i686:pc:2.11-2.6.35.4&quot;
</pre>
</li>
<li>Set up the cross compile tools build directory:
<pre class="brush: plain; title: ; notranslate">
cp -Rp ttylinux-src-mp3/cross-tools-2.11-2.6.30.5/ ttylinux-src-mp3/cross-tools-2.11-2.6.35.4/
</pre>
<p>Find XBT_KERNEL in the script ttylinux-src-mp3/cross-tools-2.11-2.6.35.4/_scripts/xbt-versions.sh and change it to:</p>
<pre class="brush: plain; title: ; notranslate">
XBT_KERNEL=&quot;linux-2.6.35.4&quot;
</pre>
</li>
<li>Build the cross compile tools:
<pre class="brush: plain; title: ; notranslate">
cd ttylinux-src-mp3/cross-tools-2.11-2.6.35.4
make setup
make dload
make i686
cd ..
</pre>
</li>
<li>Build the entire TTYLinux distro:
<pre class="brush: plain; title: ; notranslate">
make dist
</pre>
<p>From this point the instructions are just like the last few posts I have made. The distribution created in here needs to be transferred to an EBS volume and made into an AMI.
</li>
<li>Using a temporary EC2 instance create a volume that will be used to boot the install and give it a file system:
<pre class="brush: plain; title: ; notranslate">
ec2-create-volume -z us-east-1a -s 1
ec2-attach-volume volume-id -i instance-id -d /dev/sdh
mkfs.ext3 /dev/sdh
</pre>
</li>
<li>Transfer the TTYLinux distribution image that was created to the temporary EC2 instance. Then copy the image to the boot volume:
<pre class="brush: plain; title: ; notranslate">
mkdir /mnt/dest
mkdir /mnt/src
mount /dev/sdh /mnt/dest
mount -o loop img/file_sys-i686-11.2.img /mnt/src
cd /mnt/src
find . | cpio -pvd /mnt/dest
cd -
cp config/boot/* /mnt/dest/boot/
umount /mnt/src
</pre>
<p>In the above the boot volume is mounted, the TTYLinux distribution image is mounted via a loop device and then all the files are copied from the image to the boot volume. I do a copy here because the default boot image that the TTYLinux build creates is only 8M and the smallest EBS volume you can create is 1G so it is better to use what you have to have.
</li>
<li>While the boot volume is mounted there are a number of things that need to be configured that are different than some of the previous examples of booting custom systems in EC2. First set the password for root by using chroot:
<pre class="brush: plain; title: ; notranslate">
chroot /mnt/dest/ passwd
</pre>
<p>Next change the root device in fstab:</p>
<pre class="brush: plain; title: ; notranslate">
cat &lt;&lt;EOF &gt; /mnt/dest/etc/fstab
/dev/xvda1    /            ext3       defaults                      0 0
tmpfs         /dev         tmpfs      noauto                        0 0
devpts        /dev/pts     devpts     gid=5,mode=0620               0 0
tmpfs         /dev/shm     tmpfs      rw,noexec,nosuid,size=24k     0 0
proc          /proc        proc       noauto                        0 0
sysfs         /sys         sysfs      noauto                        0 0
EOF
</pre>
<p>Then modify the inittab to only create one terminal:</p>
<pre class="brush: plain; title: ; notranslate">
cat &lt;&lt;EOF &gt; /mnt/dest/etc/inittab
::sysinit:/etc/rc.d/rc.sysinit

tty1::respawn:/sbin/getty 38400 tty1

::ctrlaltdel:/sbin/reboot
::shutdown:/etc/rc.d/rc.sysdone
EOF
</pre>
<p>Then configure the network to start on boot:</p>
<pre class="brush: plain; title: ; notranslate">
cat &lt;&lt;EOF &gt; /mnt/dest/etc/sysconfig/network-scripts/ifcfg-eth0
ENABLE=yes
NAME=Ethernet
IPADDRESS=192.168.1.20
CIDRLEN=24
NETWORK=192.168.1.0
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
BROADCAST=192.168.1.255
DHCP=yes
EOF
</pre>
<p>Finally, If you want to get rid of the warnings about setting the hardware clock you can edit /mnt/dest/etc/rc.d/rc.sysdone and comment out the part that tries to set it:</p>
<pre class="brush: plain; title: ; notranslate">
# Disabled for XenU use
#if [[ &quot;$(uname -m)&quot; != armv5tej* ]]; then
#     action $&quot;syncing hardware clock to system time&quot; hwclock ${HWCLOCKARGS}
#fi
</pre>
<p>and you will also want to do the same to /mnt/dest/etc/rc.d/rc.sysinit:</p>
<pre class="brush: plain; title: ; notranslate">
# Disabled for XenU
#if [[ &quot;$(uname -m)&quot; != armv5tej* ]]; then hwclock ${HWCLOCKARGS}; fi
</pre>
</li>
<li>To tell pv-grub what to boot you will need a /boot/grub/menu.lst file with the following in it:
<pre class="brush: plain; title: ; notranslate">
mkdir /mnt/dest/boot/grub

cat &lt;&lt;EOF &gt; /mnt/dest/boot/grub/menu.lst
default 0
timeout 0
title TTYOS
        root (hd0)
        kernel /boot/vmlinuz root=/dev/xvda1
EOF
</pre>
<p>Unmount the boot image:</p>
<pre class="brush: plain; title: ; notranslate">
umount /mnt/dest/
</pre>
</li>
<li>Snapshot the volume and register it as an AMI:
<pre class="brush: plain; title: ; notranslate">
ec2-create-snapshot -d &quot;Volume Description&quot; volume-id
ec2-register -n &quot;AMIName&quot; -d &quot;AMI Description&quot; --root-device-name /dev/sda1 -b /dev/sda1=snap-id:1:true
</pre>
</li>
<li>Boot it using the hd0 kernel for your region (in my case that is aki-407d9529):
<pre class="brush: plain; title: ; notranslate">
ec2-run-instances -z us-east-1a -g your-group -k your-keypair -n 1 --kernel pv-grub-kernel-id ami-from-step-13
</pre>
</li>
</ol>
<p>There are a few final notes that might be interesting. The smallest you can create is 1G and that is about 950M too large. This is probably not a real issue since you will most likely want space to put your application but it is interesting to note. The instructions assume you are building a i386 instance but they are almost the same for a 64 bit instance.</p>
<p>With the kernel config I provide you will see boot times from start to init in about 0.3 seconds. That is pretty fast. From init to login is fast as well but depends completely on how long it takes to get an IP from the DHCP server. This type of system could potentially boot in just a second or two if it didn&#039;t have to wait for any AWS parts.</p>
<p>A few people have created <a href="http://minimalinux.org/ttylinux/addons.html">TTY addons</a> to make compiling code for TTYLinux easier. You may want to check those out. Baring that you will find instructions on building anything with the cross compiling system in the TTYLinux howto documentation. Of course you may be able to bypass any pain there by compiling static binaries or even using something like Java.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ioncannon.net/system-administration/1310/minimal_ec2_linux_install_using_ttylinux/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Build and Compile a Custom Linux Kernel for EC2</title>
		<link>http://www.ioncannon.net/system-administration/1290/how-to-build-compile-a-custom-linux-kernel-for-ec2/</link>
		<comments>http://www.ioncannon.net/system-administration/1290/how-to-build-compile-a-custom-linux-kernel-for-ec2/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 14:55:58 +0000</pubDate>
		<dc:creator>carson</dc:creator>
				<category><![CDATA[system administration]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.ioncannon.net/?p=1290</guid>
		<description><![CDATA[I have a long running goal that I&#039;m trying to reach with all these pv-grub for EC2 posts. That goal is to find the smallest/tightest usable node that can be created for EC2. The next step in that path requires a custom Linux kernel. What follows is how to build the latest Linux kernel so [...]]]></description>
			<content:encoded><![CDATA[<p>I have a long running goal that I&#039;m trying to reach with all these <a href="http://aws.typepad.com/aws/2010/07/use-your-own-kernel-with-amazon-ec2.html">pv-grub for EC2</a> posts. That goal is to find the smallest/tightest usable node that can be created for EC2. The next step in that path requires a custom Linux kernel. What follows is how to build the latest Linux kernel so that it works on EC2 using pv-grub.</p>
<p>It is important to have a recent kernel since most of what is needed to get a kernel to work on EC2 is now incorporated into the source. These instructions assume the latest kernel is 2.6.35.4 and I&#039;ve used them with 2.6.35 as well but keep that in mind since the one patch that is required could eventually be merged in. Before getting started it may help to read over how to <a href="http://www.faqs.org/docs/Linux-HOWTO/Kernel-HOWTO.html">compile the Linux kernel</a> normally and then my post on <a href="http://www.ioncannon.net/system-administration/1205/installing-cent-os-5-5-on-ec2-with-the-cent-os-5-5-kernel/">running CentOS 5.5 on EC2 using pv-grub</a>.</p>
<p><span id="more-1290"></span></p>
<p>Before you begin you will need a place to build the kernel. For these instructions I used an EC2 instance to build the kernel but you don&#039;t have to. I also installed the kernel on the same EC2 instance when I was done. The AMI I used was Amazon&#039;s EBS boot starter ( ami-b232d0db : amazon/getting-started-with-ebs-boot ).</p>
<p>The following steps go over building and installing the kernel in detail:</p>
<ol>
<li>Download the latest <a href="http://www.kernel.org/">Linux kernel</a> or the version I&#039;m using:
<pre class="brush: plain; title: ; notranslate">
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.35.4.tar.bz2
</pre>
</li>
<li>Configure the source to run on EC2:
<pre class="brush: plain; title: ; notranslate">
make menuconfig
</pre>
<p>You will need to make sure the following options are set in the configuration:</p>
<ul>
<li>&#034;Processor type and features&#034; -> &#034;High Memory Support&#034; -> Make sure it is set to 64GB</li>
<li>&#034;Processor type and features&#034; -> &#034;PAE (Physical Address Extension) Support&#034; -> enable</li>
<li>&#034;Processor type and features&#034; -> &#034;Paravirtualized guest support&#034; -> enable</li>
<li>&#034;Processor type and features&#034; -> &#034;Paravirtualized guest support&#034; -> &#034;Xen guest support&#034; -> enable</li>
<li>&#034;Device Drivers&#034; -> &#034;Block devices&#034; -> &#034;Xen virtual block device support&#034; -> enable either as a module or built in</li>
<li>&#034;Device Drivers&#034; -> &#034;Network device support&#034; -> &#034;Xen network device frontend driver&#034; -> enable either as a module or built in</li>
</ul>
<p> <br/></p>
<p>If you want you can make the device drivers modules but you have to have them so it is probably best to just compile them into the kernel itself. If you want to compare your config file with the one I used you can download mine here: <a href="http://www.ioncannon.net/examples/ec2kernel/kernel-2.6.35.4-i686.config">kernel-2.6.35.4-i686.config</a>.</p>
<p>The starter AMI I used needed ncurses development libraries and gcc installed for menuconfig to work:</p>
<pre class="brush: plain; title: ; notranslate">
yum install ncurses-devel gcc
</pre>
<p>If you want to know a little more about what is being enabled in this step see the &#034;Building with domU support&#034; section of <a href="http://wiki.xensource.com/xenwiki/XenParavirtOps">XenParavirtOps</a>.
</li>
<li>Apply the following patch to disable XSAVE:
<pre class="brush: plain; title: ; notranslate">
--- a/arch/x86/xen/enlighten.c	2010-08-05 20:35:13.000000000 -0400
+++ b/arch/x86/xen/enlighten.c	2010-08-05 20:35:22.000000000 -0400
@@ -776,6 +776,7 @@
 {
 	cr4 &amp;= ~X86_CR4_PGE;
 	cr4 &amp;= ~X86_CR4_PSE;
+	cr4 &amp;= ~X86_CR4_OSXSAVE;

 	native_write_cr4(cr4);
 }

cd /path/to/root/of/kernel/source

patch -p1 &lt; /tmp/kernel.patch
</pre>
<p>Note that the above patch file has tabs in it. Make sure there is a tab before each cr4 line and the native_write_cr4 line. If you want to you can download a copy of the <a href="http://www.ioncannon.net/examples/ec2kernel/kernel.patch">patch with the tabs in it</a> to be sure.
</li>
<li>Build the kernel and install it if you are on the same machine you want to install it on. If you need help compiling the kernel refer to the kernel compile howto. <br/><br/>
<p>After this step you have a kernel, modules and initrd that you can use. The remaining steps go over using it.
</li>
<li>Configure the /boot/grub/menu.lst file on the target AMI to use the new kernel, the following is an example of the contents of the file:
<pre class="brush: plain; title: ; notranslate">
default 0
timeout 1
title Test
     root (hd0)
     kernel /boot/vmlinuz-2.6.35.4 root=/dev/xvda1
     initrd /boot/initrd-2.6.35.4.img
</pre>
<p>Note that the root device here is /dev/xvda1 instead of /dev/sda1. This is caused by the XSAVE patch.
</li>
<li>Verify that your /etc/fstab file is correct. If your previous root device was /dev/sda1 it is going to be /dev/xvda1 now. The contents of the fstab file I used follow:
<pre class="brush: plain; title: ; notranslate">
/dev/xvda1                              /                       ext3    defaults 1 1
/dev/mapper/swapVG-swapFS               swap                    swap    defaults 0 0
/dev/mapper/storageVG-storageFS         /mnt                    ext3    defaults 0 0
none                                    /dev/pts                devpts  gid=5,mode=620 0 0
none                                    /dev/shm                tmpfs   defaults 0 0
none                                    /proc                   proc    defaults 0 0
none                                    /sys                    sysfs   defaults 0 0
</pre>
</li>
<li>Make a snapshot of the volume and register it as an AMI:
<pre class="brush: plain; title: ; notranslate">
ec2-create-snapshot -d &quot;Snapshot Description&quot; volume-id
ec2-register -n &quot;CustomKernel&quot; -d &quot;Custom kernel AMI&quot; --root-device-name /dev/sda1 -b /dev/sda1=snap-id:15:true
</pre>
<p>Note that the devices here are /dev/sda1 and not /dev/xvda1. That is a little confusing but the AWS system doesn&#039;t see the devices in the same way your AMI will once it is booted.
</li>
<li>Start the instance. In my case using the hd0 pv-grub kernel:
<pre class="brush: plain; title: ; notranslate">
ec2-run-instances -z us-east-1a -g your-group -k your-keypair -n 1 --kernel aki ami-from-step-7
</pre>
</li>
</ol>
<p>If all goes well you should be able to run dmesg and see a boot message something like the following at the top:</p>
<pre class="brush: plain; title: ; notranslate">
Reserving virtual address space above 0xf5800000
Linux version 2.6.35.4 (root@domU) (gcc version 4.1.2 20070925 (Red Hat 4.1.2-33)) #2 SMP Mon Aug 23 20:00:01 EDT 2010
BIOS-provided physical RAM map:
 Xen: 0000000000000000 - 00000000000a0000 (usable)
 Xen: 00000000000a0000 - 0000000000100000 (reserved)
 Xen: 0000000000100000 - 000000006a400000 (usable)
NX (Execute Disable) protection: active
...
</pre>
<p>With the ability to create a custom kernel for EC2 the next step is to prune the OS itself down to the bare minimum.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ioncannon.net/system-administration/1290/how-to-build-compile-a-custom-linux-kernel-for-ec2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Converting from VirtualBox or VMWare to EC2 now Easier than Ever</title>
		<link>http://www.ioncannon.net/system-administration/1246/converting-from-virtualbox-or-vmware-to-ec2-now-easier-than-ever/</link>
		<comments>http://www.ioncannon.net/system-administration/1246/converting-from-virtualbox-or-vmware-to-ec2-now-easier-than-ever/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 13:19:48 +0000</pubDate>
		<dc:creator>carson</dc:creator>
				<category><![CDATA[system administration]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[VirtualBox]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://www.ioncannon.net/?p=1246</guid>
		<description><![CDATA[The new PV-Grub ability introduced by Amazon for EC2 has opened the door for more than just custom kernels, it also makes it a lot easier to turn VirtualBox and VMWare instances into EC2 instances. In the past I have written about transfering VirtualBox images to Xen but to do that with EC2 required a [...]]]></description>
			<content:encoded><![CDATA[<p>The new PV-Grub ability introduced by Amazon for EC2 has opened the door for more than just custom kernels, it also makes it a lot easier to turn <a href="http://www.virtualbox.org/">VirtualBox</a> and <a href="http://www.vmware.com/">VMWare</a> instances into EC2 instances. In the past I have written about <a href="http://www.ioncannon.net/system-administration/80/how-to-transfer-linux-from-virtualbox-to-xen/">transfering VirtualBox images to Xen</a> but to do that with EC2 required a matching kernel exist for your VirtualBox installed OS that was blessed by Amazon. With PV-Grub as long as you can get a kernel for your existing system that is compatible with the EC2 infrastructure you can transfer it. A lot of the most popular distributions already have compatible kernels so that shouldn&#039;t be an issue and if you had to you could always compile the kernel by hand.</p>
<p>Some of what follows is exactly the same as my post about <a href="http://www.ioncannon.net/system-administration/1205/installing-cent-os-5-5-on-ec2-with-the-cent-os-5-5-kernel/">installing CentOS 5.5 on EC2 with the stock kernel</a>. Once you get the hang of it you can install just about anything Linux based to EC2. I&#039;ve broken this post into two parts to try and separate the generic transfer information from the specifics of an example. The first part that goes over the basics of what needs to be done to transfer any VirtualBox or VMWare box to EC2. The second part is an example of transferring an Ubuntu Server install to from VirtualBox to EC2. </p>
<p><span id="more-1246"></span></p>
<p>The following steps should work for any Linux OS but the main sticking point is that the kernel needs to be compatible with EC2 (see the <a href="http://aws.typepad.com/aws/2010/07/use-your-own-kernel-with-amazon-ec2.html">anouncment</a> for a list of some distros that have compatible kernels and remember you can always compile by hand as well).</p>
<ol>
<li>Make sure your VirtualBox or VMWare install has a kernel that is able to boot on EC2.</li>
<li>Make sure you have grub installed and set up your /boot/grub/menu.lst file to point to the correct Xen kernel and initrd file. See the Ubuntu instructions that follow for an example menu.lst.</li>
<li>Make sure you have your /boot directory in the correct place. If your disk is just one big partition you shouldn&#039;t need to do anything (use the hd0 PV-Grub kernel in the last step when booting). If you have a partition for /boot you will need to make sure it is the first partition on the disk and you will also need to copy the directory into /boot/boot so that the menu.lst file would be in /boot/boot/grub/menu.lst after the copy. For an example of this see the Ubuntu instructions that follow (use the hd00 PV-Grub kernel in the last step when booting).</li>
<li>Export the image to a raw form. This includes the partition table and everything. For VMWare you can use qemu-img to convert the VMDK to a raw image with the following command:
<pre class="brush: plain; title: ; notranslate">
   qemu-img convert -O raw vmware-image.vmdk myosimage.raw
</pre>
<p>Or if you are using VirtualBox you would use the VBoxManage command (I&#039;m currently using VirtualBox 3.2.6 and since the VBoxManage command has changed before that might be important for those reading this at a later date):</p>
<pre class="brush: plain; title: ; notranslate">
   VBoxManage internalcommands converttoraw myosimage.vdi myosimage.img
</pre>
<p>In both cases you should be able to run fdisk against the resulting raw image file and see a partition table:</p>
<pre class="brush: plain; title: ; notranslate">
   fdisk -lu myosimage.img
</pre>
</li>
<li>Create an EBS volume that is the same size or larger than the raw disk image created in step 4 and then attach it to a running EC2 instance:
<pre class="brush: plain; title: ; notranslate">
ec2-create-volume -z us-east-1a -s 2
ec2-attach-volume volume-id -i instance-id -d /dev/sdh
</pre>
<p>Note: The instance you attach the volume to is just a place used to copy the image file onto the volume. There is no need to be too picky about the type of instance it is as long as you have access to the dd command that should be all you need.
</li>
<li>Transfer the exported VirtualBox or VMWare disk image to the running EC2 instance created in step 5 and then copy it to the volume with the following dd command (this example assumes the volume is attached to the /dev/sdh device):
<pre class="brush: plain; title: ; notranslate">
dd if=myosimage.img of=/dev/sdh bs=10M
</pre>
<p>Note: It may make sense to compress your raw image before transferring it since any free space will be represented in the raw file and will compress down a lot.
</li>
<li>Make a snapshot of the volume:
<pre class="brush: plain; title: ; notranslate">
ec2-create-snapshot -d &quot;Volume Description&quot; volume-id
</pre>
</li>
<li>Register the snapshot as a new AMI:
<pre class="brush: plain; title: ; notranslate">
ec2-register -n &quot;AMIName&quot; -d &quot;AMI Description&quot; --root-device-name /dev/sda2 -b /dev/sda=snap-id:2:true
</pre>
</li>
<li>Boot the new AMI using the correct PV-Grub kernel. The correct kernel will depend on how your partition structure. For more information see the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?categoryID=174&#038;externalID=3967">AWS PV-Grub documentation</a>. The main thing to know is that if you have /boot on its own partition use the hd00 kernel otherwise use the hd0 kernel:
<pre class="brush: plain; title: ; notranslate">
ec2-run-instances -z us-east-1a -g your-group -k your-keypair -n 1 --kernel pv-grub-kernel-id ami-from-step-19
</pre>
</li>
</ol>
<p>The following is a specific example of converting an existing <a href="http://www.ubuntu.com/server">Ubuntu 10.04 LTS Server</a> installed on VirtualBox to a bootable EC2 AMI. Note that steps 1 to 4 of the following create my &#034;existing&#034; Ubuntu Server so skip those if you have something that already exists. The last portion of this will look just like the above generic steps:</p>
<ol>
<li>Use the Ubuntu Server ISO to install Ubuntu on a fresh VirtualBox VM. For this example I used 512M of memory and a 2G disk. This is what my VirtualBox setup looked like:<br/><br/>
<p><a href="http://www.ioncannon.net/wp-content/uploads/2010/08/EC2UbuntuVMSummary.png"><img src="http://www.ioncannon.net/wp-content/uploads/2010/08/EC2UbuntuVMSummary.png" alt="" title="EC2 Ubuntu VirtualBox Summary" width="699" height="453" class="alignnone size-full wp-image-1248" /></a>
</li>
<li>Because I wanted /boot to be on its own partition I used the manual partition creation option:<br/><br/>
<p><a href="http://www.ioncannon.net/wp-content/uploads/2010/08/EC2UbuntuManualPartitions.png"><img src="http://www.ioncannon.net/wp-content/uploads/2010/08/EC2UbuntuManualPartitions.png" alt="" title="EC2 Ubuntu Manual Partitions" width="648" height="555" class="alignnone size-full wp-image-1251" /></a></p>
<p>You don&#039;t have to do this but I wanted these instructions to align with my previous post for CentOS 5.5. In this case I made the first partition mount at /boot and the second partition was everything else mounted at / and the result looked like:<br/></p>
<p><a href="http://www.ioncannon.net/wp-content/uploads/2010/08/EC2UbuntuPartitionTable.png"><img src="http://www.ioncannon.net/wp-content/uploads/2010/08/EC2UbuntuPartitionTable.png" alt="" title="EC2 Ubuntu Partition Table" width="648" height="555" class="alignnone size-full wp-image-1249" /></a></p>
<p>Notice that I didn&#039;t include any swap, that is something you probably want to put on the EC2 instance&#039;s ephemeral storage.
</li>
<li>For Ubuntu you are prompted to install other software after the base install and setting up a user. Make sure you install OpenSSH server:<br/><br/>
<p><a href="http://www.ioncannon.net/wp-content/uploads/2010/08/EC2UbuntuOpenSSHServer.png"><img src="http://www.ioncannon.net/wp-content/uploads/2010/08/EC2UbuntuOpenSSHServer.png" alt="" title="EC2 Ubuntu OpenSSH Server" width="648" height="555" class="alignnone size-full wp-image-1250" /></a>
</li>
<li>When prompted to install grub answer yes.</li>
<li>At this point you should have a bootable Ubuntu system either from following the previous steps or from an existing bootable install. You will need to install the libuuid-perl package so that the EC2 compatible Xen kernels will be installable:
<pre class="brush: plain; title: ; notranslate">
   sudo apt-get install libuuid-perl
</pre>
</li>
<li>Grab a Xen kernel and initrd that are compatible with EC2:
<pre class="brush: plain; title: ; notranslate">
wget http://ftp.debian.org/debian/pool/main/l/linux-2.6/linux-base_2.6.32-20_all.deb
wget http://ftp.debian.org/debian/pool/main/l/linux-2.6/linux-image-2.6.32-5-xen-686_2.6.32-20_i386.deb

sudo dpkg -i linux-base_2.6.32-20_all.deb linux-image-2.6.32-5-xen-686_2.6.32-20_i386.deb
</pre>
<p>Notes: I was unable to find a compatible kernel that was apt-get installable from Ubuntu and that is why I grab the two above from the Debian site. Also, If you want to continue to boot the system outside of EC2 then make sure to edit the /boot/grub/grub.cfg file so that it has the correct kernel set to boot by default.
</li>
<li>Create a menu.lst file that points to the correct kernel and initrd that were just installed:
<pre class="brush: plain; title: ; notranslate">
   sudo vi /boot/grub/menu.lst
</pre>
<p>For this example mine contains:</p>
<pre class="brush: plain; title: ; notranslate">
default 0
timeout 1
title UBEC2
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-5-xen-686 root=/dev/xvda2
        initrd /boot/initrd.img-2.6.32-5-xen-686
</pre>
<p>Notes: The grub root command is pointing to hard disk 0 and partition 0 because I put the boot directory on the first partition. The root parameter for the kernel is pointing to /dev/xvda2 and not /dev/sda2 because the kernel patch to disable XSAVE changes the names of the devices.
</li>
<li>Copy everything from /boot into /boot/boot, this is just the easiest way of making things work since EC2 PV-Grub looks for the menu.lst file /boot/boot/grub/ when you specify the hd00 kernel:
<pre class="brush: plain; title: ; notranslate">
sudo cp -Rp /boot/ /boot/boot
</pre>
</li>
<li>Shut the VirtualBox system down and extract the hard drive image with the following command:
<pre class="brush: plain; title: ; notranslate">
VBoxManage internalcommands converttoraw ~/.VirtualBox/HardDisks/YourHardDiskName.vdi /tmp/myosimage.img
</pre>
<p>Notes: The raw image that results will be the full size of the disk as it was seen by VirtualBox so if you have a lot of free disk space on your image you will probably want to compress it before you transfer it to EC2. At this point the commands are exactly as they are for the generic instructions above.
</li>
<li>Start a temporary EC2 instance and transfer your image:
<pre class="brush: plain; title: ; notranslate">
ec2-run-instances -z us-east-1a -g your-group -k your-keypair -n 1 ami-84db39ed
</pre>
</li>
<li>Create an EBS volume of the correct size to put your image onto and attach it to the previously created temporary EC2 instance:
<pre class="brush: plain; title: ; notranslate">
ec2-create-volume -z us-east-1a -s 2
ec2-attach-volume volume-id -i instance-id -d /dev/sdh
</pre>
</li>
<li>Transfer the image to the volume:
<pre class="brush: plain; title: ; notranslate">
dd if=myosimage.img of=/dev/sdh bs=10M
</pre>
</li>
<li>Create a snapshot of the volume:
<pre class="brush: plain; title: ; notranslate">
ec2-create-snapshot -d &quot;Volume Description&quot; volume-id
</pre>
</li>
<li>Register the snapshot as an AMI:
<pre class="brush: plain; title: ; notranslate">
ec2-register -n &quot;AMIName&quot; -d &quot;AMI Description&quot; --root-device-name /dev/sda2 -b /dev/sda=snap-id:2:true
</pre>
</li>
<li>Boot the AMI:
<pre class="brush: plain; title: ; notranslate">
ec2-run-instances -z us-east-1a -g your-group -k your-keypair -n 1 --kernel pv-grub-kernel-id ami-from-step-19
</pre>
<p>Note: Because the partition table contains /boot on hd00 I used the kernel named aki-4c7d9525 for the east region.
</li>
</ol>
<p>Once you get the hang of transferring the image these steps aren&#039;t as complicated as they seem. It may help to imagine the extracted disk image as a physical hard drive that you are moving around. The main pain points are selecting the correct PV-Grub kernel and making sure your grub menu.lst file is in the correct location on the partition.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ioncannon.net/system-administration/1246/converting-from-virtualbox-or-vmware-to-ec2-now-easier-than-ever/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Installing Cent OS 5.5 on EC2 with the Cent OS 5.5 Kernel</title>
		<link>http://www.ioncannon.net/system-administration/1205/installing-cent-os-5-5-on-ec2-with-the-cent-os-5-5-kernel/</link>
		<comments>http://www.ioncannon.net/system-administration/1205/installing-cent-os-5-5-on-ec2-with-the-cent-os-5-5-kernel/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 10:51:37 +0000</pubDate>
		<dc:creator>carson</dc:creator>
				<category><![CDATA[system administration]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.ioncannon.net/?p=1205</guid>
		<description><![CDATA[Amazon recently introduced the ability to boot a custom kernel using pv-grub on EC2. This opens the door for all kinds of interesting ideas that I&#039;ve been thinking about for a while, like seeing if I can boot right into a web server and skip all that extra junk that comes with Linux distributions, but [...]]]></description>
			<content:encoded><![CDATA[<p>Amazon recently introduced the ability to <a href="http://aws.typepad.com/aws/2010/07/use-your-own-kernel-with-amazon-ec2.html">boot a custom kernel</a> using pv-grub on EC2. This opens the door for all kinds of interesting ideas that I&#039;ve been thinking about for a while, like seeing if I can boot right into a web server and skip all that extra junk that comes with Linux distributions, but that is just me. The main door it is going to open for most people interested in EC2 will be the ability to upgrade the kernel that comes with their distribution. That brings us to how to install Cent OS 5.5 on EC2 and use the kernel that is part of the distribution.</p>
<p>For those who might just be interested in booting a custom kernel using EC2 pv-grub I will try to produce a few more posts with more details on that but for now here are the main things to know:</p>
<ul>
<li>The pv-grup kernels named with hd00 will look on the first partition of the registered device in the /boot/boot/grub directory for a menu.lst file. Use this type of kernel if you create want to use a partitioned disk.</li>
<li>The pv-grup kernels named with hd0 will look on the registered device in the /boot/grub directory for a menu.lst file. Use this type of kernel if you don&#039;t have a partition on your disk.</li>
<li>You won&#039;t get anything meaningful back from the boot attempt if your grub menu.lst file is in the wrong place or is not valid. See the end of the post for what a pv-grub error message looks like and some tips on what to do if you see it.</li>
<li>The kernel you use does matter but the current mainline Linux kernel (2.6.35) contains everything you need except for a small change to turn off XSAVE. The main thing to know is that not every distribution may have made the change needed to work on EC2.</li>
<li>I have tried non-Linux kernels to no avail. See the end of the post for a little more information.</li>
</ul>
<p><span id="more-1205"></span></p>
<p>A lot of what follows is similar, both steps and concepts, to the &#034;from scratch&#034; section of my post on <a href="http://www.ioncannon.net/system-administration/894/fedora-12-bootable-root-ebs-on-ec2/">Fedora 12 on EC2 using a root EBS</a>. I&#039;ve also bundled all the instance building commands up into one <a href="http://www.ioncannon.net/examples/centos5.5.sh">script (centos5.5.sh)</a>. If you want to use that script then do 1 and 2 of what follows, make sure to change the password used for root in the script and then pick back up at 18. The following steps should not be taken as the only way to do this but more of a recipe:</p>
<ol>
<li>
Start an EC2 instance that has yum on it to be used as a setup box. A RedHat based box, Fedora or CentOS will work best unless you want to install yum. For the following steps I used a Fedora 8 based EC2 node.</p>
<pre class="brush: plain; title: ; notranslate">
ec2-run-instances -z us-east-1a -g your-group -k your-keypair -n 1 ami-84db39ed
</pre>
</li>
<li>
Create a new EBS volume to install to and map it to the running instance from step 1. Your volume should be greater than 2G for a base install. I mapped this new volume to the /dev/sdh device on the setup machine so you will notice that in the following steps (if you are using the script you will want to make sure you map to /dev/sdh as well):</p>
<pre class="brush: plain; title: ; notranslate">
ec2-create-volume -z us-east-1a -s 2
ec2-attach-volume volume-id -i instance-id -d /dev/sdh
</pre>
</li>
<li>
<p>Create a <a href="http://tldp.org/HOWTO/Partition/fdisk_partitioning.html">partion table using fdisk</a> on the volume you are going to install to.</p>
<p>I created both a /boot and / partion on /dev/sdh1 and /dev/sdh2 respecivly. I also made the /dev/sdh1 partition active so it is exactly as it would be if it had been installed on a real machine.</p>
<p>Note that this step is optional but I am going to include it because I think it makes for a more natural setup and is more in line with what you would get if you did a VirtualBox install and then transfered the image.
</li>
<li>
Format your partition(s) and mount them into /mnt. For me that was done with the following:</p>
<pre class="brush: plain; title: ; notranslate">
echo &quot;y&quot; | mkfs.ext3 /dev/sdh1
echo &quot;y&quot; | mkfs.ext3 /dev/sdh2
mount /dev/sdh2 /mnt
mkdir /mnt/boot
mkdir /mnt/dev
mkdir /mnt/proc
mkdir /mnt/etc
mount /dev/sdh1 /mnt/boot
mount -t proc none /mnt/proc
</pre>
</li>
<li>
Create a base device setup for the new instance:</p>
<pre class="brush: plain; title: ; notranslate">
for i in console null zero ; do /sbin/MAKEDEV -d /mnt/dev -x $i ; done
</pre>
</li>
<li>
Create a base fstab file in /mnt/etc/fstab. The following is the one I used:</p>
<pre class="brush: plain; title: ; notranslate">
/dev/sda1               /boot                   ext3    defaults 1 1
/dev/sda2               /                       ext3    defaults 1 2
none                    /dev/pts                devpts  gid=5,mode=620 0 0
none                    /dev/shm                tmpfs   defaults 0 0
none                    /proc                   proc    defaults 0 0
none                    /sys                    sysfs   defaults 0 0
/dev/sdc1               /mnt                    ext3    defaults 0 0
/dev/sdc2               swap                    swap    defaults 0 0
</pre>
</li>
<li>
Create the yum repo configuration, prepare for the yum install and then install the base OS onto the new volume.<br/><br/></p>
<p>The following is the yum configuration file I used:</p>
<pre class="brush: plain; title: ; notranslate">
[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
exclude=*-debuginfo
gpgcheck=0
obsoletes=1
reposdir=/dev/null

[os]
name=CentOS 5.5 - i386 - OS
mirrorlist=http://mirrorlist.centos.org/?release=5&amp;arch=i386&amp;repo=os
enabled=1

[updates]
name=CentOS 5.5 - i386 - Updates
mirrorlist=http://mirrorlist.centos.org/?release=5&amp;arch=i386&amp;repo=updates
enabled=1
</pre>
<p>The following command will install the base of Cent OS 5.5 into /mnt (note that I created the above config file as /tmp/yumec2.conf):</p>
<pre class="brush: plain; title: ; notranslate">
yum -c /tmp/yumec2.conf --installroot=/mnt -y groupinstall Base
</pre>
</li>
<li>
Install sshd, grub, the Cent OS Xen kernel and then clean the repo to free up disk space:</p>
<pre class="brush: plain; title: ; notranslate">
yum -c /tmp/yumec2.conf --installroot=/mnt -y install openssh-server
yum -c /tmp/yumec2.conf --installroot=/mnt -y install grub
yum -c /tmp/yumec2.conf --installroot=/mnt -y install kernel-xen.i686

yum -c /tmp/yumec2.conf --installroot=/mnt -y clean packages
</pre>
</li>
<li>
Disable DNS checks and allow root to log in via SSH:</p>
<pre class="brush: plain; title: ; notranslate">
echo &quot;UseDNS no&quot; &gt;&gt; /mnt/etc/ssh/sshd_config
echo &quot;PermitRootLogin yes&quot; &gt;&gt; /mnt/etc/ssh/sshd_config
</pre>
</li>
<li>
Set up networking by creating the /mnt/etc/sysconfig/network file. The contents for this example are:</p>
<pre class="brush: plain; title: ; notranslate">
NETWORKING=yes
</pre>
<p>As well as the /mnt/etc/sysconfig/network-scripts/ifcfg-eth0 file. The contents for this example are:</p>
<pre class="brush: plain; title: ; notranslate">
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
</pre>
</li>
<li>
I&#039;m not sure if this is needed still but in the past there have been some /dev file missing on boot so I always add the following to the startup script to make sure they are available. The first two are the random devices and the last three are where the ephimeral drive is usually mapped:</p>
<pre class="brush: plain; title: ; notranslate">
echo &quot;/sbin/MAKEDEV /dev/urandom&quot; &gt;&gt; /mnt/etc/rc.sysinit
echo &quot;/sbin/MAKEDEV /dev/random&quot; &gt;&gt; /mnt/etc/rc.sysinit
echo &quot;/sbin/MAKEDEV /dev/sdc&quot; &gt;&gt; /mnt/etc/rc.sysinit
echo &quot;/sbin/MAKEDEV /dev/sdc1&quot; &gt;&gt; /mnt/etc/rc.sysinit
echo &quot;/sbin/MAKEDEV /dev/sdc2&quot; &gt;&gt; /mnt/etc/rc.sysinit
</pre>
</li>
<li>
Change the root password for the new instance. This is optional as you could create scripts to download your SSH key from EC2 but for these instructions setting the root password is the easiest:</p>
<pre class="brush: plain; title: ; notranslate">
chroot /mnt
pwconv
passwd
exit
</pre>
</li>
<li>
Change the network settings so that the NetworkManager is off and network is on</p>
<pre class="brush: plain; title: ; notranslate">
chroot /mnt chkconfig --level 2345 NetworkManager off
chroot /mnt chkconfig --level 2345 network on
</pre>
</li>
<li>
Disable a few things that are enabled by default but won&#039;t do any good for an EC2 instance:</p>
<pre class="brush: plain; title: ; notranslate">
chroot /mnt chkconfig --level 2345 avahi-daemon off
chroot /mnt chkconfig --level 2345 firstboot off
</pre>
</li>
<li>
The stock CentOS Xen initrd doesn&#039;t load the Xen block or net drivers and those are required to boot. I unpacked the installed initrd and created a modified version by hand using the following commands (note that as soon as the CentOS Xen kernel version changes this will stop functioning):</p>
<pre class="brush: plain; title: ; notranslate">
cp /mnt/boot/initrd-2.6.18-194.8.1.el5xen.img /mnt/boot/initrd-2.6.18-194.8.1.el5xen.img.orig
mkdir /tmp/initrdextract
cd /tmp/initrdextract
gzip -dc /mnt/boot/initrd-2.6.18-194.8.1.el5xen.img | cpio -id
cp /mnt/lib/modules/2.6.18-194.8.1.el5xen/kernel/drivers/xen/blkfront/xenblk.ko lib
cp /mnt/lib/modules/2.6.18-194.8.1.el5xen/kernel/drivers/xen/netfront/xennet.ko lib
chmod -x lib/xenblk.ko
chmod -x lib/xennet.ko
cat &lt;&lt;EOL &gt; init
#!/bin/nash

mount -t proc /proc /proc
setquiet
echo Mounting proc filesystem
echo Mounting sysfs filesystem
mount -t sysfs /sys /sys
echo Creating /dev
mount -o mode=0755 -t tmpfs /dev /dev
mkdir /dev/pts
mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
mkdir /dev/shm
mkdir /dev/mapper
echo Creating initial device nodes
mknod /dev/null c 1 3
mknod /dev/zero c 1 5
mknod /dev/urandom c 1 9
mknod /dev/systty c 4 0
mknod /dev/tty c 5 0
mknod /dev/console c 5 1
mknod /dev/ptmx c 5 2
mknod /dev/rtc c 10 135
mknod /dev/tty0 c 4 0
mknod /dev/tty1 c 4 1
mknod /dev/tty2 c 4 2
mknod /dev/tty3 c 4 3
mknod /dev/tty4 c 4 4
mknod /dev/tty5 c 4 5
mknod /dev/tty6 c 4 6
mknod /dev/tty7 c 4 7
mknod /dev/tty8 c 4 8
mknod /dev/tty9 c 4 9
mknod /dev/tty10 c 4 10
mknod /dev/tty11 c 4 11
mknod /dev/tty12 c 4 12
mknod /dev/ttyS0 c 4 64
mknod /dev/ttyS1 c 4 65
mknod /dev/ttyS2 c 4 66
mknod /dev/ttyS3 c 4 67
echo Setting up hotplug.
hotplug
echo Creating block device nodes.
mkblkdevs
echo &quot;Loading jbd.ko module&quot;
insmod /lib/jbd.ko
echo &quot;Loading ext3.ko module&quot;
insmod /lib/ext3.ko
echo &quot;Loading xenblk.ko module&quot;
insmod /lib/xenblk.ko
echo &quot;Loading xennet.ko module&quot;
insmod /lib/xennet.ko
mkblkdevs
echo Scanning and configuring dmraid supported devices
resume /dev/sdc2
echo Creating root device.
mkrootdev -t ext3 -o defaults,ro /dev/sda1
echo Mounting root filesystem.
mount /sysroot
echo Setting up other filesystems.
setuproot
echo Switching to new root and running init.
switchroot
EOL
find ./ | cpio -H newc -o | gzip &gt; /mnt/boot/initrd-2.6.18-194.8.1.el5xen.img
cd -
</pre>
</li>
<li>
Install grub on the new instance, move the boot directory into a subdirectory and create a grub menu.lst file that points to the CentOS kernel and initrd file:</p>
<pre class="brush: plain; title: ; notranslate">
chroot /mnt grub-install /dev/sdh

mkdir /mnt/boot/boot/
mv /mnt/boot/* /mnt/boot/boot/ 2&gt; /dev/null &gt; /dev/null
</pre>
<p>Put the following in /mnt/boot/boot/grub/menu.lst  (note that as soon as the CentOS Xen kernel version changes this will be incorrect):</p>
<pre class="brush: plain; title: ; notranslate">
default 0
timeout 1
title CentOS5.5
     root (hd0,0)
     kernel /boot/vmlinuz-2.6.18-194.8.1.el5xen root=/dev/sda2
     initrd /boot/initrd-2.6.18-194.8.1.el5xen.img
</pre>
<p>Note that this goes in /mnt/boot/boot/grub and that isn&#039;t the normal spot you would expect it in. This is where the AWS EC2 pv-grub expects to find the file on the first partition and moving the boot directory around just keeps everything in line with those expectations.
</li>
<li>
Make sure everything is written to disk and unmount the volume. At this point you have a CentOS 5.5 install that is almost ready to boot.</p>
<pre class="brush: plain; title: ; notranslate">
sync
umount /mnt/proc
umount /mnt/boot
umount /mnt
</pre>
</li>
<li>
Make a snapshot of the volume you just installed to, you will need to volume ID that came from step 2:</p>
<pre class="brush: plain; title: ; notranslate">
ec2-create-snapshot -d &quot;Volume Description&quot; volume-id
</pre>
</li>
<li>
Use the snapshot from step 18 along with the ec2-register command to register your instance:</p>
<pre class="brush: plain; title: ; notranslate">
ec2-register -n &quot;AMIName&quot; -d &quot;AMI Description&quot; --root-device-name /dev/sda2 -b /dev/sda=snap-id:2:true
</pre>
<p>There are a number of things to take note of with the above command:</p>
<ol>
<li>Running this command will result in output something like: IMAGE   ami-a5ae9bb</li>
<li>The -b option can now assign a snapshot to a block device, the options in this example tell EC2 to generate 2G of space for the snapshot and to delete the volume it creates from the snapshot if the instance terminates. If you plan to use an instance long term you should replace that true at the end with a false to keep EC2 from deleting the volume when the instance terminates.</li>
<li>Notice that the -b option is assigning the snapshot to the device and not to a partition of the device, that is /dev/sda instead of /dev/sda1. You can still assign a snapshot directly to a partition but now you can also assign a block device to a raw partitioned disk. Because I created the partition table earlier the snapshot is the raw disk device here.</li>
<li>Also note that we are missing the kernel configuration option. As of this post using it with a pv-grub kernel causes the register command to fail. It isn&#039;t a big issue but just keep that in mind when you fire the AMI up otherwise it won&#039;t boot with the correct pv-grub kernel.</li>
</ol>
<p><br/>
</li>
<li>
Start an instance of the fresh CentOS 5.5 install. One key thing here is picking the correct pv-grub kernel to boot from. There are currently 4 different kernels at each location, see the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?categoryID=174&#038;externalID=3967">Enabling User Provided Kernels in Amazon EC2</a> document for a full list of kernels in each availability zone. In this case because the root disk was created with a partition table I used the &#034;ec2-public-images/pv-grub-hd00-V1.01-i386.gz.manifest.xml&#034; kernel to boot with (on US-East-1 that is kernel id aki-4c7d9525). For example:</p>
<pre class="brush: plain; title: ; notranslate">
ec2-run-instances -z us-east-1a -g your-group -k your-keypair -n 1 --kernel pv-grub-kernel-id ami-from-step-19
</pre>
</li>
</ol>
<p><b>Tips on debugging the boot process</b></p>
<p>If your instance won&#039;t boot you can use the ec2-get-console-output command to get the console output created from the pv-grub boot process. If your console output ends up like the following there are a number of things you may have done wrong.</p>
<ul>
<li>You may have selected the wrong kernel and it is trying to boot from a non-existant partition. Make sure you are using the correct pv-grub kernel hd0 vs hd00.</li>
<li>You forgot to install grub or installed grub in the wrong place. Make sure you have either /boot/grub/menu.lst or /boot/boot/grub/menu.lst</li>
<li>You have a bad menu.lst file. One mistake I made was giving a boot item a title with a space in it. Make the menu.lst as simple as you can until you get it to boot.</li>
</ul>
<pre class="brush: plain; title: ; notranslate">
    Xen Minimal OS!
  start_info: 0xb10000(VA)
    nr_pages: 0x6a400
  shared_inf: 0x002f9000(MA)
     pt_base: 0xb13000(VA)
nr_pt_frames: 0x9
    mfn_list: 0x967000(VA)
   mod_start: 0x0(VA)
     mod_len: 0
       flags: 0x0
    cmd_line:  root=/dev/sda1 ro 4
  stack:      0x946780-0x966780
MM: Init
      _text: 0x0(VA)
     _etext: 0x621f5(VA)
   _erodata: 0x76000(VA)
     _edata: 0x7b6d4(VA)
stack start: 0x946780(VA)
       _end: 0x966d34(VA)
  start_pfn: b1f
    max_pfn: 6a400
Mapping memory range 0xc00000 - 0x6a400000
setting 0x0-0x76000 readonly
skipped 0x1000
MM: Initialise page allocator for e6c000(e6c000)-0(6a400000)
MM: done
Demand map pfns at 6a401000-7a401000.
Heap resides at 7a402000-ba402000.
Initialising timer interface
Initialising console ... done.
gnttab_table mapped at 0x6a401000.
Initialising scheduler
Thread &quot;Idle&quot;: pointer: 0x7a402008, stack: 0x6a030000
Initialising xenbus
Thread &quot;xenstore&quot;: pointer: 0x7a402478, stack: 0x6a040000
Dummy main: start_info=0x966880
Thread &quot;main&quot;: pointer: 0x7a4028e8, stack: 0x6a050000
&quot;main&quot; &quot;root=/dev/sda1&quot; &quot;ro&quot; &quot;4&quot;
vbd 2048 is hd0
******************* BLKFRONT for device/vbd/2048 **********

backend at /local/domain/0/backend/vbd/2111/2048
Failed to read /local/domain/0/backend/vbd/2111/2048/feature-barrier.
Failed to read /local/domain/0/backend/vbd/2111/2048/feature-flush-cache.
12582912 sectors of 0 bytes
**************************
vbd 2051 is hd1
******************* BLKFRONT for device/vbd/2051 **********

backend at /local/domain/0/backend/vbd/2111/2051
Failed to read /local/domain/0/backend/vbd/2111/2051/feature-barrier.
Failed to read /local/domain/0/backend/vbd/2111/2051/feature-flush-cache.
1835008 sectors of 0 bytes
**************************

    [H
    [J

    GNU GRUB  version 0.97  (1740800K lower / 0K upper memory)

       [ Minimal BASH-like line editing is supported.   For

         the   first   word,  TAB  lists  possible  command

         completions.  Anywhere else TAB lists the possible

         completions of a device/filename. ]

grubdom&gt;
    [9;10H
</pre>
<p><br/><br/></p>
<p><b>Booting non-Linux OSes with EC2</b></p>
<p>I have attempted both FreeBSD and NetBSD in particular with no luck. </p>
<p>FreeBSD is tricky because it really wants to use its loader and while you can do that with the grub chainloader command it results in a grub error from EC2 about needing to load the kernel before booting:</p>
<pre class="brush: plain; title: ; notranslate">
root (hd0,1)

 Filesystem type unknown, partition type 0xa5

chainloader +1

Error 8: Kernel must be loaded before booting

Press any key to continue...
</pre>
<p>I was also able to try a modified version of FreeBSD that should boot without the loader but with that I get an error claiming the kernel isn&#039;t bziped:</p>
<pre class="brush: plain; title: ; notranslate">
root (hd0,1,a)

 Filesystem type is ufs2, partition type 0xa5

kernel /boot/loader

xc_dom_probe_bzimage_kernel: kernel is not a bzImage
ERROR Invalid kernel: xc_dom_find_loader: no loader found

xc_dom_core.c:523: panic: xc_dom_find_loader: no loader found
xc_dom_parse_image returned -1

Error 9: Unknown boot failure

Press any key to continue...
</pre>
<p>For NetBSD the result is actually a completely blank console log so I assume it causes some catastrophic failure that keeps the EC2 system from even being able to pull back a log.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ioncannon.net/system-administration/1205/installing-cent-os-5-5-on-ec2-with-the-cent-os-5-5-kernel/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Building HipHop PHP for Fedora 12 on 64 bit and 32 bit Systems</title>
		<link>http://www.ioncannon.net/programming/918/building-hiphop-php-for-fedora-12-on-64-bit-and-32-bit-systems/</link>
		<comments>http://www.ioncannon.net/programming/918/building-hiphop-php-for-fedora-12-on-64-bit-and-32-bit-systems/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 11:14:04 +0000</pubDate>
		<dc:creator>carson</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[Fedora]]></category>
		<category><![CDATA[hphp]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.ioncannon.net/?p=918</guid>
		<description><![CDATA[Now that Facebook has finally released the source for HipHop PHP it is time to give it a spin. Of course it is still a little rough around the edges so I figured I would toss together a quick howto on getting it to build. The first thing to note is that they are only [...]]]></description>
			<content:encoded><![CDATA[<p>Now that Facebook has finally released the source for <a href="http://github.com/facebook/hiphop-php/">HipHop PHP</a> it is time to give it a spin. Of course it is still a little rough around the edges so I figured I would toss together a quick howto on getting it to build.</p>
<p>The first thing to note is that they are only supporting 64 bit systems officially. Having said that it isn&#039;t too hard to modify the code to make it work on a 32 bit system although it may turn out that such early modifications are missing some fundamental bits on why they were only support 64 bit systems. I&#039;m going to assume at first that you are using a 64 bit system and then end with what you need if you are still using a 32 bit system.</p>
<p><span id="more-918"></span></p>
<p>I don&#039;t actually have a 64 bit system myself so I used an EC2 instance for the following instructions. To do the same start with Amazon&#039;s Basic 64-bit Fedora Core 8 (AMI Id: ami-86db39ef) instance (note that this is EBS backed so you will end up with an EBS volume after you start it) and then upgrade to Fedora 12 using my <a href="http://www.ioncannon.net/system-administration/894/fedora-12-bootable-root-ebs-on-ec2/">previous instructions on building a EBS bootable Fedora 12 instance</a>. You will need to remove a few packages to get the 64 bit version of Fedora 8 to upgrade that I didn&#039;t have to do for the 32 bit version, here are all the commands you need to get to a running 64 bit Fedora 12 instance (the entire upgrade takes about 20 minutes):</p>
<pre class="brush: bash; title: ; notranslate">
# Fedora 8 to Fedora 10
yum -y remove dmraid-1.0.0.rc14-4.fc8.i386 dmraid-1.0.0.rc14-4.fc8.i386 curl-7.18.2-7.fc8.i386
yum clean all
rpm -Uhv http://archive.kernel.org/fedora-archive/releases/10/Fedora/i386/os/Packages/fedora-release-10-1.noarch.rpm http://archive.kernel.org/fedora-archive/releases/10/Fedora/i386/os/Packages/fedora-release-notes-10.0.0-1.noarch.rpm
yum -y update

# Fedora 10 to Fedora 11
yum -y remove gpm-1.20.5-2.fc10.i386
yum clean all
rpm -Uvh http://mirrors.usc.edu/pub/linux/distributions/fedora/linux/releases/11/Fedora/i386/os/Packages/fedora-release-11-1.noarch.rpm http://mirrors.usc.edu/pub/linux/distributions/fedora/linux/releases/11/Fedora/i386/os/Packages/fedora-release-notes-11.0.0-2.fc11.noarch.rpm
yum -y update

# Fedora 11 to Fedora 12
yum -y remove cryptsetup-luks-1.0.6-7.fc11.i586
yum clean all
rpm -Uvh http://mirrors.kernel.org/fedora/releases/12/Fedora/i386/os/Packages/fedora-release-notes-12.0.0-4.fc12.noarch.rpm http://mirrors.kernel.org/fedora/releases/12/Fedora/i386/os/Packages/fedora-release-12-1.noarch.rpm
yum -y update

# Make sure the basics are installed
yum -y install gcc-c++ git
</pre>
<p>To start with there are some prerequisites you need. This can be taken care of in one command with yum:</p>
<pre class="brush: bash; title: ; notranslate">
yum -y install git cmake boost pcre-devel libicu-devel libmcrypt-devel oniguruma-devel mysql-devel gd-devel boost-devel libxml2-devel libcap-devel binutils-devel flex bison expat-devel
</pre>
<p>Next create a directory to hold everything in, change into that directory and create another directory to hold the customized libraries needed to compile HipHop PHP:</p>
<pre class="brush: bash; title: ; notranslate">
mkdir hiphop
cd hiphop
mkdir local
</pre>
<p>Next it is time to pull down the HipHop PHP source along with the source for some libraries it depends on (these all go into the hiphop directory created above):</p>
<pre class="brush: bash; title: ; notranslate">
git clone git://github.com/facebook/hiphop-php.git

wget &quot;http://downloads.sourceforge.net/project/re2c/re2c/0.13.5/re2c-0.13.5.tar.gz?use_mirror=cdnetworks-us-2&quot;
wget &quot;http://www.threadingbuildingblocks.org/uploads/77/142/2.2/tbb22_20090809oss_src.tgz&quot;
wget http://curl.haxx.se/download/curl-7.20.0.tar.bz2
wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz

tar xvjf curl-7.20.0.tar.bz2
tar xvzf libevent-1.4.13-stable.tar.gz
tar xvzf re2c-0.13.5.tar.gz
tar xvzf tbb22_20090809oss_src.tgz
</pre>
<p>Next the customized patches get applied to some of the library sources and each is built to install in the custom directory:</p>
<pre class="brush: bash; title: ; notranslate">
export CMAKE_PREFIX_PATH=`pwd`/local

cd tbb22_20090809oss
gmake
cp -Rp include/tbb/ /usr/include/
cp `pwd`/build/*_release/*.so /usr/lib/
ldconfig
cd ..

cd re2c-0.13.5
./configure --prefix=`pwd`/../local
make install
cd ..

cd libevent-1.4.13-stable
cp ../hiphop-php/src/third_party/libevent.fb-changes.diff .
patch &lt; libevent.fb-changes.diff
./configure --prefix=`pwd`/../local
make install
cd ..

cd curl-7.20.0
cp ../hiphop-php/src/third_party/libcurl.fb-changes.diff .
patch -p0 &lt; libcurl.fb-changes.diff
./configure --prefix=`pwd`/../local
make install
cd ..
</pre>
<p>There is one problem at this point that requires a little surgery on the HipHop PHP source itself. There is more about this in <a href="http://github.com/facebook/hiphop-php/issues#issue/6">issue #6</a> and once it gets fixed this won&#039;t need to be done. </p>
<pre class="brush: bash; title: ; notranslate">
cd hiphop-php
echo &quot;#ifndef LHASH&quot; &gt;&gt; src/cpp/ext/ext_openssl.h
echo &quot;#define LHASH LHASH_OF(CONF_VALUE)&quot; &gt;&gt; src/cpp/ext/ext_openssl.h
echo &quot;#endif&quot; &gt;&gt; src/cpp/ext/ext_openssl.h
</pre>
<p>And at last it is time to compile HipHop PHP itself:</p>
<pre class="brush: bash; title: ; notranslate">
git submodule init
git submodule update
export HPHP_HOME=`pwd`
export HPHP_LIB=`pwd`/bin
cmake .
make
</pre>
<p>It takes about 20 minutes to compile everything. Once the compile is done you are ready to roll. Check out the <a href="http://wiki.github.com/facebook/hiphop-php/running-hiphop">running HipHop wiki page</a> to learn how to run the resulting binary. One important thing to note is that you need to make sure you have the correct environment variables set when you go to compile things. I created a little file I can source with the following in it:</p>
<pre class="brush: bash; title: ; notranslate">
export HPHP_BASE=&lt;path to the first directory&gt;
export CMAKE_PREFIX_PATH=$HPHP_BASE/local
export HPHP_HOME=$HPHP_BASE/hiphop-php
export HPHP_LIB=$HPHP_HOME/bin
</pre>
<p>For those who just want it to go I&#039;ve put all of the above into one script that can be found <a href="http://www.ioncannon.net/examples/hiphopgo.sh">here</a>. If you are going from Fedora 8 to Fedora 12 on an EC2 node you can get a script for that <a href="http://www.ioncannon.net/examples/64bitfedora12ec2.sh">here</a>.</p>
<p>Now if you want to do this on a 32 bit Fedora 12 install you will need to modify the source first. The easiest way I know of doing this is to look at <a href="http://github.com/carsonmcdonald/hiphop-php/commit/792a37cb10514178341877c1425e2f3884898645">this commit log</a> or clone my version that can be found here:</p>
<pre class="brush: bash; title: ; notranslate">
git clone git://github.com/carsonmcdonald/hiphop-php.git
</pre>
<p>Please note that my version my not be up to date and the modifications to get the source to build on the 32 bit system may not be 100% correct. My goal was to get it to build and run on a 32 bit system but I don&#039;t have the time to very much more than that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ioncannon.net/programming/918/building-hiphop-php-for-fedora-12-on-64-bit-and-32-bit-systems/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Fedora 12 Bootable Root EBS on EC2</title>
		<link>http://www.ioncannon.net/system-administration/894/fedora-12-bootable-root-ebs-on-ec2/</link>
		<comments>http://www.ioncannon.net/system-administration/894/fedora-12-bootable-root-ebs-on-ec2/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 12:30:13 +0000</pubDate>
		<dc:creator>carson</dc:creator>
				<category><![CDATA[system administration]]></category>
		<category><![CDATA[EBS]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[Fedora]]></category>

		<guid isPermaLink="false">http://www.ioncannon.net/?p=894</guid>
		<description><![CDATA[I recently needed to create a clean EC2 AMI using a fairly new linux distro. It has been a while since I&#039;ve needed to create a new AMI so I also wanted to move away from the older pre-packaged AMI and boot using EBS. After taking a look at what was currently available publicly I [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to create a clean EC2 AMI using a fairly new linux distro. It has been a while since I&#039;ve needed to create a new AMI so I also wanted to move away from the older pre-packaged AMI and boot using EBS. After taking a look at what was currently available publicly I decided I would just create my own EBS bootable AMI using Fedora 12. It wasn&#039;t all that complicated but there are a decent number of steps so I figured I would document them for anyone else who might want to give it a try.</p>
<p>I&#039;m going to assume you already understand how to do things like create instances, create EBS volumes and ssh into your running instance using key based authentication. I use the AWS management console for a lot of what follows with the exception of needing to register the AMI and for that you will need the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351">Amazon EC2 API Tools</a> and <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=368">Amazon EC2 AMI Tools</a> </p>
<p><span id="more-894"></span></p>
<p>There are two ways to get to a bootable EBS backed Fedora 12 instance and they start off the same. The first thing to do is fire up the AMI named &#034;Basic Fedora Core 8 (AMI Id: ami-84db39ed)&#034; that is provided by Amazon.</p>
<p>Once the Fedora Core 8 EC2 instance is ready ssh into it. Fedora 12 requries a newer version of RPM to install so you now need to upgrade the instance to Fedora 10. This is pretty easy and can be done by following my instructions on <a href="http://www.ioncannon.net/system-administration/142/upgrading-from-fedora-9-to-fedora-10-with-yum/">upgrading from Fedora 9 to Fedora 10</a> (don&#039;t worry about skipping 9 it will work). Here are the commands needed to do the upgrade:</p>
<pre class="brush: bash; title: ; notranslate">
yum clean all
rpm -Uhv http://archive.kernel.org/fedora-archive/releases/10/Fedora/i386/os/Packages/fedora-release-10-1.noarch.rpm http://archive.kernel.org/fedora-archive/releases/10/Fedora/i386/os/Packages/fedora-release-notes-10.0.0-1.noarch.rpm
yum -y update
</pre>
<p>After a few minutes the instance will be upgraded and ready for the next step. This is where the two paths diverge depending on how you want the final product constructed. The options are to install Fedora 12 on a freshly minted volume or continue upgrading the instance you just created.</p>
<p><b>Upgrade path</b></p>
<p>I will start with the upgrade path since that is probably the easier of the two although may leave you with a messier instances after it is done. The next step for the upgrade path is to do what I outline in <a href="http://www.ioncannon.net/system-administration/358/upgrading-to-fedora-11-from-fedora-10/">upgrading from Fedora 10 to Fedora 11</a> and <a href="http://www.ioncannon.net/system-administration/719/upgrade-to-fedora-12-from-fedora-11/">upgrading from Fedora 11 to Fedora 12</a>. Here are the commands all in one place to make it easy:</p>
<pre class="brush: bash; title: ; notranslate">
yum clean all
rpm -Uvh http://mirrors.usc.edu/pub/linux/distributions/fedora/linux/releases/11/Fedora/i386/os/Packages/fedora-release-11-1.noarch.rpm http://mirrors.usc.edu/pub/linux/distributions/fedora/linux/releases/11/Fedora/i386/os/Packages/fedora-release-notes-11.0.0-2.fc11.noarch.rpm
yum -y update
yum clean all
rpm -Uvh http://mirrors.kernel.org/fedora/releases/12/Fedora/i386/os/Packages/fedora-release-notes-12.0.0-4.fc12.noarch.rpm http://mirrors.kernel.org/fedora/releases/12/Fedora/i386/os/Packages/fedora-release-12-1.noarch.rpm
yum -y update
</pre>
<p>Once you have everything upgraded to Fedora 12 you will have a 15G root partition that has less than 2G used. This may not suite your needs very well if you really don&#039;t need that extra 13G but thankfully if you want to shrink the root EBS partition you can. </p>
<p>I found some instructions in this article on <a href="http://www.elastician.com/2009/12/creating-ebs-backed-ami-from-s3-backed.html">EBS backed AMI</a>s that describes using the following command to copy the entire file system over. Assuming you have created a smaller volume and attached it to the instance as sdh you should be able to do something like the following to copy everything to the new volume:</p>
<pre class="brush: bash; title: ; notranslate">
mkfs.ext3 /dev/sdh
mount /dev/sdh /mnt
tar cpS / | cpipe -vt -b 1024 | gzip -c | tar zxpS -C /mnt
rm -rf /mnt/mnt/*
rm -rf /mnt/proc/*
umount /mnt
</pre>
<p>One thing to note in the above is that the entire sdh drive is formatted for the file system (you will actually get a prompt asking if that is ok). As far as I can tell this is the way it has to be or the instance will not boot correctly. I assume this is because the root device is hidden behind a partition already as /dev/sda1 and so shouldn&#039;t have a second partition table.</p>
<p>Skip to the common part now to learn how to make the final bootable AMI.</p>
<p><b>From scratch path</b></p>
<p>This path is similar to and mostly an update/extension to my post on creating a <a href="http://www.ioncannon.net/system-administration/128/how-to-create-a-fedora-7-instance-for-ec2/">Fedora 7 AMI setup</a>. I&#039;m going to leave out most of the details and just provide you with a script that will take an empty volume (assumed to be attached as /dev/sdh) and turn it into a bootable EBS backed Fedora 12 volume. Download the script <a href="http://www.ioncannon.net/examples/createfedora12bootebs.sh">createfedora12bootebs.sh</a> instead of trying to cut and paste the following, it gets formatted in such a way as to lose a newline that is important. Please note that you will need at least 1G of space on the given volume.</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh

echo &quot;y&quot; | mkfs.ext3 /dev/sdh
mount /dev/sdh /mnt

mkdir /mnt/dev
mkdir /mnt/proc
mkdir /mnt/etc

for i in console null zero ; do /sbin/MAKEDEV -d /mnt/dev -x $i ; done

cat &lt;&lt;EOL &gt; /mnt/etc/fstab
/dev/sda1               /                       ext3    defaults 1 1
none                    /dev/pts                devpts  gid=5,mode=620 0 0
none                    /dev/shm                tmpfs   defaults 0 0
none                    /proc                   proc    defaults 0 0
none                    /sys                    sysfs   defaults 0 0
/dev/sdc1               /mnt                    ext3    defaults 0 0
/dev/sdc2               swap                    swap    defaults 0 0
EOL

mount -t proc none /mnt/proc

cat &lt;&lt;EOL &gt; /tmp/yumec2.conf
[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
exclude=*-debuginfo
gpgcheck=0
obsoletes=1
reposdir=/dev/null

[base]
name=Fedora 12 – i386 – Base
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-12&amp;arch=i386
enabled=1

[updates-released]
name=Fedora 12 – i386 – Released Updates
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f12&amp;arch=i386
enabled=1
EOL

yum -c /tmp/yumec2.conf --installroot=/mnt -y groupinstall Base
yum -c /tmp/yumec2.conf --installroot=/mnt -y install openssh-server

yum -c /tmp/yumec2.conf --installroot=/mnt -y clean packages

echo &quot;UseDNS no&quot; &gt;&gt; /mnt/etc/ssh/sshd_config
echo &quot;PermitRootLogin without-password&quot; &gt;&gt; /mnt/etc/ssh/sshd_config

cp /etc/rc.local /mnt/etc/
cp /etc/sysconfig/network /mnt/etc/sysconfig/network
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /mnt/etc/sysconfig/network-scripts/ifcfg-eth0
cp /usr/local/sbin/* /mnt/usr/local/sbin/
cp -Rp /lib/modules/2.6.21.7-2.fc8xen/ /mnt/lib/modules/

echo &quot;/sbin/MAKEDEV /dev/urandom&quot; &gt;&gt; /mnt/etc/rc.sysinit
echo &quot;/sbin/MAKEDEV /dev/random&quot; &gt;&gt; /mnt/etc/rc.sysinit
echo &quot;/sbin/MAKEDEV /dev/sdc&quot; &gt;&gt; /mnt/etc/rc.sysinit
echo &quot;/sbin/MAKEDEV /dev/sdc1&quot; &gt;&gt; /mnt/etc/rc.sysinit
echo &quot;/sbin/MAKEDEV /dev/sdc2&quot; &gt;&gt; /mnt/etc/rc.sysinit

cat &lt;&lt;EOF &gt;&gt; /mnt/etc/rc.sysinit
# The following will partition the local drive and set up swap
cat &lt;&lt;EOL | fdisk /dev/sdc
n
p
1
1
+140G
n
p
2

w
EOL
mkswap /dev/sdc2
EOF

mv /mnt/lib/tls /mnt/lib/tls.disabled
echo &quot;hwcap 0 nosegneg&quot; &gt;&gt; /mnt/etc/ld.so.conf.d/kernelcap-2.6.21.7-2.fc8.conf

chroot /mnt chkconfig --level 2345 NetworkManager off
chroot /mnt chkconfig --level 2345 network on

sync
umount /mnt/proc
umount /mnt
</pre>
<p><b>Common wrap up</b></p>
<p>At this point you will need to create a snapshot of the volume that was created for one of the paths above. Once the snapshot is available you will need to then register the snapshot as an AMI that is bootable from EBS. To do that you would issue something like the following command substituting the correct data in where it relates to your volume and snapshot.</p>
<pre class="brush: bash; title: ; notranslate">
ec2-register -n &quot;AMIName&quot; -d &quot;AMI Description&quot; --block-device-mapping /dev/sdc=ephemeral0 --snapshot your-snapname --architecture i386 --kernel aki-a71cf9ce --ramdisk ari-a51cf9cc
</pre>
<p>One thing to note in this command is the &#8211;block-device-mapping option. That option is what gives you access to the local drive on your node once it is booted. This gives you extra storage for things you don&#039;t need to keep after the life of the running node. In the from scratch option I&#039;m turning part of the local drive into swap as well as creating a partition that could be used as a large temporary storage. If you want to know more details on the ephermeral storage look at <a href="http://developer.amazonwebservices.com/connect/thread.jspa?messageID=155916">this post</a></p>
<p>After all that you should have a bootable EBS backed Fedora 12 install to work with.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ioncannon.net/system-administration/894/fedora-12-bootable-root-ebs-on-ec2/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Building Chromium and Chrome OS with EC2</title>
		<link>http://www.ioncannon.net/system-administration/771/building-chromium-and-chrome-os-with-ec2/</link>
		<comments>http://www.ioncannon.net/system-administration/771/building-chromium-and-chrome-os-with-ec2/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 21:17:59 +0000</pubDate>
		<dc:creator>carson</dc:creator>
				<category><![CDATA[system administration]]></category>
		<category><![CDATA[chrome os]]></category>
		<category><![CDATA[chromium]]></category>
		<category><![CDATA[ec2]]></category>

		<guid isPermaLink="false">http://www.ioncannon.net/?p=771</guid>
		<description><![CDATA[When the initial cut of the Chromium OS source was released last week I decided to use the opportunity to see if it would run on my EEE PC 900 netbook (check out EEE PC 900 running Chrome OS on Youtube to see the final result). The first roadblock I hit with the build instructions [...]]]></description>
			<content:encoded><![CDATA[<p>When the initial cut of the <a href="http://www.chromium.org/chromium-os">Chromium OS</a> source was released last week I decided to use the opportunity to see if it would run on my EEE PC 900 netbook (check out <a href="http://www.youtube.com/watch?v=gfQ6Qef5DWk">EEE PC 900 running Chrome OS</a> on Youtube to see the final result). The first roadblock I hit with the <a href="http://sites.google.com/a/chromium.org/dev/chromium-os/building-chromium-os/build-instructions">build instructions</a> was the Ubuntu requirement (I did give a little effort to getting it working on Fedora first). I don&#039;t have an Ubuntu box so I started out trying to use VirtualBox but that was going to take forever so I decided to move things to EC2 and what follows is the result. This isn&#039;t meant to be a replacement for the build docs since they are surely going to change, it is more of a cookbook to build <a href="http://www.chromium.org/Home">Chromium</a> (the browser) and Chromium OS using EC2 (EBS is used as well if you want to cache the source over time).</p>
<p>When I first started down the path of using EC2 I thought I would grab the source each time I wanted to build. I quickly ran into a snag however because it took forever to sync the source and download the Ubuntu repo. Once I had the initial sync of the source I decided I would copy it all to an EBS volume and keep that volume up to date. Using EBS to store the source feels better too since I assume Google expects people to be syncing changes only as opposed to pulling the entire source tree down every time they want to build.</p>
<p>I started out by finding this <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1952&#038;categoryID=101">Ubuntu AMI</a> for a base to work from. For the most efficient compile times I ended up using the High CPU (c1.medium) instance. I started with the default small instance but it was just too slow. With the high cpu instance you are looking at about 45 minutes to build the OS after you have the source synced for the first time and if you add building Chromium in there you are looking at around 55 additional minutes. All told you can have a complete build in less than 2 hours even if there are some source updates needed. For EBS you need a 3G volume for the Chrome OS source plus Ubuntu package repo and a 4G volume for the Chromium source. </p>
<p><span id="more-771"></span></p>
<p>I&#039;ve bundled everything up into one script called <a href="http://www.ioncannon.net/examples/builder.sh">builder.sh</a> and if you don&#039;t care to know the details you can download it and give it a try. There are some things you need to know about it however even if you don&#039;t want to follow all the details. First there are some of the assumptions made by the script:</p>
<ol>
<li>The EC2 AMI ami-ccf615a5 image is used on the node it is run on.</li>
<li>If you are storing the source then you have attached the EBS volumes and you have initialized a filesystem on both with mkfs.ext3 </li>
<li>If you are storing the source then you have attached the EBS volumes and indicated what devices they are using OSVOLDEV and BROWSERVOLDEV in the following config section</li>
<li>You are running the script as the root user</li>
</ol>
<p>Next is a small configuration area at the top of the script that lets it know what devices the two volumes will be mounted on. If you don&#039;t intend on having stored source then you don&#039;t need to worry about setting them to anything as long as what they are set to doesn&#039;t match a real device.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="re2">OSVOLDEV</span>=<span class="sy0">/</span>dev<span class="sy0">/</span>sdf1<br />
<span class="re2">BROWSERVOLDEV</span>=<span class="sy0">/</span>dev<span class="sy0">/</span>sdg1</div>
</div>
<p><br/></p>
<p>There are a few command line options that will let you tune the script if you want to skip parts of the build process:</p>
<ul>
<li>&#45;-skip-sync &#8211; This will skip trying to sync any of the repos. If you aren&#039;t using EBS to store the source the script will fail if you use this option since there will be nothing to build.</li>
<li>&#45;-skip-chrome-build &#8211; This will skip trying to build chrome. You have to build chrome at least once for the chrome os build to work.</li>
<li>&#45;-skip-chrome-os-build &#8211; This will skip trying to build chrome os.</li>
</ul>
<p>Here are a few other important things to make note of:</p>
<ul>
<li>The build script adds a user named &#034;gogo&#034; that can be used to log in if you don&#039;t want to use your Google login.</li>
<li>The build script sets the password for root access to &#034;gogo&#034;.</li>
<li>Running the build script should result in an image named /mnt/builder/<BUILDID>.usb.img.bz when everything is done. This is a compressed bootable image that can be written to a USB key (use something like dd if=usb.img of=/dev/usbkeydevice bs=10M).</li>
<li> I could imagine the same instructions and script being re-purposed for building on a non-EC2 system too.</li>
<li>The script can be run multiple times on the same node and will skip the parts that should only be done once.</li>
<li>There are probably ways to speed up the build to make it even faster. With some more effort the build for the browser could be kicked off while the source for the OS was still be synced. I also wondered if using a 64 bit EC2 node and creating a large ramdisk would help but I didn&#039;t want to fiddle with 64 bit builds of Chrome, I may revisit if I find time.</li>
<li>I was tempted to build an AMI that included all the prerequisites but it only takes 5 minutes to pull all of those together so I decided not to. It could streamline things to do that but I&#039;m not sure that it is worth the effort.</li>
</ul>
<p>If you are looking for more information about the script, places where it might make sense to modify the script and the build process in general then read on. </p>
<p>To get started there are a number of prerequisites that need to be installed. These are the required parts for both Chromium and Chromium OS. One note here is that there is some issue with lighttpd on Ubuntu that causes it to die while the apt-get is downloading all the packages so I had to resort to installing Apache as well. I make sure lighttpd isn&#039;t running since the prerequisites install it.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="re5">-f</span> <span class="sy0">/</span>var<span class="sy0">/</span>run<span class="sy0">/</span>chromepre <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; <span class="kw3">echo</span> <span class="st0">&quot;Prereqs already installed, skipping&#8230;&quot;</span><br />
&nbsp; <span class="kw3">return</span><br />
<span class="kw1">fi</span></p>
<p><span class="kw2">touch</span> <span class="sy0">/</span>var<span class="sy0">/</span>run<span class="sy0">/</span>chromepre</p>
<p><span class="kw2">apt-get</span> <span class="re5">-y</span> <span class="re5">&#8211;force-yes</span> update<br />
<span class="kw2">apt-get</span> <span class="re5">-y</span> <span class="re5">&#8211;force-yes</span> upgrade<br />
<span class="kw2">wget</span> http:<span class="sy0">//</span>src.chromium.org<span class="sy0">/</span>svn<span class="sy0">/</span>trunk<span class="sy0">/</span>src<span class="sy0">/</span>build<span class="sy0">/</span>install-build-deps.sh <span class="re5">-O</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>install-build-deps.sh<br />
<span class="kw2">chmod</span> +x <span class="sy0">/</span>tmp<span class="sy0">/</span>install-build-deps.sh<br />
<span class="kw3">echo</span> <span class="st0">&quot;yy&quot;</span> <span class="sy0">|</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>install-build-deps.sh <span class="co0"># (requires y twice)</span><br />
<span class="sy0">/</span>etc<span class="sy0">/</span>init.d<span class="sy0">/</span>lighttpd stop<br />
<span class="kw2">apt-get</span> <span class="re5">-y</span> <span class="re5">&#8211;force-yes</span> <span class="kw2">install</span> git-core apache2 apt-mirror <span class="kw2">zip</span></p>
<p><span class="kw2">cat</span> <span class="sy0">&gt;</span> <span class="sy0">/</span>etc<span class="sy0">/</span>apt<span class="sy0">/</span>mirror.list <span class="sy0">&lt;&lt;</span>__EOF__<br />
<span class="kw1">set</span> base_path &nbsp; &nbsp;<span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chromeos<span class="sy0">/</span>repo<br />
<span class="kw1">set</span> mirror_path &nbsp;<span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chromeos<span class="sy0">/</span>repo<span class="sy0">/</span>mirror<br />
<span class="kw1">set</span> skel_path &nbsp; &nbsp;<span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chromeos<span class="sy0">/</span>repo<span class="sy0">/</span>skel<br />
<span class="kw1">set</span> nthreads &nbsp; &nbsp; 20<br />
<span class="kw1">set</span> _tilde 0<br />
deb http:<span class="sy0">//</span>build.chromium.org<span class="sy0">/</span>buildbot<span class="sy0">/</span>packages<span class="sy0">/</span> chromeos main restricted universe multiverse<br />
deb http:<span class="sy0">//</span>build.chromium.org<span class="sy0">/</span>buildbot<span class="sy0">/</span>packages<span class="sy0">/</span> chromeos_dev main restricted universe multiverse<br />
clean http:<span class="sy0">//</span>build.chromium.org<span class="sy0">/</span>buildbot<span class="sy0">/</span>packages<span class="sy0">/</span><br />
__EOF__</p>
<p><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="sy0">!</span> <span class="re5">-b</span> <span class="sy0">/</span>dev<span class="sy0">/</span>loop6 <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; <span class="kw2">mknod</span> <span class="re5">-m660</span> <span class="sy0">/</span>dev<span class="sy0">/</span>loop6 b 7 6<br />
<span class="kw1">fi</span></p>
<p><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="sy0">!</span> <span class="re5">-b</span> <span class="sy0">/</span>dev<span class="sy0">/</span>loop7 <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; <span class="kw2">mknod</span> <span class="re5">-m660</span> <span class="sy0">/</span>dev<span class="sy0">/</span>loop7 b 7 7<br />
<span class="kw1">fi</span></div>
</div>
<p><br/></p>
<p>The next step is to create a user that will actually run the build. It turns out to be important that this user is not root so that is why there are some hoops being jumped here. The two source volumes get mounted into the user&#039;s home directory here as well. The last part of this section builds a filesystem to be used as temporary storage for output images. The way they build is set up it will push the final images into the source tree and because that is stored on EBS it could end up eating up a lot of room, there is more to this later in the Chrome OS build section.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="re5">-d</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; <span class="kw3">echo</span> <span class="st0">&quot;Build user already created, skipping&#8230;&quot;</span><br />
&nbsp; <span class="kw3">return</span><br />
<span class="kw1">fi</span></p>
<p>useradd <span class="re5">-G</span> disk <span class="re5">-u</span> 1001 <span class="re5">-s</span> <span class="sy0">/</span>bin<span class="sy0">/</span><span class="kw2">bash</span> <span class="re5">-d</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder <span class="re5">-m</span> builder<br />
<span class="kw3">echo</span> <span class="st0">&quot;builder &nbsp; &nbsp;ALL=NOPASSWD: ALL&quot;</span> <span class="sy0">&gt;&gt;</span> <span class="sy0">/</span>etc<span class="sy0">/</span>sudoers</p>
<p><span class="kw2">mkdir</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chromeos<br />
<span class="kw2">chown</span> builder.builder <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chromeos<span class="sy0">/</span><br />
<span class="kw2">mkdir</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chrome<br />
<span class="kw2">chown</span> builder.builder <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chrome<span class="sy0">/</span></p>
<p><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="re5">-b</span> <span class="re1">$OSVOLDEV</span> <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; <span class="kw2">mount</span> <span class="re1">$OSVOLDEV</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chromeos<span class="sy0">/</span><br />
<span class="kw1">fi</span><br />
<span class="kw1">if</span> <span class="br0">&#91;</span> <span class="re5">-b</span> <span class="re1">$BROWSERVOLDEV</span> <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; <span class="kw2">mount</span> <span class="re1">$BROWSERVOLDEV</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chrome<span class="sy0">/</span><br />
<span class="kw1">fi</span></p>
<p><span class="kw3">echo</span> <span class="st0">&quot;export PATH=<span class="es1">\$</span>PATH:/mnt/builder/chromeos/depot_tools/&quot;</span> <span class="sy0">&gt;&gt;</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>.bashrc</p>
<p><span class="kw2">ln</span> <span class="re5">-s</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chromeos<span class="sy0">/</span>repo<span class="sy0">/</span>mirror<span class="sy0">/</span>build.chromium.org<span class="sy0">/</span>buildbot<span class="sy0">/</span>packages<span class="sy0">/</span> <span class="sy0">/</span>var<span class="sy0">/</span>www<span class="sy0">/</span>packages</p>
<p><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="sy0">!</span> <span class="re5">-f</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>images.img <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; <span class="kw2">dd</span> <span class="kw1">if</span>=<span class="sy0">/</span>dev<span class="sy0">/</span>zero <span class="re2">of</span>=<span class="sy0">/</span>mnt<span class="sy0">/</span>images.img <span class="re2">bs</span>=1 <span class="re2">count</span>=0 <span class="re2">seek</span>=10G<br />
&nbsp; losetup <span class="sy0">/</span>dev<span class="sy0">/</span>loop6 <span class="sy0">/</span>mnt<span class="sy0">/</span>images.img<br />
&nbsp; mkfs.ext3 <span class="sy0">/</span>dev<span class="sy0">/</span>loop6<br />
<span class="kw1">fi</span></p>
<p><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="sy0">!</span> <span class="re5">-d</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chromeos<span class="sy0">/</span>depot_tools<span class="sy0">/</span> <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; <span class="kw2">su</span> &#8211; builder <span class="re5">-c</span> <span class="st0">&quot;cd /mnt/builder/chromeos/; svn co http://src.chromium.org/svn/trunk/tools/depot_tools&quot;</span><br />
<span class="kw1">fi</span></div>
</div>
<p><br/></p>
<p>The next sections each sync either source or the apt-get repository. The first is syncing the apt-get repository using apt-mirror. In case you missed it the mirror was defined in the prerequisites section above.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">su</span> &#8211; builder <span class="re5">-c</span> apt-mirror</div>
</div>
<p><br/></p>
<p>The next is the Chromium OS source repository.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw3">cd</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chromeos<span class="sy0">/</span>chromiumos<span class="sy0">/</span><br />
<span class="kw1">if</span> <span class="br0">&#91;</span> <span class="sy0">!</span> <span class="re5">-f</span> .gclient <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; <span class="kw2">su</span> &#8211; builder <span class="re5">-c</span> <span class="st0">&quot;cd /mnt/builder/chromeos/chromiumos/; /mnt/builder/chromeos/depot_tools/gclient config http://src.chromium.org/git/chromiumos.git&quot;</span><br />
<span class="kw1">fi</span></p>
<p><span class="kw2">su</span> &#8211; builder <span class="re5">-c</span> <span class="st0">&quot;cd /mnt/builder/chromeos/chromiumos/; /mnt/builder/chromeos/depot_tools/gclient sync&quot;</span></div>
</div>
<p><br/></p>
<p>There are a few extra parts to syncing the Chromium browser. One of those extras is to make sure the third party test suites don&#039;t get synced since they are large.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">cat</span> <span class="sy0">&gt;</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>scs.sh <span class="sy0">&lt;&lt;</span>__EOF__<br />
<span class="kw3">export</span> <span class="re2">GYP_DEFINES</span>=<span class="st0">&quot;chromeos=1 target_arch=ia32&quot;</span><br />
<span class="kw3">export</span> <span class="re2">GYP_GENERATORS</span>=<span class="kw2">make</span><br />
<span class="kw3">cd</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chrome<span class="sy0">/</span></p>
<p><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="sy0">!</span> <span class="re5">-f</span> .gclient <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chromeos<span class="sy0">/</span>depot_tools<span class="sy0">/</span>gclient config http:<span class="sy0">//</span>src.chromium.org<span class="sy0">/</span>svn<span class="sy0">/</span>trunk<span class="sy0">/</span>src<br />
&nbsp; <span class="kw2">awk</span> <span class="re5">-f</span> &#8211; .gclient <span class="sy0">&lt;&lt;</span> __END__<br />
<span class="br0">&#123;</span> print <span class="br0">&#125;</span><br />
<span class="sy0">/</span><span class="st0">&quot; &nbsp; &nbsp;&quot;</span>custom_deps<span class="st0">&quot; : {&quot;</span><span class="sy0">/</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; print <span class="st0">&quot; &nbsp; &nbsp;<span class="es1">\&quot;</span>custom_deps<span class="es1">\&quot;</span> : {<span class="es1">\n</span><span class="es1">\&quot;</span>src/third_party/WebKit/LayoutTests<span class="es1">\&quot;</span>: None,&quot;</span> <br />
<span class="br0">&#125;</span><br />
__END__<br />
<span class="kw1">fi</span></p>
<p><span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chromeos<span class="sy0">/</span>depot_tools<span class="sy0">/</span>gclient <span class="kw2">sync</span> <span class="re5">&#8211;deps</span>=<span class="st0">&quot;chromeos,unix&quot;</span></p>
<p><span class="kw3">exit</span><br />
__EOF__</p>
<p><span class="kw2">chmod</span> +x <span class="sy0">/</span>tmp<span class="sy0">/</span>scs.sh</p>
<p><span class="kw2">su</span> &#8211; builder <span class="re5">-c</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>scs.sh</div>
</div>
<p><br/></p>
<p>Building the Chromium browser. This isn&#039;t needed every time. When it is done it sticks the browser in place for the Chromium OS build.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="sy0">!</span> <span class="re5">-d</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chrome.tmp <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; <span class="kw2">su</span> &#8211; builder <span class="re5">-c</span> <span class="st0">&quot;cp -Rp /mnt/builder/chrome /mnt/builder/chrome.tmp&quot;</span><br />
<span class="kw1">fi</span><br />
<span class="kw2">su</span> &#8211; builder <span class="re5">-c</span> <span class="st0">&quot;export PATH=<span class="es2">$PATH</span>:/mnt/builder/chromeos/depot_tools/; /mnt/builder/chromeos/chromiumos/chromiumos.git/src/scripts/build_chrome.sh &#8211;chrome_dir /mnt/builder/chrome.tmp/&quot;</span></div>
</div>
<p><br/></p>
<p>Finally the place where the OS actually gets compiled. The majority of this is right out of the build instructions. One thing to understand here is that the build process creates a chroot environment and then maps the source into that before the build starts. The build is done inside the chroot environment so the build script has to create a temporary script with all the commands that need to run there. One other note here is that the images filesystem created above has to be mapped into the chroot environment and I did that by setting it up as a loopback device then mounting it from inside the chroot environment. After the build is complete I can then get to the filesystem outside of the chroot environment to grab the final image. If you want to change the test user, the system password or get rid of either of those options this is the section to change.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">su</span> &#8211; builder <span class="re5">-c</span> <span class="st0">&quot;/mnt/builder/chromeos/chromiumos/chromiumos.git/src/scripts/make_chroot.sh &#8211;mirror http://localhost/packages/ &#8211;chroot /mnt/builder/chroot &#8211;replace&quot;</span></p>
<p><span class="kw2">cat</span> <span class="sy0">&gt;</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chroot<span class="sy0">/</span>tmp<span class="sy0">/</span>go.sh <span class="sy0">&lt;&lt;</span> __EOF__<br />
<span class="co0">#!/bin/sh</span><br />
<span class="kw2">rm</span> <span class="re5">-f</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>go.sh</p>
<p><span class="kw3">cd</span> ..<span class="sy0">/</span>platform<span class="sy0">/</span>pam_google <span class="sy0">&amp;&amp;</span> .<span class="sy0">/</span>enable_localaccount.sh gogo<br />
<span class="kw3">cd</span> -<br />
<span class="kw3">echo</span> <span class="st0">&quot;gogo&quot;</span> <span class="sy0">|</span> .<span class="sy0">/</span>set_shared_user_password.sh</p>
<p>.<span class="sy0">/</span>build_platform_packages.sh<br />
.<span class="sy0">/</span>build_kernel.sh</p>
<p><span class="kw2">sudo</span> <span class="kw2">mount</span> <span class="sy0">/</span>dev<span class="sy0">/</span>loop6 <span class="sy0">/</span>home<span class="sy0">/</span>builder<span class="sy0">/</span>trunk<span class="sy0">/</span>src<span class="sy0">/</span>build<span class="sy0">/</span>images<span class="sy0">/</span><br />
<span class="kw2">sudo</span> <span class="kw2">chown</span> builder.adm <span class="sy0">/</span>home<span class="sy0">/</span>builder<span class="sy0">/</span>trunk<span class="sy0">/</span>src<span class="sy0">/</span>build<span class="sy0">/</span>images</p>
<p>.<span class="sy0">/</span>build_image.sh <span class="re5">&#8211;mirror</span> http:<span class="sy0">//</span>localhost<span class="sy0">/</span>packages<span class="sy0">/</span></p>
<p><span class="kw2">sudo</span> <span class="kw2">umount</span> <span class="sy0">/</span>home<span class="sy0">/</span>builder<span class="sy0">/</span>trunk<span class="sy0">/</span>src<span class="sy0">/</span>build<span class="sy0">/</span>images<span class="sy0">/</span></p>
<p><span class="kw3">exit</span><br />
__EOF__</p>
<p><span class="kw2">chown</span> builder.builder <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chroot<span class="sy0">/</span>tmp<span class="sy0">/</span>go.sh<br />
<span class="kw2">chmod</span> +x <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chroot<span class="sy0">/</span>tmp<span class="sy0">/</span>go.sh</p>
<p><span class="kw2">su</span> &#8211; builder <span class="re5">-c</span> <span class="st0">&quot;/mnt/builder/chromeos/chromiumos/chromiumos.git/src/scripts/enter_chroot.sh &#8211;chroot /mnt/builder/chroot /tmp/go.sh&quot;</span></p>
<p><span class="kw2">mkdir</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>mnt<span class="sy0">/</span><br />
<span class="kw2">mount</span> <span class="sy0">/</span>dev<span class="sy0">/</span>loop6 <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>mnt<br />
<span class="re2">NEWEST</span>=<span class="sy0">`</span><span class="kw2">ls</span> <span class="re5">-tadr</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>mnt<span class="sy0">/*/</span> <span class="sy0">|</span> <span class="kw2">tail</span> <span class="re5">-1</span> <span class="sy0">|</span> <span class="kw2">head</span> -1<span class="sy0">`</span><br />
<span class="re2">BUILDID</span>=<span class="sy0">`</span><span class="kw2">basename</span> <span class="re1">$NEWEST</span><span class="sy0">`</span><br />
<span class="kw2">dd</span> <span class="kw1">if</span>=<span class="sy0">/</span>dev<span class="sy0">/</span>zero <span class="re2">of</span>=<span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span><span class="re1">$BUILDID</span>.usb.img <span class="re2">bs</span>=1 <span class="re2">count</span>=0 <span class="re2">seek</span>=4G<br />
losetup <span class="sy0">/</span>dev<span class="sy0">/</span>loop7 <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span><span class="re1">$BUILDID</span>.usb.img<br />
<span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>chromeos<span class="sy0">/</span>chromiumos<span class="sy0">/</span>chromiumos.git<span class="sy0">/</span>src<span class="sy0">/</span>scripts<span class="sy0">/</span>image_to_usb.sh <span class="re5">-y</span> <span class="re5">&#8211;from</span>=<span class="re1">$NEWEST</span> <span class="re5">&#8211;to</span>=<span class="sy0">/</span>dev<span class="sy0">/</span>loop7<br />
losetup <span class="re5">-d</span> <span class="sy0">/</span>dev<span class="sy0">/</span>loop7<br />
<span class="kw2">umount</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span>mnt<br />
<span class="kw2">bzip2</span> <span class="re5">-9</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>builder<span class="sy0">/</span><span class="re1">$BUILDID</span>.usb.img</div>
</div>
<p><br/></p>
<p>A final bit of glue looks for command line arguments ties everything together.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="re2">SKIP_SYNC</span>=<span class="kw2">false</span><br />
<span class="re2">SKIP_CHROME_BUILD</span>=<span class="kw2">false</span><br />
<span class="re2">SKIP_CHROME_OS_BUILD</span>=<span class="kw2">false</span></p>
<p><span class="kw1">set</span> <span class="re5">&#8211;</span> $<span class="br0">&#40;</span><span class="kw2">getopt</span> <span class="re5">-l</span> skip-sync,skip-chrome-build,skip-chrome-os-build abc: <span class="st0">&quot;$@&quot;</span><span class="br0">&#41;</span><br />
<span class="kw1">while</span> <span class="br0">&#91;</span> <span class="re4">$#</span> <span class="re5">-gt</span> 0 <span class="br0">&#93;</span><br />
<span class="kw1">do</span><br />
&nbsp; <span class="kw1">case</span> <span class="st0">&quot;$1&quot;</span> <span class="kw1">in</span><br />
&nbsp; &nbsp; <span class="br0">&#40;</span>&#8211;skip-sync<span class="br0">&#41;</span> <span class="re2">SKIP_SYNC</span>=<span class="kw2">true</span>; <span class="kw3">break</span><span class="sy0">;;</span><br />
&nbsp; &nbsp; <span class="br0">&#40;</span>&#8211;skip-chrome-build<span class="br0">&#41;</span> <span class="re2">SKIP_CHROME_BUILD</span>=<span class="kw2">true</span>; <span class="kw3">break</span><span class="sy0">;;</span><br />
&nbsp; &nbsp; <span class="br0">&#40;</span>&#8211;skip-chrome-os-build<span class="br0">&#41;</span> <span class="re2">SKIP_CHROME_OS_BUILD</span>=<span class="kw2">true</span>; <span class="kw3">break</span><span class="sy0">;;</span><br />
&nbsp; &nbsp; <span class="br0">&#40;</span>&#8211;<span class="br0">&#41;</span> <span class="kw3">shift</span>; <span class="kw3">break</span><span class="sy0">;;</span><br />
&nbsp; &nbsp; <span class="br0">&#40;</span>&#8211;<span class="sy0">*</span><span class="br0">&#41;</span> <span class="kw3">echo</span> <span class="st0">&quot;$0: error &#8211; unrecognized option $1&quot;</span> 1<span class="sy0">&gt;&amp;</span><span class="nu0">2</span>; <span class="kw3">exit</span> <span class="nu0">1</span><span class="sy0">;;</span><br />
&nbsp; &nbsp; <span class="br0">&#40;</span><span class="sy0">*</span><span class="br0">&#41;</span> &nbsp;<span class="kw3">break</span><span class="sy0">;;</span><br />
&nbsp; <span class="kw1">esac</span><br />
&nbsp; <span class="kw3">shift</span><br />
<span class="kw1">done</span></p>
<p>install_prereqs<br />
create_build_user</p>
<p><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="st0">&quot;<span class="es2">$SKIP_SYNC</span>&quot;</span> <span class="sy0">!</span>= <span class="st0">&quot;true&quot;</span> <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; sync_apt<br />
&nbsp; sync_chrome<br />
&nbsp; sync_chrome_os<br />
<span class="kw1">fi</span></p>
<p><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="st0">&quot;<span class="es2">$SKIP_CHROME_BUILD</span>&quot;</span> <span class="sy0">!</span>= <span class="st0">&quot;true&quot;</span> <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; build_chrome<br />
<span class="kw1">fi</span></p>
<p><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="st0">&quot;<span class="es2">$SKIP_CHROME_BUILD</span>&quot;</span> <span class="sy0">!</span>= <span class="st0">&quot;true&quot;</span> <span class="br0">&#93;</span><br />
<span class="kw1">then</span><br />
&nbsp; build_chrome_os<br />
<span class="kw1">fi</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.ioncannon.net/system-administration/771/building-chromium-and-chrome-os-with-ec2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Running Asterisk in the cloud with Amazon EC2</title>
		<link>http://www.ioncannon.net/system-administration/131/running-asterisk-in-the-cloud-with-amazon-ec2/</link>
		<comments>http://www.ioncannon.net/system-administration/131/running-asterisk-in-the-cloud-with-amazon-ec2/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 11:39:55 +0000</pubDate>
		<dc:creator>carson</dc:creator>
				<category><![CDATA[system administration]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[ec2]]></category>

		<guid isPermaLink="false">http://www.ioncannon.net/?p=131</guid>
		<description><![CDATA[I have been sitting on a half post for a while now on setting up Asterisk on EC2 and then this past week someone else came out with a post on how to install Asterisk from scratch on EC2. I figured I would wrap up what I have since I take the path of installing [...]]]></description>
			<content:encoded><![CDATA[<p>I have been sitting on a half post for a while now on setting up Asterisk on EC2 and then this past week someone else came out with a post on <a href="http://voxilla.com/2009/02/13/asterisk-amazon-ec2-1178">how to install Asterisk from scratch on EC2</a>. I figured I would wrap up what I have since I take the path of installing Asterisk on VirtualBox first then <a href="http://www.ioncannon.net/system-administration/80/how-to-transfer-linux-from-virtualbox-to-xen/">converting that disk image to an AMI</a> as I outlined a few weeks ago when I got serious about testing out the Asterisk on EC2 concept.</p>
<p>Reading over the comments on the Voxilla post you will see some concern about how cost effective putting Asterisk on EC2 would be. Even if the cost is an issue for normal use I think Asterisk on EC2 could work for bursts of outgoing calls or even temporary conferencing systems. Part of what I wanted to do was find the least resistant path to getting started so I went with Trixbox since it has a lot of tools pre-installed and support for <a href="http://gizmo5.com/">Gizmo5</a> that was very easy to set up. The key with Gizmo5 is that it is cheap, works with Asterisk via SIP and you can have incoming calls for free from a land line so it is easy to test cheaply.</p>
<p><span id="more-131"></span></p>
<p>To start with I&#039;ll point out that the Voxilla guys have done what I&#039;m about to go over here in a different way. A portion of what I do matches up with the Voxilla post but I&#039;m using the AWS console. There is now even a <a href="http://voxilla.com/2009/02/18/asterisk-on-the-cloud-with-a-click-1405">Voxilla public AMI available</a> for people who don&#039;t want to do anything but fire up an Asterisk node.</p>
<p>The steps for this install break down as follows:</p>
<h2>Install Trixbox under VirtualBox</h2>
<p>Start by installing <a href="http://www.trixbox.com/products/trixbox-ce">Trixbox CE</a> under <a href="http://www.virtualbox.org/">VirtualBox</a>. I&#039;m currently using VirtualBox 2.1.4 but older versions will probably work equally as well. Grab the <a href="http://www.trixbox.org/downloads">Trixbox CE ISO</a> and create a 2G partition to do the install. Here is the VirtualBox configuration I used:</p>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/VirtualBox-Trixbox-Setup.png"><img title="TrixBox VirtualBox configuration" alt="TrixBox VirtualBox configuration" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/VirtualBox-Trixbox-Setup_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
<p>The install only takes a few minutes:</p>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/Trixbox-Install.png"><img title="Installing TrixBox" alt="Installing TrixBox" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/Trixbox-Install_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
<p>Then when you are done you should let it boot:</p>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/Trixbox-Login.png"><img title="TrixBox login" alt="TrixBox login" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/Trixbox-Login_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
<p>After doing the Trixbox install you should follow instructions to <a href="http://www.ioncannon.net/system-administration/80/how-to-transfer-linux-from-virtualbox-to-xen/">extract the image from the VDI and create as an AMI</a>. You should end with a bootable AMI that will start TrixBox once you are finished.</p>
<h2>Create a security group to allow Asterisk traffic</h2>
<p>The following closely matches what the Voxilla article has except for the use of AWS Management Console everywhere. I&#039;m not really concerned with having a static IP assigned to the node so I&#039;ve skipped that part. Depending on how you want to use the system you may not need one at all.</p>
<p>Start by going into the &#034;security groups&#034; option off the main console page:</p>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/AWS_Management_Console_-_Security_Groups.png"><img title="AWS Management Console security groups" alt="AWS Management Console security groups" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/AWS_Management_Console_-_Security_Groups_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
<p>Create a new group that will contain the security rules. I&#039;ve named mine &#034;Trixbox&#034;:</p>
<p><img title="AWS Management Console create security group" alt="AWS Management Console create security group" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/AWS_Management_Console_-_Create_new_group.png"/><br/><br />
<img title="AWS Management Console security group detail" alt="AWS Management Console security group detail" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/AWS_Management_Console_-_create_details.png"/><br/></p>
<p>There are 5 rules that are needed. They are ssh, http, udp ports 10000 to 20000, tcp 5060 to 5061, and udp 5060 to 5060. Here is what my security group looks like:</p>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/AWS_Management_Console_-_firewall_setup.png"><img title="AWS Management Console security group VOIP" alt="AWS Management Console security group VOIP" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/AWS_Management_Console_-_firewall_setup_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
<p>Note that in the above I&#039;m opening everything up to the world for each entry but you probably want to restrict things more based on where the traffic will be coming from. At the very least if you open the http port to the world make sure to change all the default passwords.</p>
<p>Now you are ready to launch the instance. Find the &#034;Launch Instances&#034; button on the main console page:</p>
<p><img title="AWS Management Console start instances" alt="AWS Management Console start instances" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/AWS_Management_Console_-_start_instances.png"/><br/></p>
<p>Find the AMI that was created from the TrixBox install:</p>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/AWS_Management_Console_-_select_instance.png"><img title="AWS Management Console EC2 AMI selection" alt="AWS Management Console EC2 AMI selection" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/AWS_Management_Console_-_select_instance_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
<p>Configure the instance for launch:</p>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/AWS_Management_Console_-_configure_instance.png"><img title="AWS Management Console EC2 instance configuration" alt="AWS Management Console EC2 instance configuration" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/AWS_Management_Console_-_configure_instance_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
<p>Notice that the advanced area is open and there is a specialized kernel (<a href="http://developer.amazonwebservices.com/connect/entry!default.jspa?categoryID=116&#038;externalID=1350">aki-9b00e5f2</a>) that was selected. This is from the Voxilla article and the kernel has a higher frequency clock that makes audio lag less.</p>
<p>Once you have hit launch and the instance has started you should be able to ssh into it and verify that Asterisk is running if you wish. You can actually do all the configuration through the web interface so you don&#039;t have to log in if you have faith that everything started as it should.</p>
<h2>Configure Asterisk with the web console</h2>
<p>You should now be able to put the running instance name into your browser and bring up the web user console.</p>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/trixbox_-_User_Mode_-_main.png"><img title="TrixBox user main" alt="TrixBox user main" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/trixbox_-_User_Mode_-_main_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
<p>There are a few initial changes that need to be made to get the box running smoothly so switch to maintenance mode by clicking the &#034;maint&#034; link on the top right. You will need to use the default username and password (see the <a href="http://trixbox.org/wiki/trixbox-quick-install-guide">TrixBox documentation</a>):</p>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/trixbox_-_Admin_Mode_-_admin_main.png"><img title="TrixBox maintenance main" alt="TrixBox maintenance main" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/trixbox_-_Admin_Mode_-_admin_main_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
<p>Because the external IP is nated you will need to edit one of the configuration files to contain the external IP. Grab the external IP of your instance by pinging the hostname. From the main maintenance screen pick PBX then &#034;Config file editor&#034;. Find the filename in the list of configuration files named &#034;sip_general_custom.conf&#034; and click it.</p>
<p><img title="TrixBox SIP customization file" alt="TrixBox SIP customization file" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/trixbox_-_Admin_Mode_-_sip_custom.png"><br/></p>
<p>Put the following information in the entry box, remember to use the instance IP:</p>
<div class="codesnip-container" >externip=<your instance ip here><br />
localnet=10.0.0.0/255.0.0.0<br />
nat=yes</div>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/trixbox_-_Admin_Mode_-_custom_sip_nat.png"><img title="TrixBox SIP NAT setup" alt="TrixBox SIP NAT setup" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/trixbox_-_Admin_Mode_-_custom_sip_nat_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
<p>If you want to find out more about SIP and NAT then check out <a href="http://www.voip-info.org/wiki/view/Asterisk+sip+nat">Asterisk SIP and NAT</a> as well as <a href="http://www.voip-info.org/tiki-index.php?page=Asterisk+SIP+externip">Asterisk SIP externip</a>.</p>
<p>Now you should have the NAT configuration working. One thing to take note of is that any change you make will require a reload of the Asterisk system. Don&#039;t worry though you still need to add extensions before anything is useful and you can reload after that.</p>
<p>Follow the FreePBX <a href="http://www.freepbx.org/support/documentation/administration-guide/adding-extensions">adding extensions</a> guide to set up a few extensions.</p>
<p>I also went ahead and made one of the extensions the default inbound for testing:</p>
<p><img title="TrixBox Inbound configuration" alt="TrixBox Inbound configuration" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/trixbox_-_Admin_Mode_-_inbound.png"/><br/></p>
<p>At this point you should be able to use a VOIP phone to connect to your node and access voicemail or call from one extension to another.</p>
<h2>Use the web console to configure Gizmo5 support</h2>
<p>At this point you could just use the system for VOIP calls between extensions but that wouldn&#039;t be much fun. You really need a VOIP gateway to be able to call out and get calls in. This is where Gizmo5 comes in. You will need a Gizmo5 account before you proceed.</p>
<p>The setup with Trixbox is just a few clicks. Go to PBX, Gizmo5 and then enter your Gizmo5 login information:</p>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/trixbox_-_Admin_Mode_-_gizmo5_step1.png"><img title="TrixBox Gizmo5 configuration" alt="TrixBox Gizmo5 configuration" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/trixbox_-_Admin_Mode_-_gizmo5_step1_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
<p>After this you probably want to set up the outbound route:</p>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/trixbox_-_Admin_Mode_-_gizmo_outbound.png"><img title="TrixBox Gizmo5 outbound" alt="TrixBox Gizmo5 outbound" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/trixbox_-_Admin_Mode_-_gizmo_outbound_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
<p>You can test the Gizmo5 integration by calling one of their <a href="http://gizmo5.com/pc/network/access-numbers/">free access numbers</a>. You will first need to log in and get your Gizmo5 SIP number:</p>
<p><a href="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/Gizmo5_-_sip_number.png"><img title="Gizmo5 SIP number" alt="Gizmo5 SIP number" src="http://d28nuaxr58rcpu.cloudfront.net/img/asteriskec2/Gizmo5_-_sip_number_small.png"/></a><br/>(Click the image to see a larger version)<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ioncannon.net/system-administration/131/running-asterisk-in-the-cloud-with-amazon-ec2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to transfer a Linux image from VirtualBox to Xen</title>
		<link>http://www.ioncannon.net/system-administration/80/how-to-transfer-linux-from-virtualbox-to-xen/</link>
		<comments>http://www.ioncannon.net/system-administration/80/how-to-transfer-linux-from-virtualbox-to-xen/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 19:19:11 +0000</pubDate>
		<dc:creator>carson</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[system administration]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[virtual box]]></category>

		<guid isPermaLink="false">http://www.ioncannon.net/?p=80</guid>
		<description><![CDATA[There have been times recently when I wanted to pull a VirtualBox Linux instance I had into Xen. I kept thinking it had to be fairly easy but I kept putting off trying it until recently when I ran into something I wanted to install from a CD image into an Amazon EC2 AMI. It [...]]]></description>
			<content:encoded><![CDATA[<p>There have been times recently when I wanted to pull a <a href="http://www.virtualbox.org/">VirtualBox</a> Linux instance I had into Xen. I kept thinking it had to be fairly easy but I kept putting off trying it until recently when I ran into something I wanted to install from a CD image into an Amazon EC2 AMI. It turns out the main hurdle in transferring an image is lack of documentation.</p>
<p><span id="more-80"></span></p>
<p>I&#039;m using VirtualBox 2.1.0 so some of the following commands may not work with older versions. I learned the hard way that they have changed a number of tools for VirtualBox and some of the older tools where probably easier to use and documented better. I installed the package I was using from an ISO image and then started trying to extract the part that I needed from the VDI that was created.</p>
<p>My first attempt at extracting the partition required me to convert my dynamic VDI into a static image. To dump a dynamic VDI into a static image you run this command:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;">VBoxManage convertdd <span class="re5">-static</span> abox.vdi <span class="sy0">/</span>tmp<span class="sy0">/</span>abox.img</div>
</div>
<p>I thought I could find the image by hand in the VDI after I had it in a raw format. There were a number of hints that I found that made me think I could just pull the partition out without much of a problem: <a href="http://forensicir.blogspot.com/2008/01/virtualbox-and-forensics-tools.html">VirtualBox and forensics tools</a> and <a href="http://forums.virtualbox.org/viewtopic.php?t=52&#038;start=0&#038;postdays=0&#038;postorder=asc&#038;highlight=">a forum post</a>. However I found that just looking around wasn&#039;t easy enough to find where the partition started so I moved on to trying to find something else that could scan the disk and find it.</p>
<p>I rand into <a href="http://www.cgsecurity.org/wiki/TestDisk">TestDisk</a> and gave it a try. When it would scan the disk it found the /boot partition but for some reason it wasn&#039;t finding the root partition so I moved on.</p>
<p>I then took a look at the <a href="http://forums.virtualbox.org/viewtopic.php?t=8046">format for VDI disks</a> to see if it was possible to pull it out given the header information with a simple program but that looked like it would be a lot of work so it was back to square one.</p>
<p>Along the way I happened to came across information about an undocumented command to <a href="http://www.virtualbox.org/changeset/12775">export</a> raw <a href="http://techokarma.blogspot.com/2008/10/v2p-virtual-to-physical-for-virtualbox.html">disk image</a>. This turned out to be the break I needed because running the following command will result in only the disk image itself without any VirtualBox residue:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;">VBoxManage internalcommands converttoraw myosimage.vdi <span class="sy0">/</span>tmp<span class="sy0">/</span>myosimage.img</div>
</div>
<p>At this point things became a lot easier. There were multiple partitions on the resulting disk image but I only needed the / partition. To extract the root partition I first listed the partitions with this command:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;">fdisk <span class="re5">-lu</span> myosimage.img</div>
</div>
<p>This output the following for my image:</p>
<div class="codesnip-container" >
<div class="text codesnip" style="font-family:monospace;">You must set cylinders.<br />
You can do this from the extra functions menu.</p>
<p>Disk myosimage.img: 0 MB, 0 bytes<br />
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors<br />
Units = sectors of 1 * 512 = 512 bytes<br />
Disk identifier: 0x0003f47f</p>
<p>&nbsp; &nbsp; &nbsp; Device Boot &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Start &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End &nbsp; &nbsp; &nbsp; &nbsp; Blocks &nbsp; &nbsp;Id &nbsp;System<br />
myosimage.img1 &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;63 &nbsp; &nbsp; &nbsp; 208844 &nbsp; &nbsp; &nbsp; &nbsp;104391 &nbsp; 83 &nbsp;Linux<br />
myosimage.img2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;208845 &nbsp; &nbsp; &nbsp;3662819 &nbsp; &nbsp; 1726987+ &nbsp;83 &nbsp;Linux<br />
myosimage.img3 &nbsp; &nbsp; &nbsp; &nbsp; 3662820 &nbsp; &nbsp; 4192964 &nbsp; &nbsp; &nbsp; 265072+ &nbsp;82 &nbsp;Linux swap / Solaris</div>
</div>
<p>To figure out where the root partition starts I just multiplied the start sector by the number of bytes per sector:  208845 * 512 = 106928640</p>
<p>I then did a quick test to make sure I had the correct partition:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">mount</span> <span class="re5">-o</span> loop,<span class="re2">offset</span>=<span class="nu0">106928640</span> myosimage.img <span class="sy0">/</span>mnt<span class="sy0">/</span></div>
</div>
<p>This looked good so I extracted the partition from the disk and did a filesystem check on it:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">dd</span> <span class="kw1">if</span>=myosimage.img <span class="re2">of</span>=mypartimage.img <span class="re2">bs</span>=512 <span class="re2">skip</span>=208845 <span class="re2">count</span>=<span class="nu0">3453974</span><br />
e2fsck mypartimage.img</div>
</div>
<p>Extracting the partition you want is about 80% of the battle. Getting it to run under Xen after extraction is just a matter of fixing anything that was left out because the install was done under a &#034;real&#034; machine. </p>
<p>I add a nosegneg ld.so.conf directive and move /lib/tls directory out of the way first:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw3">echo</span> <span class="st0">&quot;hwcap 0 nosegneg&quot;</span> <span class="sy0">&gt;</span> &nbsp;<span class="sy0">/</span>mnt<span class="sy0">/</span>etc<span class="sy0">/</span>ld.so.conf.d<span class="sy0">/</span>nosegneg.conf<br />
<span class="kw2">mv</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>lib<span class="sy0">/</span>tls <span class="sy0">/</span>mnt<span class="sy0">/</span>lib<span class="sy0">/</span>tls.disabled</div>
</div>
<p>Next the base device entries needed to be created:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw1">for</span> i <span class="kw1">in</span> console null zero ; <span class="kw1">do</span> <span class="sy0">/</span>sbin<span class="sy0">/</span>MAKEDEV <span class="re5">-d</span> <span class="sy0">/</span>mnt<span class="sy0">/</span>dev <span class="re5">-x</span> <span class="re1">$i</span> ; <span class="kw1">done</span></div>
</div>
<p>I then removed the disk label from the partition using e2label:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;">e2label mypartimage.img <span class="st0">&quot;&quot;</span></div>
</div>
<p>Because I was sending this image to EC2 I recreated the fstab with the following entries that are specific to the way EC2 allocates disks to a node:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="sy0">/</span>dev<span class="sy0">/</span>sda1 &nbsp;<span class="sy0">/</span> &nbsp; &nbsp; &nbsp; &nbsp; ext3 &nbsp; &nbsp;defaults &nbsp; &nbsp; &nbsp; &nbsp;<span class="nu0">1</span> <span class="nu0">1</span><br />
<span class="sy0">/</span>dev<span class="sy0">/</span>sda2 &nbsp;<span class="sy0">/</span>mnt &nbsp; &nbsp; &nbsp;ext3 &nbsp; &nbsp;defaults &nbsp; &nbsp; &nbsp; &nbsp;<span class="nu0">1</span> <span class="nu0">2</span><br />
<span class="sy0">/</span>dev<span class="sy0">/</span>sda3 &nbsp;swap &nbsp; &nbsp; &nbsp;swap &nbsp; &nbsp;defaults &nbsp; &nbsp; &nbsp; &nbsp;<span class="nu0">0</span> <span class="nu0">0</span></div>
</div>
<p>The finally, again because I was going to EC2 I added a few scripts and created rc.local to let me in when the instance was started. </p>
<p>This seems to be a fairly easy process now that I have done it from start to finish once.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ioncannon.net/system-administration/80/how-to-transfer-linux-from-virtualbox-to-xen/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Automounting Amazon EBS volumes on EC2 instances</title>
		<link>http://www.ioncannon.net/system-administration/199/automounting-amazon-ebs-volumes-on-ec2-instances/</link>
		<comments>http://www.ioncannon.net/system-administration/199/automounting-amazon-ebs-volumes-on-ec2-instances/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 14:54:47 +0000</pubDate>
		<dc:creator>carson</dc:creator>
				<category><![CDATA[system administration]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[EBS]]></category>
		<category><![CDATA[ec2]]></category>

		<guid isPermaLink="false">http://www.ioncannon.net/?p=199</guid>
		<description><![CDATA[I&#039;ve been using S3 to store semi-transient information like log files from EC2 nodes in the past but recently decided to give Amazon&#039;s Elastic Block Store (EBS) a try instead. I quickly realized a downside to using EBS in that there is no mechanism for auto-attach and mounting volumes when an AMI is launched. This [...]]]></description>
			<content:encoded><![CDATA[<p>I&#039;ve been using <a href="http://aws.amazon.com/s3/">S3</a> to store semi-transient information like log files from <a href="http://aws.amazon.com/ec2/">EC2</a> nodes in the past but recently decided to give Amazon&#039;s Elastic Block Store (EBS) a try instead. I quickly realized a downside to using EBS in that there is no mechanism for auto-attach and mounting volumes when an AMI is launched. This is probably something Amazon will fix at some point and allow you to launch a given AMI with an attached EBS volume but until then you need some way of doing it yourself. The following is a simple way of using ruby to make it happen.</p>
<p><span id="more-199"></span></p>
<p>I&#039;m going to assume you have already created your EBS volume, if you haven&#039;t you can learn more about that from the <a href="http://docs.amazonwebservices.com/AWSEC2/2008-12-01/DeveloperGuide/index.html?ebs-creating.html">docs</a>. You will need to make sure ruby is installed on the AMI you are going to use and that the <a href="http://rightaws.rubyforge.org/">RightScale AWS</a> gem is installed as well. </p>
<p>The following script grabs the instance id from the <a href="http://docs.amazonwebservices.com/AWSEC2/2008-12-01/DeveloperGuide/index.html?AESDG-chapter-instancedata.html">EC2 metadata URL</a>. It then uses the <a href="http://rightaws.rubyforge.org/right_aws_gem_doc/classes/RightAws/Ec2.html">RightScale EC2</a> calls to attach the volume to the current EC2 instance. After the attach call it may take a few seconds for the volume to become ready so the script sleeps for a few seconds before calling out to the system to mount the device. One enhancement that is obvious here would be to have the script make a RightScale EC2 call to determine when the volume is really ready and then continue after that.</p>
<div class="codesnip-container" >
<div class="ruby codesnip" style="font-family:monospace;"><span class="co1">#!/usr/bin/ruby</span></p>
<p><span class="kw3">require</span> <span class="st0">&#039;rubygems&#039;</span><br />
<span class="kw3">require</span> <span class="st0">&#039;right_aws&#039;</span><br />
<span class="kw3">require</span> <span class="st0">&#039;net/http&#039;</span></p>
<p>url = <span class="st0">&#039;http://169.254.169.254/2008-02-01/meta-data/instance-id&#039;</span><br />
instance_id = <span class="re2">Net::HTTP</span>.<span class="me1">get_response</span><span class="br0">&#40;</span><span class="kw4">URI</span>.<span class="me1">parse</span><span class="br0">&#40;</span>url<span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">body</span></p>
<p>AMAZON_PUBLIC_KEY=<span class="st0">&#039;your public key&#039;</span><br />
AMAZON_PRIVATE_KEY=<span class="st0">&#039;your private key&#039;</span><br />
EC2_LOG_VOL=<span class="st0">&#039;the volume id&#039;</span></p>
<p>ec2 = <span class="re2">RightAws::Ec2</span>.<span class="me1">new</span><span class="br0">&#40;</span>AMAZON_PUBLIC_KEY, AMAZON_PRIVATE_KEY<span class="br0">&#41;</span></p>
<p>vol = ec2.<span class="me1">attach_volume</span><span class="br0">&#40;</span>EC2_LOG_VOL, instance_id, <span class="st0">&#039;/dev/sdh&#039;</span><span class="br0">&#41;</span><br />
<span class="kw3">puts</span> vol</p>
<p><span class="co1"># It can take a few seconds for the volume to become ready. </span><br />
<span class="co1"># This is just to make sure it is ready before mounting it.</span><br />
<span class="kw3">sleep</span> 20</p>
<p><span class="kw3">system</span><span class="br0">&#40;</span><span class="st0">&#039;mount /dev/sdh /mymountpoint&#039;</span><span class="br0">&#41;</span></div>
</div>
<p>I called the script mountlogs.rb and call it out of the local startup script /etc/rc.local so it mounts the disk on startup. This seems to work pretty well as a stopgap until Amazon puts in place a way to auto-attach EBS volumes to instance creation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ioncannon.net/system-administration/199/automounting-amazon-ebs-volumes-on-ec2-instances/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

