Search This Blog

Thursday, November 25, 2010

Media Server - Setting up the RAID 5

Now the fun part...

Moving right in to creating the RAID 5 for all the media:
sudo fdisk /dev/sdb
n   (to create a new partition)
p   (for primary partition)
1   (to create partition 1)

....If for some reason at this point it tells you there is already a partition there, that's fine.  Just press d, and it will delete it, then go back to "n".

<enter>   (to begin on cylinder 1 of the hard drive)
<enter>   (to end on the last cylinder of the hard drive)
t   (for type of partition this will be)
fd    (to make it a RAID autodetect)
w    (to write changes)

Repeat these steps for each hard drive you want in the array... (ex: /dev/sdd, /dev/sde, /dev/sdf)

Now you can either use apt-get install, or use the Synaptic package manager (whichever you prefer), but we need mdadm to proceed to creating the RAID.  If you are using this as a tutorial, mdadm was used to create the RAID 1 for the OS drives.

sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=4 /dev/sdb1 /dev/sdd1 /dev/sde1 /dev/sdf1

This will start creating the RAID 5 (--level=5) using 4 hard drives (--raid-devices=4), on their first (and only) partitions (/dev/sdb1 /dev/sdd1 /dev/sde1 /dev/sdf1)

If you want to see the status of the RAID build, use:
cat /proc/mdstat
It should say something like:
md0 : active raid5 sdf1[4] sde1[2] sdd[1] sdb[0]
          5860535808 blocks level 5, 64k chunk, algorithm 2 [4/3] [UUU_]
          [>............................]  recovery =  0.5% (11036672/1953511936) finish=545.0min speed=59392K/sec
unused devcies: <none>

This is saying that its creating the RAID.  This will take some time, depending on the size of your hard drives, how many you are using, etc.  Make sure that your power settings will not sleep your computer after a period of time, and don't do things like system updates that will cause a computer restart. It's best just to leave it alone until the process is complete.

If you want to continuously watch the status (ie: you don't have anything to do for several hours):
watch cat /proc/mdstat
Once you are bored with that <Ctrl+c> to get out of watching it

Sweet... you have a RAID!  However, nothing will be managing it.  Tell mdadm to scan the raid config file or /proc/mdstat for missing information:
sudo mdadm --detail --scan >> /etc/mdadm/mdadm.conf

Go into this file and comment out (or delete) any other entries with /dev/md0 in them:
sudo gedit /etc/mdadm/mdadm.conf
You should see the "ARRAY /dev/md0..." line at the very bottom.  Any other lines in this file will need to have a "#" in front of them so that md0 will get mounted properly.  Also, I took out "metadata=00.90" because it gave me errors, and everything still seems to work fine.

Now we need to format the RAID:
sudo mke2fs -t ext4 -j /dev/md0
-or-
mke2fs.ext4 /dev/md0  (this is the one that worked for me)
This will make an ext4 filesystem with journaling on the RAID (/dev/md0)
If you are using ext3 filesystem, leave off -t ext4

Create a mount point anywhere on the system for your md0:
sudo mkdir /mnt/Media
Putting it in /var means that everyone can read it.  You may also want to put it in /mnt and then change permissions later.

Edit the fstab so that the RAID will get mounted each time the system boots:
sudo vi /etc/fstab
Ađd the following line to the bottom of the file:
/dev/md0 /var/media ext4 defaults 1 2
From here you can reboot to see if the RAID gets mounted at /var/media, or you can mount it now without a reboot:
mount -a
This will read from the fstab and mount everything from it.

Hopefully this was all very helpful.

End notes:
I went back to not using a RAID1 for the OS. After giving it a day of thought, there really is no reason for me to waste a 250GB hard drive on something that can easily be reinstalled and configured from a CD.  Plus, I've been running Ubuntu on my MacBook for over a year now with no issues, so there should be none on the server.  If the time comes down the road where the hard drive where Ubuntu is installed fails, I would just replace it with a new one and reconfigure everything from a backup that will reside on the RAID.
That all being said, if you used a RAID for the OS, then the RAID for the media would be md1 for the above steps that reference md0.

Reference:
sonniesedge

No comments:

Post a Comment