Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
If you should resize an EBS quantity in AWS, you are able to do so utilizing bash
.
bash
fileCreate a bash file referred to as resize.sh
:
#!/bin/bash
SIZE=${1:-20}
INSTANCEID=$(curl http://169.254.169.254/newest/meta-data/instance-id)
REGION=$(curl -s http://169.254.169.254/newest/meta-data/placement/availability-zone | sed 's/(.*)[a-z]/1/')
VOLUMEID=$(aws ec2 describe-instances
--instance-id $INSTANCEID
--query "Reservations[0].Situations[0].BlockDeviceMappings[0].Ebs.VolumeId"
--output textual content
--region $REGION)
aws ec2 modify-volume --volume-id $VOLUMEID --size $SIZE
whereas [
"$(aws ec2 describe-volumes-modifications
--volume-id $VOLUMEID
--filters Name=modification-state,Values="optimizing","completed"
--query "length(VolumesModifications)"
--output text)" != "1" ]; do
sleep 1
finished
if [[ -e "/dev/xvda" && $(readlink -f /dev/xvda) = "/dev/xvda" ]]
then
sudo growpart /dev/xvda 1
STR=$(cat /and so forth/os-release)
SUB="VERSION_ID="2""
if [[ "$STR" == *"$SUB"* ]]
then
sudo xfs_growfs -d /
else
sudo resize2fs /dev/xvda1
fi
else
sudo growpart /dev/nvme0n1 1
STR=$(cat /and so forth/os-release)
SUB="VERSION_ID="2""
if [[ "$STR" == *"$SUB"* ]]
then
sudo xfs_growfs -d /
else
sudo resize2fs /dev/nvme0n1p1
fi
fi
bash
file specifying the brand new measurementNow that you’ve got the bash file, you possibly can run the bash
file together with specifying the brand new measurement of the specified quantity:
bash resize.sh 50
The above command will try and resize the EBS quantity to 50GB
.
In its place execution technique, you can even change the bash
file to be executable. This can let you name it immediately with out having to go bash
to the previous command.
First you should make the script and executable:
chmod +x resize.sh
Now you possibly can merely run the file with the parameters required:
./resize.sh 20
That is attainable as a result of the primary line of the file specifies the hashbang required to execute the code:
#!/bin/bash