File tree Expand file tree Collapse file tree 1 file changed +18
-17
lines changed Expand file tree Collapse file tree 1 file changed +18
-17
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
- set -xe
2
+ set -xeuo pipefail
3
3
4
4
echo " Starting NVMe disk setup"
5
5
6
- yum install -y lvm2
6
+ # Install required tools
7
+ yum install -y nvme-cli lvm2
7
8
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
13
14
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)
19
17
20
- echo " Found NVMe devices: ${NVME_DEVICES[@ ]:- none} "
18
+ echo " Found NVMe devices: ${SSD_NVME_DEVICE_LIST[* ]:- none} "
21
19
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"
24
22
exit 0
25
23
fi
26
24
27
- for device in " ${NVME_DEVICES[@]} " ; do
25
+ # Create physical volumes
26
+ for device in " ${SSD_NVME_DEVICE_LIST[@]} " ; do
28
27
pvcreate -f " $device "
29
28
done
30
29
31
- vgcreate instance-store-vg " ${NVME_DEVICES[@]} "
30
+ # Create volume group
31
+ vgcreate instance-store-vg " ${SSD_NVME_DEVICE_LIST[@]} "
32
32
33
+ # Display results
33
34
pvs
34
35
vgs
35
36
You can’t perform that action at this time.
0 commit comments