Created
April 22, 2019 06:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.