Skip to content

Commit c26be32

Browse files
committed
setup each disk individually
1 parent ffacf59 commit c26be32

File tree

1 file changed

+28
-44
lines changed

1 file changed

+28
-44
lines changed

eks-nvme-ssd-provisioner.sh

+28-44
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,40 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
23

3-
set -o errexit
4-
set -o nounset
5-
set -o pipefail
6-
7-
SSD_NVME_DEVICE_LIST=($(nvme list | grep "Amazon EC2 NVMe Instance Storage" | cut -d " " -f 1 || true))
4+
mapfile -t SSD_NVME_DEVICE_LIST < <(nvme list | awk '/Amazon EC2 NVMe Instance Storage/{print $1}' || true)
85
SSD_NVME_DEVICE_COUNT=${#SSD_NVME_DEVICE_LIST[@]}
9-
RAID_DEVICE=${RAID_DEVICE:-/dev/md0}
10-
RAID_CHUNK_SIZE=${RAID_CHUNK_SIZE:-512} # Kilo Bytes
116
FILESYSTEM_BLOCK_SIZE=${FILESYSTEM_BLOCK_SIZE:-4096} # Bytes
12-
STRIDE=$(expr $RAID_CHUNK_SIZE \* 1024 / $FILESYSTEM_BLOCK_SIZE || true)
13-
STRIPE_WIDTH=$(expr $SSD_NVME_DEVICE_COUNT \* $STRIDE || true)
14-
157

16-
# Checking if provisioning already happend
17-
if [[ "$(ls -A /pv-disks)" ]]
18-
then
19-
echo 'Volumes already present in "/pv-disks"'
20-
echo -e "\n$(ls -Al /pv-disks | tail -n +2)\n"
21-
echo "I assume that provisioning already happend, doing nothing!"
22-
sleep infinity
8+
# Checking if provisioning already happened
9+
if [[ "$(ls -A /pv-disks)" ]]; then
10+
echo 'Volumes already present in "/pv-disks"'
11+
echo -e "\n$(ls -Al /pv-disks | tail -n +2)\n"
12+
echo "I assume that provisioning already happened, doing nothing!"
13+
sleep infinity
2314
fi
2415

2516
# Perform provisioning based on nvme device count
26-
case $SSD_NVME_DEVICE_COUNT in
17+
case ${SSD_NVME_DEVICE_COUNT} in
2718
"0")
28-
echo 'No devices found of type "Amazon EC2 NVMe Instance Storage"'
29-
echo "Maybe your node selectors are not set correct"
30-
exit 1
31-
;;
32-
"1")
33-
mkfs.xfs -m 0 -b $FILESYSTEM_BLOCK_SIZE $SSD_NVME_DEVICE_LIST
34-
DEVICE=$SSD_NVME_DEVICE_LIST
35-
;;
19+
echo 'No devices found of type "Amazon EC2 NVMe Instance Storage"'
20+
echo "Maybe your node selectors are not set correct"
21+
exit 1
22+
;;
3623
*)
37-
mdadm --create --verbose $RAID_DEVICE --level=0 -c ${RAID_CHUNK_SIZE} \
38-
--raid-devices=${#SSD_NVME_DEVICE_LIST[@]} ${SSD_NVME_DEVICE_LIST[*]}
39-
while [ -n "$(mdadm --detail $RAID_DEVICE | grep -ioE 'State :.*resyncing')" ]; do
40-
echo "Raid is resyncing.."
41-
sleep 1
42-
done
43-
echo "Raid0 device $RAID_DEVICE has been created with disks ${SSD_NVME_DEVICE_LIST[*]}"
44-
mkfs.ext4 -m 0 -b $FILESYSTEM_BLOCK_SIZE -E stride=$STRIDE,stripe-width=$STRIPE_WIDTH $RAID_DEVICE
45-
DEVICE=$RAID_DEVICE
46-
;;
24+
i=0
25+
for DEVICE in "${SSD_NVME_DEVICE_LIST[@]}"; do
26+
((i+=1))
27+
mkfs.xfs -f -m crc=0 -b size="${FILESYSTEM_BLOCK_SIZE}" "${DEVICE}"
28+
UUID=$(blkid -s UUID -o value "${DEVICE}")
29+
mkdir -p /pv-disks/"${UUID}"
30+
mount -o defaults,noatime,discard,nobarrier --uuid "${UUID}" /pv-disks/"${UUID}"
31+
mkdir -p /nvme
32+
ln -s /pv-disks/"${UUID}" /nvme/disk"${i}"
33+
echo "Device ${DEVICE} has been mounted to /pv-disks/${UUID}"
34+
echo "NVMe SSD provisioning is done and I will go to sleep now"
35+
done
36+
;;
4737
esac
4838

49-
UUID=$(blkid -s UUID -o value $DEVICE)
50-
mkdir -p /pv-disks/$UUID
51-
mount -o defaults,noatime,discard,nobarrier --uuid $UUID /pv-disks/$UUID
52-
ln -s /pv-disks/$UUID /nvme/disk
53-
echo "Device $DEVICE has been mounted to /pv-disks/$UUID"
54-
echo "NVMe SSD provisioning is done and I will go to sleep now"
5539

56-
sleep infinity
40+
sleep infinity

0 commit comments

Comments
 (0)