Skip to content

Commit

Permalink
nvme-udev-rule: add udev rule to ensure block device symlinks exist f…
Browse files Browse the repository at this point in the history
…or modern nvme EBS mappings
  • Loading branch information
missinglink committed Feb 8, 2022
1 parent 46420d5 commit b5e4115
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions templates/setup.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,38 @@ if [[ "$potential_nvme_disk" != "" ]]; then
data_volume_name=$potential_nvme_disk
fi

# Automatic Mapping of NVMe-style EBS Volumes to Standard Block Device Paths
# https://github.com/oogali/ebs-automatic-nvme-mapping
cat << EOF > /usr/local/sbin/ebs-nvme-mapping.sh
#!/bin/bash
if [[ -z nvme ]]; then
echo "ERROR: NVME tools not installed." >> /dev/stderr
exit 1
fi
if [[ ! -b $1 ]]; then
echo "ERROR: cannot find block device $1" >> /dev/stderr
exit 1
fi
nvme_link=$$( \
nvme id-ctrl --output binary "$1" | \
cut -c3073-3104 | \
sed 's/^\/dev\///g'| \
tr -d '[:space:]' \
);
echo $nvme_link;
EOF

sudo chmod +x /usr/local/sbin/ebs-nvme-mapping.sh

cat << EOF > /etc/udev/rules.d/999-aws-ebs-nvme.rules
SUBSYSTEM=="block", KERNEL=="nvme[0-9]*n1", ATTRS{model}=="Amazon Elastic Block Store", PROGRAM+="/usr/local/sbin/ebs-nvme-mapping.sh /dev/%k" SYMLINK+="%c"
EOF

sudo apt-get update -y && sudo apt-get install -y nvme-cli
sudo udevadm control --reload-rules && udevadm trigger

sudo mkfs -t ext4 $data_volume_name
sudo tune2fs -m 0 $data_volume_name
sudo mkdir -p ${elasticsearch_data_dir}
Expand Down

0 comments on commit b5e4115

Please sign in to comment.