Skip to content

Commit 3a63fb4

Browse files
committed
Improve bootstrap script
1 parent 7278652 commit 3a63fb4

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

modules/eks/bootstrap.sh

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
#!/bin/bash
2-
set -xe
2+
set -xeuo pipefail
33

44
echo "Starting NVMe disk setup"
55

6-
yum install -y lvm2
6+
# Install required tools
7+
yum install -y nvme-cli lvm2
78

8-
ROOT_PART=$(findmnt -n -o SOURCE / | sed 's/\[.*\]//')
9-
ROOT_DEVICE=$(lsblk -no PKNAME "$ROOT_PART")
10-
ROOT_DEVICE="/dev/${ROOT_DEVICE}"
11-
12-
NVME_DEVICES=()
9+
# Check if NVMe instance storage is available
10+
if ! nvme list | grep -q "Amazon EC2 NVMe Instance Storage"; then
11+
echo "No NVMe instance storage devices found"
12+
exit 0
13+
fi
1314

14-
for dev in /dev/nvme*n1; do
15-
if [ "$dev" != "$ROOT_DEVICE" ] && [ -b "$dev" ]; then
16-
NVME_DEVICES+=("$dev")
17-
fi
18-
done
15+
# Collect NVMe instance storage devices
16+
mapfile -t SSD_NVME_DEVICE_LIST < <(nvme list | grep "Amazon EC2 NVMe Instance Storage" | awk '{print $1}' || true)
1917

20-
echo "Found NVMe devices: ${NVME_DEVICES[@]:-none}"
18+
echo "Found NVMe devices: ${SSD_NVME_DEVICE_LIST[*]:-none}"
2119

22-
if [ ${#NVME_DEVICES[@]} -eq 0 ]; then
23-
echo "No NVMe instance storage devices found"
20+
if [ ${#SSD_NVME_DEVICE_LIST[@]} -eq 0 ]; then
21+
echo "No usable NVMe instance storage devices found"
2422
exit 0
2523
fi
2624

27-
for device in "${NVME_DEVICES[@]}"; do
25+
# Create physical volumes
26+
for device in "${SSD_NVME_DEVICE_LIST[@]}"; do
2827
pvcreate -f "$device"
2928
done
3029

31-
vgcreate instance-store-vg "${NVME_DEVICES[@]}"
30+
# Create volume group
31+
vgcreate instance-store-vg "${SSD_NVME_DEVICE_LIST[@]}"
3232

33+
# Display results
3334
pvs
3435
vgs
3536

0 commit comments

Comments
 (0)