How to Extend EBS disk space of AWS EC2 Instance

How to Extend EBS disk space of AWS EC2 Instance

July 6, 2020 / Nirav Shah

Extend Disk space with ZERO Downtime !! Yes, you read it right.

Sometimes clients ask our AWS Team that how they can extend disk space of AWS EC2 Linux/Ubuntu Instance with zero downtime. So let us come to the solution, a secret.

But first I highly recommend you to please take AMI backup of the instance or snapshot of the volume. Just for safety purposes.

In AWS EC2, instances contain block-level storage that is EBS. Sounds familiar right !! So basically EBS is like a physical Hard Drive and it’s attached to your running instance . EBS Volumes are highly flexible, you can dynamically increase size, change Volume type and modify the provisioned IOPS.

Steps To extend ebs volume aws

Now let’s see how to extend disk space of your running instance.

Step 1

Login to your AWS account. Go to Services and then navigate to EC2 service. Select the EC2 Instance ,navigate to Block Devices and select the Block device to be modified.

AWS account launch instance login

Step 2

Click on actions and go to modify volume.

AWS instance modify volume

step 3

Increase the size of the Volume. Here I can extended the volume size is to15gb.

Increase the size of the Volume

step 4

And click on “yes” button

Modify volume to increase size of EBS volume

step 5

Wait for a minute and Refresh the page so you will get the new size of volume

Extend EBS disk space of AWS EC2 Instance

step 6

Log in to your instance via SSH or Putty and apply the following command

$df -h

Now you can see the size is still showing 8GB

Extend EBS disk space of AWS EC2 Instance

step 7

Here you can see the EBS size is already increase but the size of the partition is still showing 8 GB

$lsbsk

Extend EBS disk space of AWS EC2 Instance

step 8

Use the following command to increase the partition size.

$ growpart /dev/xvda 1

Extend EBS disk space of AWS EC2 Instance

step 9

Now run “lsblk” again and check the partition size. You can see the size of the partition is increased to 15 GB now. But in “df -h” the size is still 8 GB. This is due to the reason that you have extended your EBS volume and also increased your Partition Size but File System on the Volume is still not modified.

Extend EBS disk space of AWS EC2 Instance

step 10

Now time to extend file system

$ file -s /dev/xvd*         -     	(This command works for T2 based Instances)
$file -s /dev/nvme*     -     	(This Command works for Nitro Based Instances)

The system may be EXT2, EXT3, EXT4 or XFS. In my case here the file system is XFS for /dev/xvda1

Extend EBS disk space of AWS EC2 Instance

use below command to extend XFS file system on the volume.

$ sudo xfs_growfs -d /

Note: Using / in the above command as /dev/xvda1 is mounted on / , you can see this my df -h or lsblk command. If in case /dev/xvda1 would have mounted on /data, we need to use command the following command.

$ sudo xfs_growfs -d /data

Extend EBS disk space of AWS EC2 Instance

Now apply df -h and you can see the size partition is extended now

Extend EBS disk space of AWS EC2 Instance

Also Read :

1. How to Setup Multiple Websites in a Single AWS Instance?

2.Learn more expand the Amazon EBS root volume- AWS documents

 

Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let Us Talk About Your AWS Development Requirements

    Have queries about your AWS project ideas and concepts? Please drop in your project details to discuss with our AWS experts, professionals and consultants.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project