Chapter 17. RAID

Objectives

  • Explain the concept of RAID
  • Summarize RAID levels
  • Configure RAID
  • Monitor RAID devices
  • Use hot spares

RAID

Stands for Redundancy Array of Indenpendent Disks, its objective is to span a filesystem over several physical disks (partitions). It allows the increase I/O performance and reliability

Raid can be implemented at these levels

  • Software
    • It is a feature of mature linux kernels
  • Hardware
    • If it is possible to configure RAID through hardware it could perform better than a software configuration
    • When RAID is implemented through hardware it will be transparent for the Operating System

Essential Features of RAID

  • Mirroring
    • Write the same data to more than one disk
  • Striping
    • Splitting of data to more than one disk
  • Parity
    • Extra data is stored to allow fault tolerance, error detection and repair

mdadm

Command used to create and manage RAID devices, once a "RAID devices" has been created (out from several disks partitions) it can be used like any other filesystem block device ( Sample of a block device : /dev/sda or /dev/sdb )

RAID LEVELS

  • RAID 0
    • Uses only striping, it does not allow fault tolerance but it has good performance
  • RAID 1
    • Uses only mirroring, good for recovery.
    • At least 2 disks are required
  • RAID 5
    • Uses a rotating parity stripe, thus allowing fault tolerance and reliability.
    • At least 3 disks are required
  • RAID 6
    • Uses striped disks with dual parity, It is an evolution of RAID 5, allowing fault tolerance and performance.
    • At least 4 disks are required.
  •  RAID 10
    • Uses mirroring and striping, thus allowing redundancy and performance.
    • At least 4 disk are required

CONFIGURE RAID

Steps to configure a RAID device

  • Create partitions on each disk 
    • "fd" type in fdisk
  • Create RAID device with "mdadm"
  • Format RAID device
  • Add device to /etc/fstab
  • Mount RAID device
  • Capture RAID details to ensure persistence

Stop RAID

Suppose we have a RAID device at /dev/md0, the next command shall be used to stop it

$ sudo mdadm -S /dev/md0

Sample

1. Create two partitions of type "fd" on disk /dev/sdb and /dev/sdc (lets say /dev/sdbX and /dev/sdcX) 

$ sudo fdisk /dev/sdb
$ sudo fdisk /dev/sdc

2. Create the RAID device with mdadm command

$ sudo mdadm --create /dev/md0 --level=1 --raid-disks=2 /dev/sdbX /dev/sdcX

3. Create an ext4 filesystem within /dev/md0

$ sudo mkfs.ext4 /dev/md0

4. Write to mdadm.conf file data bout the recent action

$ sudo bash -c "mdadm --detail --scan >> /etc/mdadm.conf"

5. Create a directory to mount the new filesystem

$ sudo mkdir /myraid

6. Mount the filesystem

$ sudo mount /dev/md0 /myraid

7. Add an entry to fstab file in order to make the mount permanent

$ sudo echo "/dev/md0 /myraid ext4 defaults 0 2"

8. Examine the RAID devices with

$ cat /proc/mdstat

Monitoring RAID

Suppose we have a RAID device /dev/md0, we can use

mdadm
Will show the status of the current RAID device /dev/md0

$ sudo mdadm /dev/md0

/proc/mdstat
Will show the status of all the RAID devices on the system

$ cat /proc/mdstat

mdmonitor
This utility allow us to monitor the RAID devices, for example to notify a given email account when a RAID device is damaged we can do this :

1. Add the email to the /etc/mdadm.conf

MAILADDR alejandro@alejandrobernalcollazos.com

2. Turn on the mdmonitor service

$ sudo service mdmonitor start

3. Configure the monitor to start at boot time 

$ sudo chkconfig mdmonitor on

or in Ubuntu

$ sudo chkconfig mdadm on

​RAID Hot Spares

To create a hot spare device when creating the RAID array

$ sudo mdadm --create /dev/md0 -l 5 -n3 -x 1 /dev/sda8 /dev/sda9 /dev/sda10 /dev/sda11

The -x option tells in this case to mdadm to add 1 spare device. Also a hot spare device can added latter.

The next command command will test the redundancy and hot spare of your array 

$ sudo mdadm --fail /dev/md0 /dev/sd2

To replace a spare device

1. Remove it from the RAID array

$ sudo mdadm --remove /dev/md0 /dev/sdb2

2. Add a new device to the array

$ sudo mdadm --add /dev/md0 /dev/sde2

Lab 17.1: Creating a RAID Device

Normally when creating a RAID device we would use partitions on separate disks. However, for this exercise we probably don’t have such hardware available.

Thus we will need to have two partitions on the same disk, or we can use LVM partitions just for demonstration purposes. (Note we can’t use image files and loopback for this exercise.)

The process will be the same whether the partitions are on one drive or several (Although there is obviously little reason to actually create a RAID on a single device).

  1. Create two 200 MB partitions of type raid (fd) either on your hard disk using fdisk, or using LVM.

  2. Create a RAID 1 device named /dev/md0 using the two partitions.

  3. Format the RAID device as an ext4 filesystem. Then mount it at /myraid and make the mount persistent.

  4. Place the information about /dev/md0 in /etc/mdadm.conf file using mdadm. (Depending on your distribution, this file may not previously exist.)

  5. Examine /proc/mdstat to see the status of your RAID device. 

Solution

Suppose we have two partitions available (/dev/sdc1 and /dev/sdd1) with the "Linux raid auto" partition type, follow these steps

1. Create the RAID array /dev/md0

$ sudo mdadm -C /dev/md0 --level=1 --raid-disks=2 /dev/sdc1 /dev/sdd1

2. Set ext4 filesystem type upon /dev/md0 array

$ sudo makefs.ext4 /dev/md0

3. Create a directory where we will mount the filesystem

$ sudo make /myraid

4. Mount the filesystem of the md0 array at the created directory

$ sudo mount /dev/md0 /myraid

5. Write the mount configuration at the fstab 

$ sudo bash -c "echo '/dev/md0  /myraid  ext4  defaults  0  0' >> /etc/fstab"

6. Write the mdadm configuration output within its configuration file

$ sudo bash -c "mdadm --detail --scan >> /etc/mdadm.conf"

7. Check the RAID status

$ cat /proc/mdstat