Skip to content

Instantly share code, notes, and snippets.

@brahman81
Last active September 16, 2019 08:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brahman81/04d1d19b81f78385aacf0a9a3a3afe26 to your computer and use it in GitHub Desktop.
Save brahman81/04d1d19b81f78385aacf0a9a3a3afe26 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Inspired by https://github.com/oogali/ebs-automatic-nvme-mapping
# Thanks Oogali!
# Tested on Ubuntu 16.04
# To be used with the below udev rule (/etc/udev/rules.d/99-ebs-nvme.rules)
# SUBSYSTEM=="block", KERNEL=="nvme[0-9]*n[0-9]*", ATTRS{model}=="Amazon Elastic Block Store", PROGRAM+="/usr/local/sbin/nvme-mapping.sh /dev/%k" SYMLINK+="%c"
if [[ -x /usr/sbin/nvme ]] && [[ -b ${1} ]]; then
# capture 32 bytes at an offset of 3072 bytes from the raw-binary data
# not all block devices are extracted with /dev/ prefix
# use `xvd` prefix instead of `sd`
# remove all trailing space
nvme_link=$( \
/usr/sbin/nvme id-ctrl --raw-binary "${1}" | \
/usr/bin/cut -c3073-3104 | \
/bin/sed 's/^\/dev\///g'| \
/bin/sed 's/^sd/xvd/'| \
/usr/bin/tr -d '[:space:]' \
);
echo $nvme_link;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment