Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

script and udev rule for deterministic ephemeral devices #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 999-aws-ebs-nvme.rules
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
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"
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon EC2 NVMe Instance Storage", PROGRAM="/usr/local/bin/nextephemeraldevice.sh %k", SYMLINK+="%c"
27 changes: 27 additions & 0 deletions nextephemeraldevice.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# To be used with the udev rule: /etc/udev/rules.d/999-aws-ebs-nvme.rules

# check if lock file exists
script_name="$(basename $0)"
pid_file="/tmp/${script_name}.lock"
counter=0
until [ $counter -eq 5 ] || [[ ! -e "${pid_file}" ]] ; do
sleep $(( counter++ ))
done

# create lock file if it does not exist
if [[ -e "${pid_file}" ]]; then
echo "Lock file ${pid_file} still exists after counter ended" >&2
exit 1
else
touch "${pid_file}"
fi

kern_name=${1}
incr=0
while [[ -e "/dev/ephemeral${incr}" ]] && [[ $(readlink "/dev/ephemeral${incr}") != "${kern_name}" ]]; do
incr=$[$i+1]
done
# remove lock file
rm "${pid_file}"
echo "ephemeral${incr}"