How to extend a root FS EBS volume of AWS EC2 using CLI

 

Query all running ec2 instances and with an instance name 'main'  for details of Block Devices or volume ids

Query only running ec2 instance for the Block Devices or volume ids

aws ec2 describe-instances --filters Name=instance-state-name,Values=running Name=tag:Name,Values='main' --query "Reservations[*].Instances[*].BlockDeviceMappings[*].Ebs.VolumeId" --output text


Check the volume properties

aws ec2 describe-volumes --volume-ids <id>


Modify a Volume

aws ec2 modify-volume --volume-id <id> --size <final size>


Once this is done follow the below steps to extend the

lsblk              – to check which is the root fs

df -h             – to check the fs usage

sudo growpart /dev/xvda 1                 - To extend the partition size if the partition is 1st partition

sudo mount | grep /dev/xvda1          To check the fs type


If fs Type is ext3 or ext4 then

sudo resize2fs /dev/xvda1

Or if fs type is xfs

sudo xfs_growfs /dev/xvda1


Comments

Popular posts from this blog

Install and configure AWS CLI and kubectl in a EC2 Client machine for AWS EKS

Deploying the custom docker image as POD/container in kubernetes and creating LB to access the services

Building a custom docker container image and pushing it to Docker Hub – Docker Compose