Skip to content

Commit

Permalink
Add resize.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
SudKul committed Nov 30, 2021
1 parent 130f2e7 commit 4766a96
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Supporting-material/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ test:
lint:
pylint --disable=R,C,W1203 example_src/*.py

all: install lint test

format:
black **/*.py

all: install lint test
3 changes: 2 additions & 1 deletion Supporting-material/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pylint
wikipedia
python-json-logger
boto3
boto3
black
59 changes: 59 additions & 0 deletions Supporting-material/resize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Specify the desired volume size in GiB as a command line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}

# Get the ID of the environment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)

# Get the ID of the Amazon EBS volume associated with the instance.
VOLUMEID=$(aws ec2 describe-instances \
--instance-id $INSTANCEID \
--query "Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId" \
--output text)

# Resize the EBS volume.
aws ec2 modify-volume --volume-id $VOLUMEID --size $SIZE

# Wait for the resize to finish.
while [ \
"$(aws ec2 describe-volumes-modifications \
--volume-id $VOLUMEID \
--filters Name=modification-state,Values="optimizing","completed" \
--query "length(VolumesModifications)"\
--output text)" != "1" ]; do
sleep 1
done

#Check if we're on an NVMe filesystem
if [ $(readlink -f /dev/xvda) = "/dev/xvda" ]
then
# Rewrite the partition table so that the partition takes up all the space that it can.
sudo growpart /dev/xvda 1

# Expand the size of the file system.
# Check if we are on AL2
STR=$(cat /etc/os-release)
SUB="VERSION_ID=\"2\""
if [[ "$STR" == *"$SUB"* ]]
then
sudo xfs_growfs -d /
else
sudo resize2fs /dev/xvda1
fi

else
# Rewrite the partition table so that the partition takes up all the space that it can.
sudo growpart /dev/nvme0n1 1

# Expand the size of the file system.
# Check if we're on AL2
STR=$(cat /etc/os-release)
SUB="VERSION_ID=\"2\""
if [[ "$STR" == *"$SUB"* ]]
then
sudo xfs_growfs -d /
else
sudo resize2fs /dev/nvme0n1p1
fi
fi

0 comments on commit 4766a96

Please sign in to comment.