<?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>BlueGecko Denmark</title>
	<atom:link href="https://bluegecko.dk/tag/persistent-boot/feed/" rel="self" type="application/rss+xml" />
	<link>https://bluegecko.dk</link>
	<description>Your remote dba</description>
	<lastBuildDate>Tue, 02 Mar 2010 22:51:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.2</generator>
	<item>
		<title>EC2 persistent boots with pivot root</title>
		<link>https://bluegecko.dk/ec2-persistent-boots-with-pivot-root/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ec2-persistent-boots-with-pivot-root</link>
					<comments>https://bluegecko.dk/ec2-persistent-boots-with-pivot-root/#comments</comments>
		
		<dc:creator><![CDATA[rharwood]]></dc:creator>
		<pubDate>Tue, 02 Mar 2010 22:51:48 +0000</pubDate>
				<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[busybox]]></category>
		<category><![CDATA[busyroot]]></category>
		<category><![CDATA[ebs volume]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[persistent boot]]></category>
		<category><![CDATA[pivot root]]></category>
		<guid isPermaLink="false">http://www.bluegecko.net/?p=801</guid>

					<description><![CDATA[Amazon recently allowed Elastic Block Store to boot persistent images. However, there are two concerns I have with the method. * The EBS boot volumes must be EBS Snapshots, which cost more than regular EBS volumes. (http://aws.amazon.com/ec2/#pricing) * The EBS boot volumes currently do not work within the Virtual Private Cloud (VPC) infrastructure. (http://aws.amazon.com/vpc/faqs/#45) To [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Amazon recently allowed Elastic Block Store to boot persistent images. However, there are two concerns I have with the method.</p>
<p>* The EBS boot volumes must be EBS Snapshots, which cost more than regular EBS volumes.  (http://aws.amazon.com/ec2/#pricing)<br />
* The EBS boot volumes currently do not work within the Virtual Private Cloud (VPC) infrastructure.  (http://aws.amazon.com/vpc/faqs/#45)<span id="more-801"></span></p>
<p>To work around these two issues, it is possible to &#8220;pivot&#8221; from a normal AMI&#8217;s local root volume (/dev/sda1) to an arbitrary EBS volume that contains a full OS installation. An additional benefit is that a very small AMI may be used to launch the EBS backed instance, so that the instance launches much faster than a large AMI.</p>
<p>The goal of this post is to provide instructions on how to build a small AMI that is capable of launching a full-blown persistent Linux installation that is backed on EBS storage. BusyBox, &#8220;The Swiss Army Knife of Embedded Systems&#8221;, provides a solid foundation for our small AMI. To build a BusyBox AMI and an instance backed by EBS, simply follow these directions:</p>
<p>1. Start an instance from an AMI that is running the desired kernel and software configuration. (You can use an existing public AMI or a custom AMI that you created. Personally, I prefer to create my own AMI&#8217;s, so I know what is in them.)</p>
<p>2. Log into the instance.</p>
<p>3. Download the latest version of BusyBox.</p>
<p>wget &#8220;http://busybox.net/downloads/busybox-1.15.3.tar.bz2&#8221;</p>
<p>4. Create a busyroot directory.</p>
<p>mkdir busyroot</p>
<p>5. Extract BusyBox.</p>
<p>bunzip2 busybox-1.15.3.tar.bz2<br />
tar xvf busybox-1.15.3.tar</p>
<p>6. Configure BusyBox. (You can experiment here to reduce the image size, but the configuration listed below works.)</p>
<p>cd busybox-1.15.3<br />
make config<br />
Select &#8220;y&#8221; for the STATIC option and the default values for everything else.<br />
Build BusyBox as a static binary (no shared libs) (STATIC) [N/y/?] y</p>
<p>7. Make and install BusyBox.</p>
<p>make CONFIG_PREFIX=$HOME/busyroot install<br />
chmod 4755 $HOME/busyroot/bin/busybox</p>
<p>8. Create required directories.</p>
<p>cd $HOME/busyroot<br />
mkdir dev sys etc proc mnt mnt/new-root</p>
<p>9. Create the necessary devices. (We will use /dev/sdj for the EBS volume, but this could be any block device not used by the normal AMI.)</p>
<p>MAKEDEV -d $HOME/busyroot/dev -x sdj<br />
MAKEDEV -d $HOME/busyroot/dev -x console<br />
MAKEDEV -d $HOME/busyroot/dev -x null<br />
MAKEDEV -d $HOME/busyroot/dev -x zero</p>
<p>10. Create the init file.</p>
<p>mv $HOME/busyroot/sbin/init $HOME/busyroot/sbin/init.orig<br />
cat &lt;&lt;&#8216;EOL&#8217; &gt;  $HOME/busyroot/sbin/init<br />
#!/bin/busybox sh<br />
PATH=/bin:/usr/bin:/sbin:/usr/sbin<br />
NEWDEV=&#8221;/dev/sdj&#8221;<br />
NEWTYP=&#8221;ext3&#8243;<br />
NEWMNT=&#8221;/mnt/new-root&#8221;<br />
OLDMNT=&#8221;/mnt/old-root&#8221;<br />
OPTIONS=&#8221;noatime,ro&#8221;<br />
SLEEP=10</p>
<p>echo &#8220;Remounting writable.&#8221;<br />
mount -o remount,rw /<br />
[ ! -d $NEWMNT ] &amp;&amp; echo &#8220;Creating directory $NEWMNT.&#8221; &amp;&amp; mkdir -p $NEWMNT</p>
<p>while true ; do<br />
echo &#8220;sleeping&#8230;&#8221;<br />
sleep $SLEEP<br />
echo &#8220;Trying to mount $NEWDEV writable.&#8221;<br />
mount -t $NEWTYP -o rw $NEWDEV $NEWMNT || continue<br />
echo &#8220;Mounted.&#8221;<br />
break;<br />
done</p>
<p>[ ! -d $NEWMNT/$OLDMNT ] &amp;&amp; echo &#8220;Creating directory $NEWMNT/$OLDMNT.&#8221; &amp;&amp; mkdir -p $NEWMNT/$OLDMNT</p>
<p>echo &#8220;Remounting $NEWMNT $OPTIONS.&#8221;<br />
mount -o remount,$OPTIONS $NEWMNT</p>
<p>echo &#8220;Trying to pivot.&#8221;<br />
cd $NEWMNT<br />
pivot_root . ./$OLDMNT</p>
<p>for dir in /dev /proc /sys; do<br />
echo &#8220;Moving mounted file system ${OLDMNT}${dir} to $dir.&#8221;<br />
mount &#8211;move ./${OLDMNT}${dir} ${dir}<br />
done</p>
<p>echo &#8220;Trying to chroot.&#8221;<br />
exec chroot . /bin/sh -c &#8220;umount ./$OLDMNT; exec /sbin/init $*&#8221; &lt; /dev/console &gt; /dev/console 2&gt;&amp;1<br />
EOL</p>
<p>chmod 755 $HOME/busyroot/sbin/init</p>
<p>11. Create the fstab file.</p>
<p>cat &lt;&lt;&#8216;EOL&#8217; &gt;  $HOME/busyroot/etc/fstab<br />
/dev/sda1 /     ext3    defaults 1 1<br />
none      /dev/pts devpts  gid=5,mode=620 0 0<br />
none      /proc proc    defaults 0 0<br />
none      /sys  sysfs   defaults 0 0<br />
EOL</p>
<p>12. Create a 4MB loopback file.</p>
<p>cd<br />
dd if=/dev/zero of=busybox.fs bs=1M count=4<br />
mkfs.ext3 busybox.fs</p>
<p>13. Mount the loopback file.</p>
<p>mkdir $HOME/busyimg<br />
mount -o loop $HOME/busybox.fs $HOME/busyimg</p>
<p>14. Copy the staged files and directories to the image. (Technically, the BusyBox image could have been built directly in $HOME/busyimg, but we were not sure how big the image was going to be.)</p>
<p>cp -rp $HOME/busyroot/* $HOME/busyimg</p>
<p>15. Un-mount the image.</p>
<p>sync<br />
umount -d $HOME/busyimg</p>
<p>16. Set environment variables.</p>
<p>export EC2_HOME=/opt/ec2-api-tools<br />
export EC2_CERT=/path/to/your/cert.pem<br />
export EC2_PRIVATE_KEY=/path/to/your/pk.pem<br />
export AWS_ACCOUNT_NUMBER=&#8221;NNNN-NNNN-NNNN&#8221;<br />
export AWS_ACCESS_KEY_ID=your_key<br />
export AWS_SECRET_ACCESS_KEY=your_secret_key<br />
export EC2_BUCKET=&#8221;your_bucket&#8221;<br />
export JAVA_HOME=/usr/java/default<br />
export ARCH=`uname -i`<br />
export AKI=`curl -s http://169.254.169.254/latest/meta-data/kernel-id`<br />
export ARI=`curl -s http://169.254.169.254/latest/meta-data/ramdisk-id`<br />
export INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`<br />
export AVAIL_ZONE=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`<br />
export SEC_GROUP=`curl -s http://169.254.169.254/latest/meta-data/security-groups`<br />
export PUB_KEY=`wget -q -O &#8211; &#8220;http://169.254.169.254/latest/meta-data/public-keys&#8221; | awk -F= &#8216;{print $2}&#8217;`</p>
<p>17. Bundle the image.</p>
<p>ec2-bundle-image -i $HOME/busybox.fs -d /tmp -k $EC2_PRIVATE_KEY -c $EC2_CERT -u $AWS_ACCOUNT_NUMBER -r $ARCH &#8211;kernel $AKI &#8211;ramdisk $ARI</p>
<p>18. Upload the image.</p>
<p>ec2-upload-bundle -b $EC2_BUCKET -m /tmp/busybox.fs.manifest.xml -a $AWS_ACCESS_KEY_ID -s $AWS_SECRET_ACCESS_KEY</p>
<p>19. Register the AMI.</p>
<p>BUSYBOX_AMI=`ec2-register &#8220;$EC2_BUCKET/busybox.fs.manifest.xml&#8221; | awk &#8216;{print $2}&#8217;`<br />
echo &#8220;BUSYBOX_AMI: $BUSYBOX_AMI&#8221;</p>
<p>20. Create an EBS volume of the desired size (10G or more) in the desired availability zone.</p>
<p>VOLUME_ID=`ec2-create-volume -s 10 -z $AVAIL_ZONE | awk &#8216;{print $2}&#8217;`<br />
echo &#8220;VOLUME_ID: $VOLUME_ID&#8221;</p>
<p>21. Attach the volume to the current instance as /dev/sdj.</p>
<p>ec2-attach-volume $VOLUME_ID -i $INSTANCE_ID -d /dev/sdj</p>
<p>22. Create an EXT3 file system on /dev/sdj.</p>
<p>mkfs.ext3 /dev/sdj</p>
<p>22. Mount the EBS volume.</p>
<p>mkdir /mnt/ebs_boot<br />
mount /dev/sdj /mnt/ebs_boot</p>
<p>23. Copy the current AMI to the EBS volume.</p>
<p>rsync -avHx / /mnt/ebs_boot</p>
<p>24. Fix the /etc/fstab file.</p>
<p>vi /mnt/ebs_boot/etc/fstab<br />
Remove the local file systems.<br />
/dev/sda1  /         ext3    defaults        1 1<br />
/dev/sdb  /mnt      ext3    defaults        1 2<br />
/dev/sda3  swap      swap    defaults        0 0<br />
Add the /dev/sdj file system.<br />
/dev/sdj  /         ext3    defaults        1 1</p>
<p>25. Fix the /etc/inittab file. The cloud AMI&#8217;s are normally configured for runlevel 4.</p>
<p>vi /mnt/ebs_boot/etc/inittab<br />
Edit the following line if necessary:<br />
id:4:initdefault:</p>
<p>26. Un-mount the EBS volume.</p>
<p>sync<br />
umount /mnt/ebs_boot</p>
<p>27. Detach the volume.</p>
<p>ec2-detach-volume $VOLUME_ID -i $INSTANCE_ID -d /dev/sdj</p>
<p>28. Create a new instance running the BusyBox AMI.</p>
<p>BUSYBOX_ID=`ec2-run-instances $BUSYBOX_AMI -z $AVAIL_ZONE -k $PUB_KEY -g $SEC_GROUP | awk &#8216;{print $6}&#8217;`</p>
<p>29. Wait until the instance is running&#8230;</p>
<p>ec2-describe-instances $BUSYBOX_ID</p>
<p>30. Attach the EBS volume to the BusyBox instance as /dev/sdj.</p>
<p>ec2-attach-volume $VOLUME_ID -i $BUSYBOX_ID -d /dev/sdj</p>
<p>31. Reboot the BusyBox instance to make sure it picks up the new device.</p>
<p>ec2-reboot-instances $BUSYBOX_ID</p>
<p>32. Check the BusyBox instance&#8217;s console output to make sure it came up as expected.</p>
<p>ec2-get-console-output $BUSYBOX_ID</p>
<p>33. Log into the new EBS backed instance.</p>
<p>That should be it. You now have a persistent instance that is backed by EBS storage!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://bluegecko.dk/ec2-persistent-boots-with-pivot-root/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Object Caching 24/83 objects using disk
Page Caching using disk: enhanced 

Served from: bluegecko.dk @ 2026-10-17 01:05:36 by W3 Total Cache
-->