summaryrefslogtreecommitdiff
path: root/mkraid
blob: 26ce7bef0d106b7594615c51449c2f1bd245e1de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/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)

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