In Defiance of Titles

Just another weblog

My Home NAS, Part 6: RAID Setup

leave a comment »

Now that my home NAS has its hard drives installed, it’s time to set up the RAID-1 array. As it turns out, this is pretty simple work. First, create a single Linux RAID Autodetect partition on each disk, taking up its entire usable space. You can do this by running fdisk /dev/sda; fdisk is pretty powerful, so just in case you’ve never done this before, I’ll walk you through the steps. The listing below shows you fdisk’s prompts, with the appropriate response in bold; press the {enter} key after each command, of course.

Command (m for help): o
{several lines of output from fdisk}

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-x, default 1): {just press enter to keep the default}
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-x, default x): {again, just press enter}
Using default value x

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Repeat the process for your second disk (e.g., /dev/sdb). When you’ve finished with this process for both disks, you’ll have two new device special files in /dev, corresponding to the new partitions you created. These should be called /dev/sda1 and /dev/sdb1 (i.e., partition 1 on /dev/sdb). You’re now ready to create your RAID-1 array out of these partitions.

Make sure you’ve got the mdadm package installed (apt-get install mdadm); then, create your new RAID array as follows:

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sd[ab]1

Like I said, dang simple. The arguments work as follows:

  • --create /dev/md0 tells mdadm that the device special filename for the new RAID device should be /dev/md0. This is conventional; I think you could name it something else if you wanted, but it’s best not to get too creative with this kind of thing.
  • --level=1 tells mdadm that this is a RAID-1 array. In a RAID-1 array, each disk is basically a copy of every other disk, getting you full redundancy in case one disk fails.
  • --raid-devices=2 tells mdadm that this array will have two devices in it, something which it could probably figure out from the fact that we’re about to tell it which two devices are in the array. But it never hurts to specify.
  • Finally, the flagless argument /dev/sd[ab]1 is actually expanded by the shell into two arguments, /dev/sda1 and /dev/sdb1 (that’s what the square brackets do; fun trick); these are the devices that will make up the array.

It’ll take awhile to finish setting up the array, but you can actually start using /dev/md0 right away (if, for instance, you want to move on to my next post about LVM setup). You can always monitor the new array at any point by running one of two commands; either cat /proc/mdstat or mdadm --detail /dev/md0 will give you useful information about how things are running. Once it’s had time to create the array, both of these commands should show you that the state of the array is clean. But that may take awhile, so be patient.

Now, things aren’t quite usable yet in this state. For reasons related to my backup policy (which I will explain later hopefully), I wanted to separate the array out into several distinct filesystems, each with a fixed size. Unfortunately, I’m out of time for now, so I’ll have to show you that process in another post.


Written by jazzslider

January 11, 2009 at 10:13 am

Posted in Uncategorized

Tagged with , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: