17 June 2019

Create Software RAID Arrays using mdadm Commands

Create Software RAID Arrays using mdadm Commands

Creating a RAID 0 Array

Primary benefit: Performance (minimum of 2 storage devices)

Find the identifiers for the raw disks that you will be using:
lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT
Create the array:
mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sdb /dev/sdc
Ensure that the RAID was successfully created:
cat /proc/mdstat
Create and mount the filesystem:
mkfs.ext4 -F /dev/md0      # create the filesystem
mount /dev/md0 /mnt/md0    # mount the filesystem

Creating a RAID 1 Array

Primary benefit: Redundancy (minimum of 2 storage devices)

Find the identifiers for the raw disks that you will be using:
lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT
Create the array:
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
Ensure that the RAID was successfully created:
cat /proc/mdstat
Create and mount the filesystem:
mkfs.ext4 -F /dev/md0      # create the filesystem
mount /dev/md0 /mnt/md0    # mount the filesystem

Creating a RAID 5 Array

Primary benefit: Redundancy with more usable capacity (minimum of 3 storage devices)

Find the identifiers for the raw disks that you will be using:
lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT
Create the array:
mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd
Ensure that the RAID was successfully created:
cat /proc/mdstat
Create and mount the filesystem:
mkfs.ext4 -F /dev/md0      # create the filesystem
mount /dev/md0 /mnt/md0    # mount the filesystem

Other mdadm Maintenance Commands

Gathering RAID info:
mdadm --detail --scan    # dump current RAID configuration
mdadm --detail /dev/md0  # status of RAID array
Assemble a RAID array:
mdadm --assemble --scan                               # automatically using /etc/mdadm.conf
mdadm --assemble /dev/md1 --uuid xxxx:xxxx:xxxx:xxxx  # manually using uuid
Resetting existing RAID devices:
cat /proc/mdstat                          # find the active arrays
umount /dev/md0                           # unmount the array from the filesystem
mdadm --stop /dev/md0                     # stop the array
mdadm --remove /dev/md0                   # remove the array

lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT # Find the devices that were used to build the array
mdadm --zero-superblock /dev/sdb          # zero their superblock to reset them to normal 
mdadm --zero-superblock /dev/sdc          # zero their superblock to reset them to normal