Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 8ae64c7

Browse files
committed
module/init-snippet-attach-ebs-volume: Manually make device name for attached EBS volume.
Due to Linux kernel and Distro changes, an attched EBS volume may not get the specified device name (Ref https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html). Hence logic following may break since specified device does not exist. This change uses Linux trick to manually setup (if it has not) the device name, so other logic can be static, without guessing which device is it.
1 parent 5d49e88 commit 8ae64c7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

modules/init-snippet-attach-ebs-volume/snippet.tpl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ${init_prefix}
33
export AWS_DEFAULT_REGION=${region}
44
VOLUME_ID=${volume_id}
55
INSTANCE_ID="$(ec2metadata --instance-id)"
6+
67
echo "${log_prefix} will attach $${VOLUME_ID} via the AWS API in ${region}"
78
while ! aws ec2 attach-volume \
89
--volume-id "$${VOLUME_ID}" \
@@ -11,8 +12,14 @@ while ! aws ec2 attach-volume \
1112
echo "Attaching command failed to run. Retrying."
1213
sleep '${wait_interval}'
1314
done
15+
echo "${log_prefix} $${VOLUME_ID} attached."
1416

15-
while ! ls '${device_path}'; do
16-
sleep '${wait_interval}'
17+
vol_id="$(echo "$${VOLUME_ID}" | tr -d '-')"
18+
while sleep '${wait_interval}'; [ ! -e /dev/disk/by-id/*-Amazon_Elastic_Block_Store_$${vol_id} ]; do
19+
dev_id="$(ls /dev/disk/by-id/*-Amazon_Elastic_Block_Store_$${vol_id} | head -1)"
20+
dev_name="/dev/$(readlink "$${dev_id}" | tr / '\n' | tail -1)"
21+
[ "$${dev_name}" == "${device_path}" ] || ln -s "$${dev_name}" "$${device_path}"
22+
break
1723
done
24+
1825
${init_suffix}

0 commit comments

Comments
 (0)