<?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>JamieRF &#187; linux</title>
	<atom:link href="http://www.jamierf.co.uk/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jamierf.co.uk</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 04 Jun 2010 11:20:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Software RAID-5: using mdadm in Ubuntu 9.10</title>
		<link>http://www.jamierf.co.uk/2009/11/04/software-raid-5-using-mdadm-in-ubuntu-9-10/</link>
		<comments>http://www.jamierf.co.uk/2009/11/04/software-raid-5-using-mdadm-in-ubuntu-9-10/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 19:53:54 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[raid]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.jamierf.co.uk/?p=313</guid>
		<description><![CDATA[As a follow on to my post about choosing RAID, here is a quick guide to setting up RAID-5 using mdadm. In theory this should apply to any distro that has mdadm, but I was already running Ubuntu 9.10 (just upgraded yesterday actually!). Note: RAID-5 requires a minimum of 3 drives, and all should be [...]]]></description>
			<content:encoded><![CDATA[<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> <p>As a follow on to my post about <a href="http://www.jamierf.co.uk/2009/10/30/choosing-raid/">choosing RAID</a>, here is a quick guide to setting up RAID-5 using <a href="http://en.wikipedia.org/wiki/Mdadm">mdadm</a>. In theory this should apply to any distro that has mdadm, but I was already running Ubuntu 9.10 (just upgraded yesterday actually!).</p>
<p><strong>Note</strong>: RAID-5 requires a minimum of 3 drives, and all should be the same size. It provides the ability for one drive to fail without any data loss.</p>
<pre>Usable space = (no. of drives - 1) * size of smallest drive</pre>
<p>In my set up I started with 3x 1.5TB drives, giving 3.0TB usable space. I have now grown it to 4x 1.5TB drives, giving 4.5TB usable space.</p>
<p><span id="more-313"></span></p>
<h3>Required software</h3>
<p>To create, format and resize the array we need to use various filesystem manipulation tools, but they should all come with Ubuntu. The only software you should need to install is mdadm.</p>
<pre>sudo aptitude install mdadm</pre>
<h3>Initial setup</h3>
<h4>1. Preparing the drives</h4>
<p>Before we jump into creating the actual RAID array, we first need to prepare partitions for the array to use. This can be done using a GUI tool such as GParted (available in the Ubuntu repositories), but I prefer using the terminal.</p>
<p>To get a list of available drives/partitions:</p>
<pre>sudo fdisk -l</pre>
<p>This will output, for each drive you have, something along the lines of:</p>
<pre>Disk <span style="color: #ff0000;">/dev/sda</span>: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000f1f05</pre>
<p>There may well be slightly more information available too if you already have some partitions made. From here note the name of the drives you wish to use (for example, /dev/sda). For each drive, create a partition and mark it as a RAID partition.</p>
<pre>sudo fdisk <span style="color: #ff0000;">/dev/sda</span></pre>
<p>This will open up fdisk, the partition manager. If you already have any partitions on the drive you should first delete them (obviously this will erase any data on them!). To create one partition that is the size of the whole drive:</p>
<pre>Command (m for help): <strong>n</strong>
Command action
	e	extended
	p	primary partition (1-4)
<strong>p</strong>
Partition number (1-4): <strong>1</strong>
First cylinder (1-182401, default 1): <span style="color: #ff0000;"><strong>[blank]</strong></span>
Last cylinder or +size or +sizeM or +sizeK (1-182401, default 182401): <span style="color: #ff0000;"><strong>[blank]</strong></span></pre>
<p>When choosing the first and last cylinder simply hitting return will use the default values (which are probably the values you actually want).</p>
<p>Next we will mark the partition as being part of a RAID array, allowing mdadm to automatically detect it:</p>
<pre>Command (m for help): <strong>t</strong>
Partition number (1-4): <strong>1</strong>
Hex code (type L to list codes): <strong>fd</strong>
Changed system type of partition 1 to fd (Linux raid auto)</pre>
<p>So far our changes haven&#8217;t actually been written to disk, so finally,<span style="background-color: #ffffff;"> issue the command to write the changes to disk.</span></p>
<pre>Command (m for help): <strong>w</strong>
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.</pre>
<p>Remember to repeat this step for each drive you wish to use in the array.</p>
<h4>2. Creating the array</h4>
<p>To create the array, we use the mdadm create flag (who&#8217;d have guessed that!). We also need to specify what RAID level we want, as well as how many devices and what they are.</p>
<pre>sudo mdadm --create --verbose <span style="color: #ff0000;">/dev/md0</span> --level=5 --raid-devices=<span style="color: #ff0000;">3</span> <span style="color: #ff0000;">/dev/sda1</span> <span style="color: #ff0000;">/dev/sdb1</span> <span style="color: #ff0000;">/dev/sdc1</span></pre>
<p>The verbose flag tells it to output extra information. In the above command I am creating a RAID-5 array at /dev/md0, using 3 partitions. If you already have a RAID array set up then you may need to use /dev/md1 for example. The number of partitions you are using, and their names will probably be different, so do not just copy and paste all of the command above. Note that the partition name is something like /dev/sda1, whereas the drive name is something like /dev/sda; the 1 refers to the partition number.</p>
<p>While the array is being built you can view its status in the file /proc/mdstat. Here the <a href="http://en.wikipedia.org/wiki/Watch_(Unix)">watch</a> command comes in handy:</p>
<pre>sudo watch cat /proc/mdstat</pre>
<p>This will output the contents of the file to the screen, refreshing every 2 seconds (by default). While the array is being built it will show how much of the &#8220;recovery&#8221; has been done, and an estimated time remaining.</p>
<p>Now that we have set up the array, we need to edit the mdadm configuration so it knows how to reassemble it when the system boots.</p>
<pre>sudo nano /etc/mdadm/mdadm.conf</pre>
<p>There should already be some sample configuration here:</p>
<pre># by default, scan all partitions (/proc/partitions) for MD superblocks.
# alternatively, specify devices to scan, using wildcards if desired.
DEVICE partitions

# auto-create devices with Debian standard permissions
CREATE owner=root group=disk mode=0660 auto=yes

# automatically tag new arrays as belonging to the local system
HOMEHOST

# instruct the monitoring daemon where to send mail alerts
MAILADDR root

# definitions of existing MD arrays
<span style="color: #ff0000;">ARRAY /dev/md0 level=raid5 num-devices=3 UUID=31283299:0c118170:8b4eb9a8:4e935bf2</span></pre>
<p>The ARRAY line probably doesn&#8217;t already exist. It is used to describe an array (such as the one we just created). While similar, your array will not be the same as mine above so do not just copy and paste it! Luckily, mdadm provides a utility to fetch this line exactly (by looking for partitions marked as belonging to a RAID array, as we did when preparing the drives):</p>
<pre>sudo mdadm --detail --scan</pre>
<p>If you add the &#8211;verbose flag here it will also output the devices which are part of the array. Because we marked the partitions as being part of a RAID array mdadm can find them automatically so this isn&#8217;t required in our case, but it may be if you have more than one RAID array in your machine.</p>
<p>Now, I decided to wait for the array to finish syncing before moving on, but you should be able to continue and format the array while it syncs if you wish. In my case, building the array with 3x 1.5TB drives took around 6 hours.</p>
<h4>3. Creating and mounting the filesystem</h4>
<p>Now that the array is built we need to format it. What filesystem you choose is up to you, but I would probably recommend ext3.  <strong>Note</strong>: For my array I chose to use ext4. So far I have not had any problems, but ext4 is still fairly new and there are still various bug reports going around mentioning data loss [<a href="http://bugzilla.kernel.org/show_bug.cgi?id=14354">bugzilla.kernel.org</a>] (which I conveniently didn&#8217;t notice until after!).</p>
<pre>sudo mkfs.ext3 <span style="color: #ff0000;">/dev/md0</span></pre>
<p>This will take a while, especially if your array is large.</p>
<p>If you chose to use ext2/3/4 you should also be aware of reserved space. By default ext2/3/4 will reserve 5% of the drives space, which only root is able to write to. This is done so a user cannot fill the drive and prevent critical daemons writing to it, but 5% of a large RAID array which isn&#8217;t going to be written to by critical daemons anyway, is a lot of wasted space.  I chose to set the reserved space to 0%, using tune2fs:</p>
<pre>sudo tune2fs -m 0 <span style="color: #ff0000;">/dev/md0</span></pre>
<p>Next we should add the array to the fstab, so that it will automatically be mounted when the system boots up. This can be done by editing the file /etc/fstab. For more detailed information, see the <a href="http://en.wikipedia.org/wiki/Fstab">fstab</a> Wikipedia article.</p>
<pre>sudo nano /etc/fstab</pre>
<p>Your fstab should already contain a few entries (if it doesn&#8217;t something is wrong!). At the bottom add a line similar to the following:</p>
<pre><span style="color: #ff0000;">/dev/md0</span>	<span style="color: #ff0000;">/mnt/raid</span>	<span style="color: #ff0000;">ext4</span>	defaults	0	0</pre>
<p>I chose to mount my array on /mnt/raid, but you may well wish to mount it somewhere else. If the folder you chose doesn&#8217;t exist you will need to create it. As I said earlier I chose to use ext4, but here you will need to enter whatever filesystem you chose earlier.</p>
<p>Now, mount the array.</p>
<pre>sudo mount -a</pre>
<p>This will mount anything mentioned in the fstab that isn&#8217;t currently mounted but should be (hopefully your array!).</p>
<p>You should now have a working RAID-5 array! Next I would strongly suggest you investigate how to look after and monitor it, being able to cope with one drive failure is no use if you don&#8217;t notice when it fails and let a second fail!</p>
<h3>Growing</h3>
<p>One of the advantages of software RAID is the flexibility it gives you, that would normally only be available from high end (expensive) RAID cards. This includes the ability to grow an existing array (only for certain RAID levels), which means if you run out of space you can easily plug in a new drive and keep going.</p>
<h4>1. Growing the array</h4>
<p>Growing a RAID-5 array with mdadm is a fairly simple (though slow) task. First you will need to prepare the new drive in the same we we prepared the initial drives (step 1, above). To start the actual growing of the array we then add the new drive to the array as a spare:</p>
<pre>sudo mdadm --add <span style="color: #ff0000;">/dev/md0</span> <span style="color: #ff0000;">/dev/sdd1</span></pre>
<p>Then we grow the array onto this device. Because I had 3 drives before, the new drive obviously makes 4. Make sure to change this to whatever number you now have!</p>
<pre>sudo mdadm --grow <span style="color: #ff0000;">/dev/md0</span> --raid-devices=<span style="color: #ff0000;">4</span></pre>
<p>As when creating the array, we can follow the progress by checking the file /proc/mdstat.</p>
<pre>sudo watch cat /proc/mdstat</pre>
<p>Again, I decided to wait for the operation to finish before attempting to grow the filesystem, but you should be able to do it while the array syncs.</p>
<h4>2. Growing the filesystem</h4>
<p>Before we can grow the filesystem we need to unmount it:</p>
<pre>sudo umount <span style="color: #ff0000;">/dev/md0</span></pre>
<p>Now that it is unmounted we can run a filesystem check to make sure everything is in order:</p>
<pre>sudo fsck.ext3 -f <span style="color: #ff0000;">/dev/md0</span></pre>
<p>If any issues arise, let it attempt to fix them for you.</p>
<p>Once the filesystem has been checked we can perform the resize. If you decided to use something other than ext2/3/4 this may be done differently, but for the ext2/3/4 filesystems we use the resize2fs tool.</p>
<pre>sudo resize2fs <span style="color: #ff0000;">/dev/md0</span></pre>
<p>This will automatically grow the filesystem to the new size of the device.</p>
<p>You can now remount the drive and start filling it up again!</p>
<h3>Sources</h3>
<ul>
<li><a href="http://bfish.xaedalus.net/2006/11/software-raid-5-in-ubuntu-with-mdadm/">Software RAID 5 in Ubuntu with mdadm</a></li>
<li><a href="http://scotgate.org/2006/07/03/growing-a-raid5-array-mdadm/">Growing a RAID5 array – MDADM</a></li>
<li><a href="http://linux-raid.osdl.org/index.php/Main_Page">Linux Raid Wiki</a></li>
<li><a href="http://www.andremiller.net/content/recovering-reserved-space-ext2-and-ext3-filesystems">Recovering reserved space in ext2 and ext3 filesystems</a></li>
</ul>
<p><em>If you spot any errors, or have any problems then please leave a comment and let me know!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamierf.co.uk/2009/11/04/software-raid-5-using-mdadm-in-ubuntu-9-10/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Choosing RAID</title>
		<link>http://www.jamierf.co.uk/2009/10/30/choosing-raid/</link>
		<comments>http://www.jamierf.co.uk/2009/10/30/choosing-raid/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 10:21:15 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[raid]]></category>

		<guid isPermaLink="false">http://www.jamierf.co.uk/?p=285</guid>
		<description><![CDATA[Having been virtually out of hard drive space for the past couple of months I finally decided to do something about it, and purchased 3 new 1.5TB Seagate Barracuda hard drives. I chose these because I already had one and thought 4 the same would make sense, but if you are buying all new then [...]]]></description>
			<content:encoded><![CDATA[<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> <p>Having been virtually out of hard drive space for the past couple of months I finally decided to do something about it, and purchased 3 new <a href="http://www.amazon.co.uk/dp/B001IKKCLI/?tag=ja0e-21">1.5TB Seagate Barracuda</a> hard drives. I chose these because I already had one and thought 4 the same would make sense, but if you are buying all new then the <a href="http://www.amazon.co.uk/dp/B001UE8LRO/?tag=ja0e-21">1.5TB Western Digital Caviar Green</a> is maybe a better option; it is 5400rpm rather than 7200rpm, the performance loss shouldn&#8217;t be an issue for a basic file server, but the power saving and quieter operation may be appreciated.</p>
<p>I decided to create a software RAID-5 array using the 4 drives, to give a total capacity of 4.5TB with the ability to handle 1 drive failure.</p>
<p><span id="more-285"></span></p>
<h3>What is RAID?</h3>
<p>RAID stands for Redundant Array of Inexpensive Disks, and is a way of organizing data over multiple drives to provide higher performance and/or reliability than available from a single drive.</p>
<h4>What is RAID not?</h4>
<p>Although RAID is redundant and can recover from drive failure, it alone is <span style="text-decoration: underline;">not a backup solution</span>! If you delete a file on a RAID array it is deleted from all drives in that array, similarly if your data is corrupted then the corrupted data will be mirrored across the whole array.</p>
<h3>Hardware RAID vs Fake RAID vs Software RAID</h3>
<p>Before getting started you should think about how best to implement your RAID array, because once it&#8217;s done it can be hard (if not impossible without enough spare disks to back up all your data) to change.</p>
<h4>Hardware RAID</h4>
<p>Hardware RAID is usually considered the &#8220;real&#8221; implementation of RAID. It requires a dedicated RAID card, which handles maintaining the array; this has the advantage that the CPU is not required so performance is usually better. The disadvantages however are that you are then restricted to the RAID card you have; the implementations of RAID isn&#8217;t always compatible between different models, and almost definitely isn&#8217;t between different vendors, and the cost; hardware RAID is not cheap!</p>
<h4>Fake RAID</h4>
<p>Most motherboards these days come with RAID support, which is known as Fake RAID. What&#8217;s fake about it? There is no dedicated chip to maintain the array as with &#8220;real&#8221; RAID. This means that the processing is handed off to the CPU, so the performance benefit is no longer there. On the upside, it is cheap!</p>
<h4>Software RAID</h4>
<p>The third option when implementing RAID is Software RAID, which, as the name suggests, is done totally in software. This means, like with Fake RAID, the CPU is required to do the processing. The advantages however are it&#8217;s portability, and cost (free!). Because the implementation is entirely software based, there is no restriction on hardware any more; you can move the drives between computers without any problems. There is however now a restriction on software; if you created the RAID array under Linux (using <a href="http://en.wikipedia.org/wiki/Mdadm">mdadm</a>), it will not be accessible under Windows (or any other OS that doesn&#8217;t have the same implementation of mdadm available). It is also worth mentioning that mdadm includes many features which can only be found on the high end (expensive) RAID cards, such as the ability to grow or shrink a live array.</p>
<h3>Levels of RAID</h3>
<p>Another thing you will need to decide on before starting is what level of RAID you require. For a detailed review of the different levels see the Wikipedia article about <a href="http://en.wikipedia.org/wiki/Standard_RAID_levels">Standard RAID levels</a>. I am using RAID-5 because it provides some redundancy but without sacrificing too much capacity (usable size = (num of drives &#8211; 1) * size of smallest drive), however there is <a href="http://blogs.zdnet.com/storage/?p=162">some speculation</a> that as disk sizes are increasing, RAID-5 is becoming less reliable. When I next get paid I may consider upgrading to RAID-6 (which, using software RAID, is easy!).</p>
<p>&nbsp;</p>
<p><em>Follow up: <a href="http://www.jamierf.co.uk/2009/11/04/software-raid-5-using-mdadm-in-ubuntu-9-10/">Software RAID-5: using mdadm in Ubuntu 9.10</a></em><em>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamierf.co.uk/2009/10/30/choosing-raid/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
