Forked from wongcyrus/cloud9 resize command with volume size 60 GB
Last active
December 24, 2023 06:00
-
-
Save jsamuel1/0fccea56fd96c07000ad9de784ab1ab3 to your computer and use it in GitHub Desktop.
Cloud9 Disk Resize
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
curl -s https://gist.githubusercontent.com/wongcyrus/a4e726b961260395efa7811cab0b4516/raw/6a045f51acb2338bb2149024a28621db2abfcaab/resize.sh | bash /dev/stdin 60 |
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
#!/bin/bash | |
# Specify the desired volume size in GiB as a command line argument. If not specified, default to 20 GiB. | |
SIZE=${1:-60} | |
# Get the ID of the environment host Amazon EC2 instance. | |
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id) | |
REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/\(.*\)[a-z]/\1/') | |
# 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 \ | |
--region $REGION) | |
# 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 [[ -e "/dev/xvda" && $(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're 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment