There are many types of RAID but Raid 5 is the one I'm interested in here.
[*][*]EDIT This How To is a collection of data pertinent to all software RAID configurations. But I am interested in RAID 5 here.
It requires at least 3 disks. The result is only 2 disks worth of storage space but if any one disk fails the data is not lost.
The following is scraped together from various places but I thought it warranted putting in one place. Its not complete as its a big topic, but I found myself running all over the place just trying to understand how to set up RAID. So this is a future reference for me as much as anything and it may as well be a reference for the next guy/gal too
Its become obvious that there are a few layers of decisions when setting up RAID. This is just the path I took.
Any disks will do for experimenting but the final result will be only as fast as the slowest disk and as big as the smallest disk. If it comes to purchasing disks then don't forget to get a spare. After all, the point of most RAID implementations is that you can pop a replacement disk in when one fails, and they should be the same size. I guess at a pinch the spare could be bigger than the rest.
Description of the types of RAID : http://en.wikipedia.org/wiki/RAID
Interesting argument of Software V Hardware RAID: http://linux.yyz.us/why-software-raid.html
RAID tools for Linux:
LVM........http://www.redhat.com/magazine/009jul05/features/lvm2/
dmraid....http://www.linuxmanpages.com/man8/dmraid.8.php
mdadm...http://www.linuxmanpages.com/man8/mdadm.8.php
LVM is used to manage partitions on RAID arrays.
dmraid is used to discover and use the so called "fakeRAID" hardware.
FakeRAID is so called because although there are some settings outside of the OS (in the motherboards BIOS or on a controller card), the OS is used to do the work. Real hardware RAID is implemented on an embedded chip so the OS never knows the disks are RAID disks. Full hardware RAID is usually expensive too.
Software RAID on the other hand is not expensive , and if implemented correctly, is not difficult and gives many benefits.
Setting up a fakeRAID has been covered in the Mint forums here http://forums.linuxmint.com/viewtopic.p ... id#p178926
mdadm is used to set up and manage software RAID
[*][*][*]EDIT START[*][*][*][*]
[*][*] I have since got back at looking at RAID while looking at eBox from eBox Platform
eBox has some useful information about RAID and seems to be able to do the work for you. Making this How To a little redundant
All the same have a look at the documentation as it shows a use for LVM in expanding a RAID more easily and how to deal with the /boot partition on software RAID. There are some clear diagrams and at the the moment they use XFS partitions as its supposed to be possible to expand them while the system is live. I would love to see that. !!
There is another documentation section but this is where I found the good bits:
http://trac.ebox-platform.com/wiki/Document/Index
This link has RAID info:
http://trac.ebox-platform.com/wiki/Docu ... figuration
Some info about using XFS:
http://trac.ebox-platform.com/wiki/Docu ... tEboxSetup
http://trac.ebox-platform.com/wiki/Docu ... up/Install
Resizing LVM and XFS:
http://trac.ebox-platform.com/wiki/Docu ... lumeResize
Also I have since come to my own conclusion that for a simple home or even small office set-up RAID 1 (mirroring) is best.
Reasons:
-Less trouble in recovery as the data is all on either drive. (if its a business then an off site backup solution needs to be implemented anyway)
-The OS has redundancy (its not possible to have the /boot on RAID 5 but you can put it on RAID1)
-Speed is not likely to be an issue for a small setup. Speed is needed for database access by multiple (thousands) connections.
-Cost. Why buy 3 or 4 identical disks when you can use 2 for RAID1. If you need more you just get 2 more and not necessarily the same size as the originals. The extra space available when using RAID 5 is really only realized when using 5 or more disks. At that point the "redundant" disk space is a negligible part of the total disk space and cost. But for small configurations 2 hard drives and 1/2 the space used is close "ish" to 3 drives and 2/3 the space used.
Thats my current thinking anyway.
All that said, its good to play with good tools and build RAID 5 to learn.
[*][*][*EDIT END][*][*][*][*]
--setting up software RAID
I got my basic info. here: http://linux-raid.osdl.org/index.php/RAID_setup but found it needed cleaning up with a change or two for my Mint.
Near the end of writing I found this. Its for Software RAID in Ubuntu: http://bfish.xaedalus.net/2006/11/softw ... nt-page-2/ Note: in the linked example ext3 partitions are created on the disks and the RAID is made out of the partitions. This How To uses full disks without partitions.
--Getting started
With software RAID 5 it doesn't seem possible to boot from it. The best I can think of for OS redundancy is a backup of the OS with Remastersys. It is possible to boot from another mirror RAID. Alternatively put grub and /boot on another drive and let them point at the rest of the OS on the RAID array.
Anyway this RAID will just be for general data and for now I'll use another disk for the OS.
Boot from a LIVE Mint CD to get going . Because GRUB is installed during the OS install, I want to make sure it is going on the right disk and not on one of my RAID disks. One way to do this is make sure the OS disk is on the first primary SATA or IDE cable. (Its all very possible to do fancy things with grub but I really don't want to start messing with GRUB at the moment)
After the LIVE CD boot GParted is good for checking the first drive is right. For me its /dev/sda. I can tell by the size of the disks etc what disks are what.
Then on to the Mint install with whatever preferences you like. Just remember to stay clear of the RAID disks.
Do some Mint updates and then open a command prompt and make sure the Kernel supports software RAID with this (Mint supports it ):
Code: Select all
sudo modprobe raid5
Code: Select all
cat /proc/mdstat
--Installing mdadm
The original text I read said to use apt-get to install mdadm:
Code: Select all
sudo apt-get install mdadm
In Synaptic Package Manager right click on mdadm button and go to the "Mark Recommended for Installation". If you select sSMTP here you will get sSMTP instead of Postfix with the mdadm install.
We will get back to sSMTP later. Did I mention its easy
--On to the disks
There is a choice to be made about how the RAID is implemented on the disks. Either putting a partition on each disk and then using partitions to build the RAID array or as whole disks without partitioning first. Have not found any major argument against using the whole disk! So not much for me to do here.
If using LVM then perhaps partitioning first would make be a good idea.
--Creating the RAID array
Note: drive or partition names need to be corrected for your system. These were right for mine but they may not be right for yours.
Gparted gives a nice view of a disk, its name and if there are any partitions on it. There are other, more CLI "correct" ways of doing things though. (feel free to comment )
This is the original format I found for the mdadm create command:
Code: Select all
mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1 --spare-devices=1 /dev/sde1
My script is like this:
Code: Select all
sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd
The status can be checked with this:
Code: Select all
watch cat /proc/mdstat
Press CTRL+C to cancel the watch.
There's a count down displayed with "watch cat " e.g. "finish=200.5min"
Apparently its possible to format it and start using it immediately !
Anyway it should be possible to carry on with the configuration while its working away. Its generally recommended that even when its finished you "burn it in" and don't depend on it straight away. Put data on it and use it but keep another copy for a week or so.
--config of mdadm and mount points
When the RAID array is ready it's necessary to make sure the mdadm.conf file knows about it.
In a terminal type:
Code: Select all
sudo mdadm --detail --scan
This line needs to be in the mdadm.conf file. I found it necessary to edit the mdadm.conf file with gedit:ARRAY /dev/md0 level=raid5 num-devices=3 metadata=00.90 UUID=0a32fea9:b84eeae7:7b509728:5b74e2ab
Code: Select all
sudo gedit /etc/mdadm/mdadm.conf
NOTE: There is a problem with how data is parsed somewhere so the an extra "0" gets added. Change "metadata=00.90" to "metadata=0.90"#definitions of existing MD arrays
ARRAY /dev/md0 level=raid5 num-devices=3 metadata=0.90 UUID=0a32fea9:b84eeae7:7b509728:5b74e2ab
Your UUID is going to be different to mine lol
Make a mount point for the new raid drive:
Code: Select all
sudo mkdir /media/raidmd0
Make sure fstab.conf knows where to mount the drive so:
Code: Select all
sudo gedit /etc/fstab
That's what my one looks like and it works for now./dev/md0 /media/raidmd0 auto defaults 0 0
I was looking at using LVM2 to manage the RAID drive but have not seen the advantage of it for a simple setup like this yet. If anyone can comment on how it may be useful and suggest a way to set it up it would be great
Some useful mdadm commands
[*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*]
[*]--Removing RAID
[*]If for some reason you need to get rid of the RAID set-up entirely then this is what is needed.
[*]unmount any partitions on the array that might be mounted.
[*]Find out what disks are involved in the RAID:
Code: Select all
sudo mdadm --detail /dev/md0
Code: Select all
sudo umount /dev/md0
Code: Select all
sudo mdadm --stop /dev/md0
Code: Select all
sudo mdadm --zero-superblock /dev/sda
[*]Its also useful to know how to start a RAID array and this is one way:
Code: Select all
mdadm --assemble --scan
-- Formatting the new RAID drive
I'm interested in using ext3 as a file system but mke2fs has many parameters to look at. The "-j" option makes it ext3.
This will get it up and running:
Code: Select all
sudo mke2fs -j /dev/md0
The stride and strip-width in the RAID can be set using
tune2fs -E stride=n,stripe-width=m /dev/mdx
Code: Select all
sudo modprobe raid5
Code: Select all
cat /proc/mdstat
My chunk size is 64 and there is a block size of 4096B or 4 kB mentioned when mke2fs ran.
The values for the stride and strip-width are calculated like this:
There are 16 blocks of 4kB in one array chunk of size 64. Therefor 16 is one stride.
Stripe-width is calculated by multiplying the stride=16 value with the number of data disks in the array ( a raid5 with n disks has n-1 data disks, one being reserved for parity)
My setup with 3 disks has 2 data disks. 16 X 2 gives a Stripe-width=32
So:
Code: Select all
tune2fs -E stride=16,stripe-width=32 /dev/md0
Probably good to uninstall postifix first if its installed and your not going to use it.
sSMTP may already be installed from the install of mdadm, but if not then its available in Synaptic Package Manager or with :
Code: Select all
sudo apt-get install ssmtp
Code: Select all
sudo gedit /etc/ssmtp/ssmtp.conf
Code: Select all
man ssmtp
As with the linked example I'm using Gmail. However since this setup requires putting a gmail account password in the file, I created a nice new Gmail account just for my computer to use. It sends system email to me from the new account.
There is a way to secure the .conf file: http://blogs.techrepublic.com.com/security/?p=440 but I'm leaving that for another day.
In the ssmtp.conf file set:
(I'm the administrator so I wont to get the system emails. This could alternatively be set as the new Gmail account )
(this is the mailhub info for the Gmail account )mailhub=smtp.gmail.com:587
And add these:
(This is the user name of the new Gmail account I want sSMTP to use)AuthUser=Thegmailusername
(This is the password of the new Gmail account I want sSMTP to use)AuthPass=Thegmailpassword
(This means you dont have to explicitly set dedicated port number for SMTP)UseSTARTTLS=YES
Once the changes are saved this can be tested in a terminal:
Code: Select all
sendmail AnyEmailAddress@Anyservice.com
to: AnyEmailAddress@Anyservice.com
from: Thegmailusername
Subject: First Test of sSMTP
Hello. This is a test sSMTP email
Note the blank line after "Subject:" This is needed and everything below it is message body.
The line with the sendmail command can be
Check the email accounts and see what's in the sent items and in-boxes
As you can see this is simple at least at this level and quite flexible.
--Configure mdadm monitor mode
First open the mdadm.conf file:
Code: Select all
sudo gedit /etc/mdadm/mdadm.conf
and set the next line to:# instruct the monitoring daemon where to send mail alerts.
Now test the relationship between mdadm and sSMTP:MAILADDR myemailaddress@whatever.com
Code: Select all
sudo mdadm --monitor --scan --test
After 30 sec or so press Ctrl+C and check the email accounts again.
Now set the auto monitor mode:
Code: Select all
sudo dpkg-reconfigure mdadm
Result is Software RAID 5 with an email sent when bad things happen
Enjoy,
Treefrog
--