<?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>Xi Group Ltd. Company Blog &#187; Xi Group Ltd. Company Blog &#187; partitioning</title>
	<atom:link href="http://blog.xi-group.com/tag/partitioning/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.xi-group.com</link>
	<description>High-quality DevOps Services</description>
	<lastBuildDate>Tue, 09 Jun 2015 11:38:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.2</generator>
	<item>
		<title>Small Tip: Partitioning disk drives from within UserData script</title>
		<link>http://blog.xi-group.com/2014/06/small-tip-partitioning-disk-drives-from-within-userdata-script/</link>
		<comments>http://blog.xi-group.com/2014/06/small-tip-partitioning-disk-drives-from-within-userdata-script/#comments</comments>
		<pubDate>Wed, 11 Jun 2014 08:51:43 +0000</pubDate>
		<dc:creator><![CDATA[Ivo Vachkov]]></dc:creator>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[Small Tip]]></category>
		<category><![CDATA[fdisk]]></category>
		<category><![CDATA[instance store]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[partitioning]]></category>

		<guid isPermaLink="false">http://blog.xi-group.com/?p=47</guid>
		<description><![CDATA[In a recent upgrade to the new generation of instances we faced an interesting conundrum. Previous generations came with quite the amount of disk spaces. Usually instance stores are mounted on /mnt. And it is all good and working. The best part, one can leave the default settings for the first instance store and do [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">In a recent upgrade to the new generation of instances we faced an interesting conundrum. Previous generations came with quite the amount of disk spaces. Usually instance stores are mounted on /mnt. And it is all good and working. The best part, one can leave the default settings for the first instance store and do anything with the second. And &#8220;anything&#8221; translated to enabling swap on the second instance store. With the new instance types, however the number (and the size) of the instance stores is reduced. It is SSD, but m2.4xlarge comes with 2 x 840 GB, while the equivalent in the last generation, r3.2xlarge, comes with only one 160 GB instance store partition.</p>
<p>Not a problem, just a challenge!</p>
<p style="text-align: justify;">We prefer to use UserData for automatic server setup. After some attempts it became clear that partitioning disks from a shell script is not exactly trivial tasks under Linux in AWS. BSD-based operating systems come with <strong>disklabel</strong> and <strong>fdisk</strong> and those will do the job. Linux comes with <strong>fdisk</strong> by default and that tool is somewhat limited &#8230;</p>
<p style="text-align: justify;">Luckily, <strong>fdisk</strong> reads data from <strong>stdin</strong> so quick-and-dirty solution quickly emerged!</p>
<p style="text-align: justify;">The following UserData is used to modify the instance store of a m3.large instance, creating 8GB swap partition and re-mounting the rest as /mnt:</p>
<p></p><pre class="crayon-plain-tag">#!/bin/bash -ex

# Mark execution start
echo "STARTING" &gt; /root/user_data_run

# Unmount /dev/xvdb if already mounted
umount -f /dev/xvdb

# Partition the disk (8GB for SWAP / Rest for /mnt)
(echo n; echo p; echo 1; echo 2048; echo +8G; echo t; echo 82; echo n; echo p; echo 2; echo; echo; echo w) | fdisk /dev/xvdb

# Make and enable swap
mkswap /dev/xvdb1
swapon /dev/xvdb1

# Make /mnt partition and mount it
mkfs.ext4 /dev/xvdb2
mount /dev/xvdb2 /mnt
sed -i s/xvdb/xvdb2/g /etc/fstab

# Mark execution end
echo "DONE" &gt; /root/user_data_run</pre><p>Execute it with AWS CLI (Using stock Ubuntu 14.04 HVM AMI):</p><pre class="crayon-plain-tag">aws ec2 run-instances --image-id ami-1d8c9574 --count 1 --instance-type m3.large --key-name test-key --security-groups test-sg --user-data file://userdata.sh</pre><p>The result:</p><pre class="crayon-plain-tag">:~&gt; ssh ubuntu@ec2-54-197-66-121.compute-1.amazonaws.com "df -h"
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.8G  765M  6.6G  11% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            3.7G   12K  3.7G   1% /dev
tmpfs           749M  336K  748M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            3.7G     0  3.7G   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/xvdb2       22G   44M   21G   1% /mnt
:~&gt; ssh ubuntu@ec2-54-197-66-121.compute-1.amazonaws.com "free -h"
             total       used       free     shared    buffers     cached
Mem:          7.3G       276M       7.0G       352K       8.6M       177M
-/+ buffers/cache:        90M       7.2G
Swap:         8.0G         0B       8.0G
:~&gt;</pre><p></p>
<p style="text-align: justify;">There it is, 8GB swap partition (/dev/xvdb1) and the rest (/dev/xvdb2) mounted as /mnt. Note that /etc/fstab is also updated to account for the device name change!</p>
<div class="rpbt_shortcode">
<h3>Related Posts</h3>
<ul>
					
			<li><a href="http://blog.xi-group.com/2014/11/small-tip-how-to-use-block-device-mappings-to-manage-instance-volumes-with-aws-cli/">Small Tip: How to use &#8211;block-device-mappings to manage instance volumes with AWS CLI</a></li>
					
			<li><a href="http://blog.xi-group.com/2014/06/small-tip-use-aws-cli-to-create-instances-with-bigger-root-partitions/">Small Tip: Use AWS CLI to create instances with bigger root partitions</a></li>
					
			<li><a href="http://blog.xi-group.com/2015/01/small-tip-how-to-use-aws-cli-filter-parameter/">Small Tip: How to use AWS CLI &#8216;&#8211;filter&#8217; parameter</a></li>
					
			<li><a href="http://blog.xi-group.com/2014/07/small-tip-how-to-use-aws-cli-to-start-spot-instances-with-userdata/">Small Tip: How to use AWS CLI to start Spot instances with UserData</a></li>
					
			<li><a href="http://blog.xi-group.com/2014/07/small-tip-aws-announces-t2-instance-types/">Small Tip: AWS announces T2 instance types</a></li>
			</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.xi-group.com/2014/06/small-tip-partitioning-disk-drives-from-within-userdata-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
