Skip to content

Instantly share code, notes, and snippets.

@tgerla
Created January 15, 2013 23:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tgerla/4543228 to your computer and use it in GitHub Desktop.
Save tgerla/4543228 to your computer and use it in GitHub Desktop.
Attach a volume to an instance and try to detect which device it ended up on. Hacky.
attach_volume () {
volId=$1
grep vd[a-z]$ /proc/partitions | awk "{print \$4;}" > /tmp/before
sleep 2
# attach the volume
echo "Attaching $volId to $instanceId"
euca-attach-volume -i $instanceId $volId -d /dev/vdc
sleep 5
# detect which device the volume is attached to
grep vd[a-z]$ /proc/partitions | awk "{print \$4;}" > /tmp/after
NEWDEV=$(diff -C0 /tmp/before /tmp/after | grep ^+ | awk "{print \$2;}")
if [ ! $NEWDEV ]; then
echo "Can't detect newly-attached device--quitting."
exit 1
fi
rm -f /tmp/before /tmp/after
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment