summaryrefslogtreecommitdiff
path: root/mkraid
diff options
context:
space:
mode:
authorSam Chudnick <sam@chudnick.com>2022-04-15 21:08:34 -0400
committerSam Chudnick <sam@chudnick.com>2022-04-15 21:08:34 -0400
commit85c561f9a32f8f2b9ddf34e7d60ef4b7bf0d3680 (patch)
tree637c319270201555d66f9bf1cbcc63d893405e69 /mkraid
inital commit - various scripts
Diffstat (limited to 'mkraid')
-rwxr-xr-xmkraid53
1 files changed, 53 insertions, 0 deletions
diff --git a/mkraid b/mkraid
new file mode 100755
index 0000000..b2fe60b
--- /dev/null
+++ b/mkraid
@@ -0,0 +1,53 @@
1#!/bin/sh
2
3help() {
4 echo "usage: mkraid --id array_id --name array_name --level raid_level" \
5 "--devices 'raid_device_1 raid_device_2 ...'" \
6 "--spares 'spare_device_1 spare_device_2 ...'"
7 echo "\n-i, --id:\tid of RAID array as a number up to 127"
8 echo "-n, --name:\tname of RAID array"
9 echo "-l, --level:\tRAID level"
10 echo "-d, --devices:\tdevices in RAID array - quoted and space separated"
11 echo "-s, --spares:\thot spare devices - quoted and space separated if multiple"
12 echo "\nexample: mkraid --id 0 --name arr1 --level 5 --devices"\
13 "'/dev/sda /dev/sdb /dev/sdc' --spares /dev/sdd"
14 exit
15}
16
17opts=$(getopt -o "i:,n:,l:,d:,s:h" -l "id:,name:,level:,devices:,spares:,help" -- "$@")
18eval set -- "$opts"
19id=
20name=
21level=
22devices=
23spares=
24while true
25do
26 case "$1" in
27 '-i' | '--id') id="$2" shift 2; continue ;;
28 '-n' | '--name') name="$2" shift 2; continue ;;
29 '-l' | '--level') level="$2" shift 2; continue ;;
30 '-d' | '--devices') devices="$2" shift 2; continue ;;
31 '-s' | '--spares') spares="$2" shift 2; continue ;;
32 '-h' | '--help') help ;;
33 '--') shift; break ;;
34 esac
35done
36[ -z "$id" ] && help
37[ -z "$name" ] && help
38[ -z "$level" ] && help
39[ -z "$devices" ] && help
40[ -z "$spares" ] && help
41
42numdevs=$(echo $devices | tr ' ' '\n' | wc -l)
43numspare=$(echo $spares | tr ' ' '\n' | wc -l)
44
45echo "mdadm --create /dev/md$id --level=$level --raid-devices=$numdevs $devices --spare-devices=$numspare $spares"
46
47exit
48
49mdadm --create /dev/md$id --level=$level --raid-devices=$numdevs $devices --spare-devices=$numspare $spares
50
51uuid="$(mdadm --detail /dev/md0 | grep UUID | tr -d '[:space:]' | cut -d ':' -f 2-)"
52
53echo "ARRAY /dev/md$id metadata=1.2 UUID=$uuid name=$name" >> /etc/mdadm/mdadm.conf