-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathEBSmount.sh
31 lines (26 loc) · 1.17 KB
/
EBSmount.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
VOLUME_ID=vol-054914c6b50b19a9c
#Check devices and mapping
#aws ec2 describe-volumes --region eu-west-1 --filters Name=attachment.instance-id,Values=$INSTANCE_ID --query 'Volumes[*].Attachments[*].{VolumeId:VolumeId,DeviceMapping:Device}' --output text
#Type ID and mount
#aws ec2 describe-volumes --region eu-west-1 --filters Name=attachment.instance-id,Values=i-01038c9bddee62cf8 --query 'Volumes[*].{Type:VolumeType,ID:VolumeId,Mounted_as:Attachments[*].Device}' --output text
VOL_STATE=`aws ec2 describe-volumes --volume-ids $VOLUME_ID --region eu-west-1 --query 'Volumes[0].State' --output text`
if [ $VOL_STATE = in-use ]; then
aws ec2 detach-volume --force --volume-id $VOLUME_ID --region eu-west-1
fi
aws ec2 wait volume-available --volume-ids $VOLUME_ID --region eu-west-1
if [ ! -e /dev/sdk ]
then
aws ec2 attach-volume --volume-id $VOLUME_ID --instance-id $INSTANCE_ID --device /dev/sdk --region eu-west-1
while [ ! -e /dev/sdk ]; do sleep 5; done
fi
if ! blkid /dev/sdk
then
mkfs.ext4 /dev/sdk
fi
mkdir -p /data
if ! grep -qs '/data' /proc/mounts
then
mount /dev/sdk /data
fi