Skip to content

Commit 4766a96

Browse files
committed
Add resize.sh
1 parent 130f2e7 commit 4766a96

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

Supporting-material/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ test:
1010
lint:
1111
pylint --disable=R,C,W1203 example_src/*.py
1212

13-
all: install lint test
13+
14+
format:
15+
black **/*.py
16+
17+
all: install lint test

Supporting-material/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pylint
22
wikipedia
33
python-json-logger
4-
boto3
4+
boto3
5+
black

Supporting-material/resize.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# Specify the desired volume size in GiB as a command line argument. If not specified, default to 20 GiB.
4+
SIZE=${1:-20}
5+
6+
# Get the ID of the environment host Amazon EC2 instance.
7+
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
8+
9+
# Get the ID of the Amazon EBS volume associated with the instance.
10+
VOLUMEID=$(aws ec2 describe-instances \
11+
--instance-id $INSTANCEID \
12+
--query "Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId" \
13+
--output text)
14+
15+
# Resize the EBS volume.
16+
aws ec2 modify-volume --volume-id $VOLUMEID --size $SIZE
17+
18+
# Wait for the resize to finish.
19+
while [ \
20+
"$(aws ec2 describe-volumes-modifications \
21+
--volume-id $VOLUMEID \
22+
--filters Name=modification-state,Values="optimizing","completed" \
23+
--query "length(VolumesModifications)"\
24+
--output text)" != "1" ]; do
25+
sleep 1
26+
done
27+
28+
#Check if we're on an NVMe filesystem
29+
if [ $(readlink -f /dev/xvda) = "/dev/xvda" ]
30+
then
31+
# Rewrite the partition table so that the partition takes up all the space that it can.
32+
sudo growpart /dev/xvda 1
33+
34+
# Expand the size of the file system.
35+
# Check if we are on AL2
36+
STR=$(cat /etc/os-release)
37+
SUB="VERSION_ID=\"2\""
38+
if [[ "$STR" == *"$SUB"* ]]
39+
then
40+
sudo xfs_growfs -d /
41+
else
42+
sudo resize2fs /dev/xvda1
43+
fi
44+
45+
else
46+
# Rewrite the partition table so that the partition takes up all the space that it can.
47+
sudo growpart /dev/nvme0n1 1
48+
49+
# Expand the size of the file system.
50+
# Check if we're on AL2
51+
STR=$(cat /etc/os-release)
52+
SUB="VERSION_ID=\"2\""
53+
if [[ "$STR" == *"$SUB"* ]]
54+
then
55+
sudo xfs_growfs -d /
56+
else
57+
sudo resize2fs /dev/nvme0n1p1
58+
fi
59+
fi

0 commit comments

Comments
 (0)