-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathaks-nvme-ssd-provisioner.sh
55 lines (48 loc) · 1.81 KB
/
aks-nvme-ssd-provisioner.sh
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
50
51
52
53
54
55
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
SSD_NVME_DEVICE_LIST=($(ls /sys/block | grep nvme | xargs -I. echo /dev/. || true))
SSD_NVME_DEVICE_COUNT=${#SSD_NVME_DEVICE_LIST[@]}
RAID_DEVICE=${RAID_DEVICE:-/dev/md0}
RAID_CHUNK_SIZE=${RAID_CHUNK_SIZE:-512} # Kilo Bytes
FILESYSTEM_BLOCK_SIZE=${FILESYSTEM_BLOCK_SIZE:-4096} # Bytes
STRIDE=$(expr $RAID_CHUNK_SIZE \* 1024 / $FILESYSTEM_BLOCK_SIZE || true)
STRIPE_WIDTH=$(expr $SSD_NVME_DEVICE_COUNT \* $STRIDE || true)
# Checking if provisioning already happend
if [[ "$(ls -A /pv-disks)" ]]
then
echo 'Volumes already present in "/pv-disks"'
echo -e "\n$(ls -Al /pv-disks | tail -n +2)\n"
echo "I assume that provisioning already happend, doing nothing!"
sleep infinity
fi
# Perform provisioning based on nvme device count
case $SSD_NVME_DEVICE_COUNT in
"0")
echo 'No devices found of type "Microsoft NVMe Direct Disk"'
echo "Maybe your node selectors are not set correct"
exit 1
;;
"1")
mkfs.ext4 -m 0 -b $FILESYSTEM_BLOCK_SIZE $SSD_NVME_DEVICE_LIST
DEVICE=$SSD_NVME_DEVICE_LIST
;;
*)
mdadm --create --verbose $RAID_DEVICE --level=0 -c ${RAID_CHUNK_SIZE} \
--raid-devices=${#SSD_NVME_DEVICE_LIST[@]} ${SSD_NVME_DEVICE_LIST[*]}
while [ -n "$(mdadm --detail $RAID_DEVICE | grep -ioE 'State :.*resyncing')" ]; do
echo "Raid is resyncing.."
sleep 1
done
echo "Raid0 device $RAID_DEVICE has been created with disks ${SSD_NVME_DEVICE_LIST[*]}"
mkfs.ext4 -m 0 -b $FILESYSTEM_BLOCK_SIZE -E stride=$STRIDE,stripe-width=$STRIPE_WIDTH $RAID_DEVICE
DEVICE=$RAID_DEVICE
;;
esac
UUID=$(blkid -s UUID -o value $DEVICE)
mkdir -p /pv-disks/$UUID
mount -o defaults,noatime,discard,nobarrier --uuid $UUID /pv-disks/$UUID
echo "Device $DEVICE has been mounted to /pv-disks/$UUID"
echo "NVMe SSD provisioning is done and I will go to sleep now"
#sleep infinity