Resize your AWS EC2’s EBS Volume Size with ZERO DOWNTIME

Steps

1. Go to EC2 dashboard and search the instance you want to increase. Click the instance and check the description below

2. Click root device then EBS ID and you will be redirected to EBS page.

3. Click Actions button then Modify Volume button. Change the size to your desired size. (ex. 250 to 300). Click Modify button.

4. Wait for the State to finish optimizing before applying the commands in next steps.

5. SSH into the instance and check the List Block Services that attach to EC2 (check if its nvme0n1 (Ubuntu) or xvda (Amazon Linux)

lsblk

Ubuntu

Ubuntu lsblk

Amazon Linux

Amazon Linux lsblk

As you can see xvda1 is still 8 gb partition part and nvme0n1p1 is still 250G (not 300G) and there are no other partitions on the volume. Let’s use “growpart” to resize 8G partition up to 16G / 250G to 300G:

6. Use growpart command to resize the partition.

Ubuntu

sudo growpart /dev/nvme0n1 1 Ubuntu - sudo growpart /dev/nvme0n1 1

sudo growpart /dev/nvme0n1 1

Amazon Linux

sudo growpart /dev/xvda 1 Amazon Linux - sudo growpart /dev/xvda 1

Check the changes on your partitions using lsblk and df -h commands. You can see /dev/xvda1 is now 16G and 300G for /dev/nvme0n1

7. Resize file system to grow all the way to fully use the new partition space. Check the column (Size, Used, Avail) then df -h again after resize2fs command to see the changes.

Ubuntu

#Check filesystem command df -h #resize filesystem sudo resize2fs /dev/nvme0n1p1 #check again after resizing df -h

Ubuntu resize2fs

Amazon Linux

#Check filesystem command df -h #resize filesystem sudo resize2fs /dev/xvda1 #IF resize2fs doesn't work do this instead sudo xfs_growsfs /dev/xvda1 #check again after resizing df -h

Amazon Linux xfs_growfs

Bookmark this for your future reference.

Congratulations you successfully resize your EC2’s EBS volume with zero downtime.