From 85c561f9a32f8f2b9ddf34e7d60ef4b7bf0d3680 Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Fri, 15 Apr 2022 21:08:34 -0400 Subject: inital commit - various scripts --- mkraid | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 mkraid (limited to 'mkraid') diff --git a/mkraid b/mkraid new file mode 100755 index 0000000..b2fe60b --- /dev/null +++ b/mkraid @@ -0,0 +1,53 @@ +#!/bin/sh + +help() { + echo "usage: mkraid --id array_id --name array_name --level raid_level" \ + "--devices 'raid_device_1 raid_device_2 ...'" \ + "--spares 'spare_device_1 spare_device_2 ...'" + echo "\n-i, --id:\tid of RAID array as a number up to 127" + echo "-n, --name:\tname of RAID array" + echo "-l, --level:\tRAID level" + echo "-d, --devices:\tdevices in RAID array - quoted and space separated" + echo "-s, --spares:\thot spare devices - quoted and space separated if multiple" + echo "\nexample: mkraid --id 0 --name arr1 --level 5 --devices"\ + "'/dev/sda /dev/sdb /dev/sdc' --spares /dev/sdd" + exit +} + +opts=$(getopt -o "i:,n:,l:,d:,s:h" -l "id:,name:,level:,devices:,spares:,help" -- "$@") +eval set -- "$opts" +id= +name= +level= +devices= +spares= +while true +do + case "$1" in + '-i' | '--id') id="$2" shift 2; continue ;; + '-n' | '--name') name="$2" shift 2; continue ;; + '-l' | '--level') level="$2" shift 2; continue ;; + '-d' | '--devices') devices="$2" shift 2; continue ;; + '-s' | '--spares') spares="$2" shift 2; continue ;; + '-h' | '--help') help ;; + '--') shift; break ;; + esac +done +[ -z "$id" ] && help +[ -z "$name" ] && help +[ -z "$level" ] && help +[ -z "$devices" ] && help +[ -z "$spares" ] && help + +numdevs=$(echo $devices | tr ' ' '\n' | wc -l) +numspare=$(echo $spares | tr ' ' '\n' | wc -l) + +echo "mdadm --create /dev/md$id --level=$level --raid-devices=$numdevs $devices --spare-devices=$numspare $spares" + +exit + +mdadm --create /dev/md$id --level=$level --raid-devices=$numdevs $devices --spare-devices=$numspare $spares + +uuid="$(mdadm --detail /dev/md0 | grep UUID | tr -d '[:space:]' | cut -d ':' -f 2-)" + +echo "ARRAY /dev/md$id metadata=1.2 UUID=$uuid name=$name" >> /etc/mdadm/mdadm.conf -- cgit v1.2.3