The Basics

mdadm (multiple devices admin) is software solution to manage RAID.

It allow:

  • create, manage, monitor your disks in an RAID array.
  • you can the full disks (/dev/sdb, /dev/sdc) or (/dev/sdb1, /dev/sdc1)
  • replace or complete raidtools

Checks

  • Basic checks
1# View real-time information about your md devices
2cat /proc/mdstat 
3
4# Monitor for failed disks (indicated by "(F)" next to the disk)
5watch cat /proc/mdstat
  • Checks RAID
1# Display details about the RAID array (replace /dev/md0 with your array)
2mdadm --detail /dev/md0 
3
4# Examine RAID disks for information (not volume) similar to --detail
5mdadm --examine /dev/sd*

Settings

The conf file /etc/mdadm.conf does not exist by default and need to be created once you finish your install. This file is required for the autobuild at boot.

1# mdadm --detail -scan 
2ARRAY /dev/md0 level=linear num-devices=2 metadata=1.2 name=localhost.localdomain:0 UUID=a50ac9f2:62646d92:725255bd:7f9d30e3 devices=/dev/sdb,/dev/sdc 
3	
4# As seen in the output above, I have a linear array md0 with 2 devices /dev/sdb and /dev/sdc.
5mdadm --verbose --detail -scan > /etc/mdadm.conf 
6mdadm --examine -scan > /etc/mdadm.conf

Corrective Actions

  • Put back the config
1mdadm -D --scan
2mdadm -D /dev/md3 --scan
3mdadm -D /dev/md3 --scan >> /etc/mdadm.conf
  • Remove and Add a disk without downtime (almost)
 1mdadm -D /dev/md124
 2mdadm --manage --remove /dev/md124 /dev/san/BETZ9C50D4C
 3mdadm --manage --add /dev/md124 /dev/san/BETZ9C50D4C
 4
 5# one command-line
 6mdadm /dev/md5 --remove /dev/dm-64 --add /dev/dm-64
 7
 8ls -l /dev/dm-64 
 9mdadm /dev/md5  --add /dev/dm-64 
10mdadm --detail /dev/md5
11
12mdadm --assemble --force /dev/md/pvdata_2 /dev/sd[n-y]

Create and manage RAID array

  • Linear Mode
1# Longue Version
2mdadm --create --verbose /dev/md0 --level=linear --raid-devices=2 /dev/sdb /dev/sdc
3
4# Short version
5mdadm --Cv /dev/md0 --l linear -n2 /dev/sdb /dev/sdc
  • RAID 0
1mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sdb /dev/sdc
  • RAID 1
1mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc --spare-devices=/dev/sdd
  • RAID 5
1# with 3 devices and a spare
2mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd --spare-devices=/dev/sde  
3
4# with 6 devices
5mdadm --create --verbose /dev/md/pvdata_1 --level=5 --raid-devices=6 --assume-clean /dev/sd[c-h]
  • Attach your fs to an Array
1mkfs.ext4 /dev/md0
2mkdir /data01
3mount /dev/md0 /data01
4# Add it to /etc/fstab
  • Delete a Array
1mdadm --stop /dev/md0
2mdadm --remove /dev/md0
  • Relaunch a Array
1mdadm --stop /dev/md0
2mdadm --assemble /dev/md0

The assemble command relies on the /etc/mdadm.conf file for array configuration. Ensure you’ve saved your configuration in mdadm.conf before stopping the array to prevent issues during reassembly.

  • Add disk to an Array
1mdadm --add /dev/md0 /dev/sdd
  • Remove a disks from an Array - first fail a device (-f) from an array and then remove (-r) it.
1mdadm --manage /dev/md0 -f /dev/sdd
2mdadm --manage /dev/md0 -r /dev/sdd
  • Change a disk on a RAID mirroring:
 1# First data need to be writen
 2sync; sync; sync
 3# Put in fail 
 4mdadm --manage /dev/md0 --fail /dev/sdb1
 5# Remove disk
 6mdadm --manage /dev/md0 --remove /dev/sdb1
 7# Copy partition table
 8sfdisk -d /dev/sda | sfdisk /dev/sdb
 9# Recreate mirror
10mdadm --manage /dev/md0 --add /dev/sdb1
11# Test and check the rebuild 
12/sbin/mdadm --detail /dev/md0 
13cat /proc/mdstat