Carl Willimott - Tech Blog: Resizing AWS Elastic Block Storage (EBS)

Resizing AWS Elastic Block Storage (EBS)

June 18, 2023

3 min read

Back

Recently I ran out of space on an EBS block in AWS which was attached to an ec2 instance. Historically, in this scenario you would need to create a snapshot of your EBS block, create a new block with a larger memory allocation and then restore. Fortunately you don't need to do that anymore, and can in most cases just increase the limit in the AWS console without too mich trouble.

Checking your available space

Once you have followed the steps in the AWS console and waited for a few minutes to complete, you may be temped to think that your job here is done. However, if you run the following command in your terminal you should see something like the following:

df -h

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.8G  7.8G     0 100% /

As you can see in my case, there is literally no space left. I actually decided to delete some log files from the /var/log directory in order to make a small amount of space, but this is optional. You could also clear some cache or remove some larger files with a command similar to this: find / -type f -size +50M. This will search for files which are larger than 50mb.

Utilising the new space

In order to use all that new space we just allocated, we need to grow our partition. I opted to go from 8gb to 12gb, if you run the following command in your terminal you should see something similar, the disk has 12gb, but our partition is still using 8gb.

lsblk

NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  12G  0 disk
└─xvda1 202:1    0   8G  0 part /

In order to grow your partition to the disk size, you can run this command (you may need to use sudo):

growpart /dev/xvda 1

Assuming everything worked for you, running the list-blocks command again, should give you the following:

lsblk

NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  12G  0 disk
└─xvda1 202:1    0  12G  0 part /

Summary

As you can see, it's fairly simple to resize your disk partition once you have increased the size of your storage. Now, obviously you may not want to use the entire disk size for your partition, so you use case may differ. But if like me, you just need to add some more space to your ec2 instance then this should work for you.

Useful links