Running Software RAID

Conditions of installation

- The array is created on a computer that is already running (a deb-based OS such as Debian or Ubuntu is preferred)
- The hard disks used are SATA hard disks (though this guide can be used for PATA hard disks as well, swop /dev/sdX with /dev/hdX)
- mdadm is used

Here is a logical layout of the setup:

Preparing the disks

Firstly, the disks must be detected by the OS. For compatible chipsets, you may refer to here.

Format the disks with fdisk:

sudo fdisk /dev/sdX

(Replace /dev/sdX with the name of your device, if applicable)

Create a single partition on the disk, with the partition type set as “Linux RAID automount” (type: “fd”)

Write the partition changes to disk and repeat for the rest of the disks.

Creating the RAID array

Install mdadm (you will need to enable the multiverse and/or universe repositories)

sudo apt-get -y install mdadm

One of the advantages of mdadm over raidtools is that it does not require any configuration file, if you are so inclined.

To create the RAID array, execute the following command:

sudo mdadm --create --auto=md --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
  • –create instructs mdadm to create the RAID array
  • –level=1 indicates that the array will be of a RAID1 configuration. Other options include RAID0, RAID5, RAID10 etc.
  • /dev/md0 is the new RAID device that is created
  • –raid-devices=2 indicates the number of partitions used (in this example, 2 – /dev/sda1 and /dev/sdb1)

For more information, a quick

man mdadm

should suffice.

Following the creation of the array, mdadm has to initialize the array, which takes quite some time, depending on the processor speed. To check on the progress of the array initialization, run:

sudo watch cat /proc/mdstat

Creating the filesystem

As /dev/md0, the new array, is just a raw disk, we need to put a filesystem on it. My file system of choice is ReiserFS, which is what I will be using:

sudo mkfs -t reiserfs /dev/md0

If you prefer to use ext4 (the successor to ext3), type:

sudo mkfs -t ext4 /dev/md0

After the filesystem is set up, the array can be mounted:

sudo mount /dev/md0 /media/raid

(replace /media/raid with the mount directory of choice)

Starting the array at boot

To start the array at boot, insert the following line into your /etc/fstab (do remember to back up the fstab file beforehand. Before rebooting, please check through carefully as it may render your system unbootable!)

/dev/md0 /media/raid reiserfs rw,user,noatime 0 0

At any point in time, you may check out the status of the array by doing a:

cat /proc/mdstat

Assembling a pre-built array

If you happen to already have an array, and wish to reinstate it on the computer (e.g. after moving the hard disks to another computer), you will want the –assemble option

sudo mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1
  • –assemble tells mdadm that you want to assemble the array from the existing data
  • /dev/md0 is the name of the md device that you want to assign the array to
  • /dev/sda1 and /dev/sdb1 are the constituent partitions that will make up the array

Recovering from a degraded array

Let’s say that the worst has come, and one of your hard disks has crashed on you. But not to worry, that’s why you have RAID – protection against hardware failure.

The array is now known to be degraded. In a RAID5 array, this will lead to degraded performance. To recover from failure, follow the steps below.

First, remove the defective hard disk

sudo mdadm --remove /dev/sdb1

Next, swop out the damaged hard disk for a working one, formatting the new hard disk as per the instructions above.

Following that, we tell mdadm that a new disk has been put in

sudo mdadm --add /dev/sdb1 /devmd0

mdadm will then proceed to rebuild the array from the good copy of the data.