Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add ephemera storage to Amazon ECS-optimized AMIs (v1)
#!/bin/bash -exu
# find ephemeral devices using the metadata service
# note: this will block loading until the metadata service is ready
find_ephemeral_devices() {
echo "Querying metadata instance store for ephemeral volumes" >&2
local DEVICE_NOT_FOUND=0
for d in $(curl -s "http://169.254.169.254/latest/meta-data/block-device-mapping/" | grep ephemeral); do
NAME=$(curl -s "http://169.254.169.254/latest/meta-data/block-device-mapping/$d")
DEVICE_NAME="/dev/$NAME"
echo "Detected ephemeral device $d corresponding to $DEVICE_NAME" >&2
# if block device (-b)
if [[ -b "$DEVICE_NAME" ]]; then
echo "$DEVICE_NAME"
DEVICE_NOT_FOUND=0
else
echo "Couldn't find device $DEVICE_NAME" >&2
DEVICE_NOT_FOUND=1
fi
done
return ${DEVICE_NOT_FOUND}
}
# on nvme instances the device names don't match what AWS reports, so just filter by model name
find_nvme_ephemeral() {
lsblk -o KNAME,MODEL | grep "Amazon EC2 NVMe Instance Storage" | awk '{ print "/dev/"$1 }'
}
METADATA_DEVICES=$(find_ephemeral_devices)
NVME_DEVICES=$(find_nvme_ephemeral)
DEVS=/dev/xvdcz
[[ ! -z "$NVME_DEVICES" ]] && DEVS="$NVME_DEVICES $DEVS"
[[ ! -z "$METADATA_DEVICES" ]] && DEVS="$METADATA_DEVICES $DEVS"
echo "Updating docker storage devices to '$DEVS'"
sed -i -e "s;DEVS=.*;DEVS=\"${DEVS}\";g" /etc/sysconfig/docker-storage-setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.