2019-07-20 17:15:29 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# arg: $1 = raid_device (e.g. /dev/md10)
|
|
|
|
# arg: $* = devices to use (can use globbing)
|
|
|
|
|
|
|
|
raid_device=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
devices=
|
|
|
|
while (( "$#" )); do
|
|
|
|
devices="$devices $1"
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2020-04-16 20:13:35 +03:00
|
|
|
echo "devices=$devices"
|
|
|
|
|
|
|
|
# print partition information
|
2020-04-16 20:40:01 +03:00
|
|
|
parted -s --list 2>/dev/null
|
2020-04-16 20:07:44 +03:00
|
|
|
|
2020-04-16 20:13:35 +03:00
|
|
|
# creating the partitions
|
2019-07-20 17:15:29 +03:00
|
|
|
for disk in $devices; do
|
2020-04-16 20:13:35 +03:00
|
|
|
echo "partitioning $disk"
|
2020-01-13 14:25:10 +03:00
|
|
|
parted -s $disk "mklabel gpt"
|
|
|
|
parted -s $disk -a optimal "mkpart primary 1 -1"
|
|
|
|
parted -s $disk print
|
|
|
|
parted -s $disk "set 1 raid on"
|
2020-04-16 20:13:35 +03:00
|
|
|
done
|
2019-07-20 17:15:29 +03:00
|
|
|
|
2020-04-16 20:13:35 +03:00
|
|
|
# make sure all the partitions are ready
|
|
|
|
sleep 10
|
|
|
|
# get the partition names
|
|
|
|
partitions=
|
|
|
|
for disk in $devices; do
|
2020-03-17 19:06:25 +03:00
|
|
|
partitions="$partitions $(lsblk -no kname -p $disk | tail -n1)"
|
2019-07-20 17:15:29 +03:00
|
|
|
done
|
2020-04-16 20:13:35 +03:00
|
|
|
echo "partitions=$partitions"
|
2019-07-20 17:15:29 +03:00
|
|
|
|
|
|
|
ndevices=$(echo $partitions | wc -w)
|
|
|
|
|
2020-04-16 20:13:35 +03:00
|
|
|
echo "creating raid device"
|
2020-04-16 20:41:19 +03:00
|
|
|
mdadm --create $raid_device --level 0 --raid-devices $ndevices $partitions || exit 1
|
2019-07-20 17:15:29 +03:00
|
|
|
sleep 10
|
2020-01-13 14:25:10 +03:00
|
|
|
|
|
|
|
mdadm --verbose --detail --scan > /etc/mdadm.conf
|