diff options
| author | Sam Chudnick <sam@chudnick.com> | 2022-04-15 21:08:34 -0400 | 
|---|---|---|
| committer | Sam Chudnick <sam@chudnick.com> | 2022-04-15 21:08:34 -0400 | 
| commit | 85c561f9a32f8f2b9ddf34e7d60ef4b7bf0d3680 (patch) | |
| tree | 637c319270201555d66f9bf1cbcc63d893405e69 /mkraid | |
inital commit - various scripts
Diffstat (limited to 'mkraid')
| -rwxr-xr-x | mkraid | 53 | 
1 files changed, 53 insertions, 0 deletions
| @@ -0,0 +1,53 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | help() { | ||
| 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 | |||
| 17 | opts=$(getopt -o "i:,n:,l:,d:,s:h" -l "id:,name:,level:,devices:,spares:,help" -- "$@") | ||
| 18 | eval set -- "$opts" | ||
| 19 | id= | ||
| 20 | name= | ||
| 21 | level= | ||
| 22 | devices= | ||
| 23 | spares= | ||
| 24 | while true | ||
| 25 | do | ||
| 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 | ||
| 35 | done | ||
| 36 | [ -z "$id" ] && help | ||
| 37 | [ -z "$name" ] && help | ||
| 38 | [ -z "$level" ] && help | ||
| 39 | [ -z "$devices" ] && help | ||
| 40 | [ -z "$spares" ] && help | ||
| 41 | |||
| 42 | numdevs=$(echo $devices | tr ' ' '\n' | wc -l) | ||
| 43 | numspare=$(echo $spares | tr ' ' '\n' | wc -l) | ||
| 44 | |||
| 45 | echo "mdadm --create /dev/md$id --level=$level --raid-devices=$numdevs $devices --spare-devices=$numspare $spares" | ||
| 46 | |||
| 47 | exit | ||
| 48 | |||
| 49 | mdadm --create /dev/md$id --level=$level --raid-devices=$numdevs $devices --spare-devices=$numspare $spares | ||
| 50 | |||
| 51 | uuid="$(mdadm --detail /dev/md0 | grep UUID | tr -d '[:space:]' | cut -d ':' -f 2-)" | ||
| 52 | |||
| 53 | echo "ARRAY /dev/md$id metadata=1.2 UUID=$uuid name=$name" >> /etc/mdadm/mdadm.conf | ||
