Loading...
 

RAID

Linux Software RAID

mdadm is used for building, managing, and monitoring Linux md devices (aka RAID arrays)
For detailed help on the above major modes use --help after the mode

e.g.
         mdadm --assemble --help
 For general help on options use
         mdadm –help-options

create a RAID1 deviced

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 missing

missing can be used to only add in one device

Create the config file

echo 'DEVICE /dev/sd[a-d] /dev/sd*[a-z]' > /etc/mdadm/mdadm.conf
mdadm --examine --scan --config=mdadm.conf >> /etc/mdadm/mdadm.conf

This will probably create extra unwanted data. Review mdadm.conf - in particular the devices= lines

view raid status

mdadm -- verbose --detail /dev/md0

removing a device

--manage is assumed and not a necessary flag

mdadm /dev/md0 --fail /dev/sda


then

mdadm /dev/md0 --remove /dev/sda

adding device

lsscsi or dmesg will show the device that has been added

echo "- - -" > /sys/class/scsi_host/hostX/scan

where X stands for the SCSI bus you want to scan. If using the same disk:

echo 1 > /sys/bus/scsi/drivers/sd/<SCSI-ID>/block/device/rescan.

Then

mdadm /dev/md0 –[re-]add /dev/sd[a,c]

grow the array

mdadm --grow /dev/md0 --size=930G --backup-file=/media/usb/backups/backup-md4
  • This can be for increasing or decreasing disks or the size. Backups must be on a separate device
  • growfs will need to be used to make the filesystem pick up the new size

Monitoring

if mdadm.conf has a MAILADDR set, then the following command will send and email to that address

/sbin/mdadm --monitor --pid-file /var/run/mdadm/monitor.pid --daemonise --scan --syslog

or from a monitoring platform to consume

sudo mdadm --detail --test /dev/md0 > /dev/null;echo $?

this will output a status code (0 = okay, 1 = 1 failed device, 2 = multiple failed devices, 4 = error gathering information)