Extend disk space of AWS EC2 Linux Instance

In this tutorial , we will learn how to extend disk space of AWS EC2 Linux Instance with zero downtime.

Before Starting I would recommend you to take AMI backup of the instance or Snapshot of the Volume.Taking backup is recommended for safety purpose.

Recommended Article : AWS EC2 AMI backup and restore

Also Read : Extend disk space of AWS EC2 Windows Instance

In AWS EC2 Instance ,EBS Volumes are used as disk storage.AWS EBS Volume is a durable and block-level storage device that is attached to an EC2 Instance.It is used like a physical Hard Drive,but one thing that other physical Hard Drive do not have and EBS Volume have is its flexibility.EBS Volumes are highly flexible,you can dynamically increase size, change Volume type and modify the provisioned IOPS capacity on live Server.

Block-Level Storage are nothing but blocks of storage created on SAN(Storage Area Network) and each block are treated as individual hard drive.

Let’s start to extend disk space of AWS EC2 Linux 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.

Note : If you have multiple EBS Volumes attached to your Instance and want to see which Block Device you have to choose , you can find this by following command, by login into your Linux Instance.

 $ df -h

df -h shows here we have only one EBS Volume attached i.e /dev/xvda with one partition /dev/xvda1.If you have multiple EBS Volumes attached such as /dev/xvdb , /dev/xvdc etc. that can be also seen by “dh -h” command only .So use this command to find out the Block device name so that you can select the same on AWS console to resize.

Step 2 – As soon as you  click on the EBS ID looks like vol-xxxxxxxxxxxxxx as shown in screenshot in Step 1, it will redirect you to the following screen.Select Actions and click on Modify Volume.

Step 3– Increase the size of the Volume.Here, current Size is 8 GB and we are extending it to 15 GB.

Step 4– Click on Yes to confirm the modification.

Step 5 – Refresh the page and you will see the size of the volume is modified.

Step 6 – Login to your Linux Box and enter the following command.

  $df -h

You can see the size of the partition is still showing 8 GB.

Following command will give you more clarity.

$ lsblk

Here you can see the size of the EBS Volume is already increased to 15 GB , but the size of the partition is still showing 8 GB.

Step 7 – Use the following command to increase the Partition size.

  $ growpart /dev/xvda 1

Now run “lsblk”  again and check the 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 extend your EBS volume and also increased your Parition Size but File System on the Volume is still not modified.

Step 8 – Extend the File System.

Check your File system by following commands

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

 $file -s /dev/nvme*              (This Command works for Natro Based Instances)

As a result , the file system may be EXT2,EXT3,EXT4 or XFS.

See below example , here the file system is XFS for /dev/xvda1.

    i)Extend XFS File System.

use following 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

Now run df -h again. You can see the size of the partition is extended now.

   ii) Extend EXT2, EXT3 or EXT4 File Systems.

Use resize2fs command to extend EX2,EXT3,EXT4 files systems on each Volume


         $ sudo resize2fs /dev/xvda1

         $ sudo resize2fs /dev/xvdf1

Now run dh -h command again and you can see the File System is modified now.

I hope you enjoyed this tutorial and learned Extend disk space of AWS EC2 Linux Instance with zero downtime. If you think this is really helpful, please do share my website https://devopsmyway.com to others as well. Please also share your valuable feedback, comment or any query in the comment box.I will really happy to resolve your queries.

Thank You

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter


You may also like…

2 Responses

  1. A says:

    Thanks! You saved me a lot of time!

Leave a Reply

Your email address will not be published. Required fields are marked *