How to increase the disk space of an AWS EC2 Ubuntu instance

Sometimes there could be a need to increase the disk space of your servers. It is always recommended to take a snapshot of the volume before you extend it or increase the disk size. Also, it is not advisable to decrease the disk size. Increasing the size of a volume does not increase the size of the partition, its file system must be extended. One needs to use a file system-specific command to resize the file system of the volume. 

In this article, we will increase the disk space of the boot volume (root partition) with the filesystem of type ext4 of Ubuntu 20.04 Server.

Pre-requisites

  1. AWS Account(Create if you don’t have one).
  2. An EC2 Ubuntu 20.04 server Instance(Click here to learn to create an EC2 Instance)

What will we do?

  1. Check current disk space.
  2. Modify the disk size of the root Volume.
  3. Extend the Filesystem.

Check current disk space

Let's first check the current disk space, information about available block devices using lsblk and blkid command.

df -h

lsblk

blkid

Current disk space

In the above screenshot, you can see that the current disk size of / (root) is 7.7 GBs(approx 8 GBs). We will try to increase the size of this disk.

Modify the disk size of the Volume

Go to the EC2 instance -- > Volume attached to the instance.

Check EC2 instance

Here you see the volume, click on "Actions" --> "Modify Volumes".

Modify EBS Volume

On the pop-up screen, specify the desired size. I have specified 30 GBs, earlier it was 8 GBs. Click on the "Modify" button, this will change the disk size to 30GBs.

Specify the required disk space

Confirm the modification by clicking on the "Yes" option.

Confirm modification

You will see that the disk has been modified.

Till this point we have just changed the disk size, it is not yet available for use. Now we need to extend the volume's file system to make use of the new storage capacity.

Successful EBS modification

Extend the Filesystem.

At this point, if you check the disk space you will see that the / volume still has 7.7 GBs.

df -h

To extend the volume size, get information about the block devices attached to your instance using the lsblk command

lsblk

Check the file system type, use the following command.

blkid

In our case, the file system is of type ext4 of the volume

Use the following command to extend the volume of the ext4 type.

sudo resize2fs /dev/xvda1

If you check the disk size this time, you will see that the disk has been extended and now we have 28 GBs(Approx 30 GBs) for / partition.

df -h

Increase the disk space of EC2 Ubuntu instance

If you see some other file system than ext4, visit the official documentation of AWS here.

Conclusion

In this article, we saw the steps to increase the disk size of the boot volume and extend the file system of type ext4. It is always advisable to take a snapshot of the disk before increasing its size, and it is also advisable that one should avoid decreasing the disk size.

Share this page:

3 Comment(s)