Skip to content

Instantly share code, notes, and snippets.

@luhn
Created April 5, 2021 21:21
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 luhn/702d976757f4e711a943f070935ac952 to your computer and use it in GitHub Desktop.
Save luhn/702d976757f4e711a943f070935ac952 to your computer and use it in GitHub Desktop.
Mount NVMe EBS volume
# Mount the data disk
# Adapted from https://gist.github.com/ctompkinson/30f570882af38879b36fc7bffe3d1a60
device=/dev/sdh
mount_point=/monitor-config
apt-get install -y nvme-cli
while [ true ]; do
for blkdev in $(nvme list | awk '/^\/dev/ { print $1 }'); do
mapping=$(nvme id-ctrl --raw-binary "${blkdev}" | cut -c3073-3104 | tr -s ' ' | sed 's/ $//g')
if [ ${mapping} = ${device} ]; then
echo "Found $device on $blkdev"
if ! file -s ${blkdev} | grep -q ext4; then
echo "Device empty, formatting..."
mkfs -t ext4 ${blkdev}
fi
echo "Mounting..."
mkdir ${mount_point}
uuid=$(blkid -s UUID -o value ${blkdev})
echo "UUID=\"${uuid}\" ${mount_point} ext4 defaults,nofail" >> /etc/fstab
mount UUID="${uuid}"
echo "Done!"
break 2
fi
done
echo "Could not find drive, trying again in 1 second."
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment