Linux Software RAID

What is RAID?

RAID stands for either Redundant Array of Independent Disks, or Redundant Array of Inexpensive Disks. The intention of RAID is to spread your data across several disks, such that a single disk failure will not lose that data.

The current RAID drivers in Linux support the following levels:

  • Linear Mode : JBOD
  • RAID0/Stripe : Two or more disks. No redundancy.
  • RAID1/Mirror : Two or more disks. Redundancy.
  • RAID-4 : Three or more disks. Redundancy. Not used very often.
  • RAID-5 : Three or more disks. Redundancy. Allows one disk failure.
  • RAID-6 : Four or more disks. Redundancy. Allows two disks failure.
  • RAID-10 : Four or more disks. Combination of RAID-1 and RAID-0.

Linux Software RAID (often called mdraid or MD/RAID) makes the use of RAID possible without a hardware RAID controller.

mdadm utility

The mdadm utility can be used to create and manage storage arrays using Linux’s software RAID capabilities.

Creating a RAID Array

The following example shows the creation of a RAID 0 array with 8 NVME disks.

$ mdadm --create /dev/md0 --name=mdvol --level=raid0 --raid-devices=8 /dev/nvme2n1 /dev/nvme3n1 /dev/nvme4n1 /dev/nvme5n1 /dev/nvme6n1 /dev/nvme7n1 /dev/nvme8n1 /dev/nvme9n1

Check RAID array status

$ cat /proc/mdstat
    Personalities : [raid0]
    md0 : active raid0 nvme9n1[7] nvme8n1[6] nvme7n1[5] nvme6n1[4] nvme5n1[3] nvme4n1[2] nvme3n1[1] nvme2n1[0]
      30004846592 blocks super 1.2 512k chunks

$  mdadm --detail /dev/md0
    /dev/md0:
               Version : 1.2
         Creation Time : Mon Sep 20 17:39:47 2021
            Raid Level : raid0
            Array Size : 30004846592 (27.94 TiB 30.72 TB)
          Raid Devices : 8
         Total Devices : 8
           Persistence : Superblock is persistent
    
           Update Time : Mon Sep 20 17:39:47 2021
                 State : clean
        Active Devices : 8
       Working Devices : 8
        Failed Devices : 0
         Spare Devices : 0
    
            Chunk Size : 512K
    
    Consistency Policy : none
    
                  Name : host1:mdvol
                  UUID : 5908fc3f:8c8b8851:c0875278:ea274fec
                Events : 0
    
        Number   Major   Minor   RaidDevice State
           0     259        2        0      active sync   /dev/nvme2n1
           1     259        6        1      active sync   /dev/nvme3n1
           2     259        7        2      active sync   /dev/nvme4n1
           3     259        8        3      active sync   /dev/nvme5n1
           4     259       11        4      active sync   /dev/nvme6n1
           5     259       12        5      active sync   /dev/nvme7n1
           6     259       10        6      active sync   /dev/nvme8n1
           7     259        9        7      active sync   /dev/nvme9n1 

Deleting a RAID Array

If a RAID volume is no longer required, it can be deactivated using the following commands:

$ mdadm --stop /dev/md0
mdadm: stopped /dev/md0

A Linux software RAID array stores all of the necessary information about a RAID array in a superblock. The superblock for the individual devices can be deleted by the following commands. By doing this, you can re-use these disks for new RAID arrays.

$ mdadm --zero-superblock /dev/nvme2n1 /dev/nvme3n1 /dev/nvme4n1 /dev/nvme5n1 /dev/nvme6n1 /dev/nvme7n1 /dev/nvme8n1 /dev/nvme9n1

Reference