azurehpc/scripts/create_raid0.sh

45 строки
944 B
Bash
Исходник Обычный вид История

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
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"
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
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
mdadm --verbose --detail --scan > /etc/mdadm.conf