Created
January 15, 2013 23:42
-
-
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.
This file contains 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
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