Skip to content

Instantly share code, notes, and snippets.

@JJC1138
Created April 22, 2019 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JJC1138/6669ac7d93b8e83ff07e62f0bc2e9500 to your computer and use it in GitHub Desktop.
Save JJC1138/6669ac7d93b8e83ff07e62f0bc2e9500 to your computer and use it in GitHub Desktop.
Shell script to list all NVMe Instance Storage Devices on an EC2 instance
#!/bin/bash -e
for nvme_device_name in `lsblk | cut --delimiter=" " --fields=1 | grep ^nvme | sort -n`; do
nvme_device="/dev/${nvme_device_name}"
if ( nvme id-ctrl "${nvme_device}" | grep --quiet "^mn\\s*:\\s*Amazon EC2 NVMe Instance Storage\\s*$" ); then
echo "${nvme_device}"
fi
done
@JJC1138
Copy link
Author

JJC1138 commented Apr 22, 2019

This might come in handy if you want to inspect your instance's NVMe Instance Storage configuration at runtime so that you can make a generic instance that can work across different instance types without having to configure the launch parameters specially for that instance type's storage.

It's necessary because the NVMe devices that are available can be EBS volumes or Instance Storage volumes and the numbering isn't reliable so you have to query to see which ones are which.

I don't think the device manufacturer string that this script is looking for is officially documented so caveat emptor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment