When you start an EC2 instance, you define an EBS volume size. However, you may need more disk space later for some reason. In this blog post, I will demonstrate an example on how you can increase the root volume size of an EC2 Linux instance.
There are three components of this operation:
- AWS Elastic Block Storage (EBS) volumes attached as block devices to our EC2 instance such as
- Partions on block devices, such as
- Mounted filesystem on the operating system such as
"/dev/xvda1" mounted on "/".
How to check block devices and filesystem
First of all let’s connect to our EC2 instance using SSH. For demonstration, I will be using a t2.micro instance backed by 8GB EBS initially and running Ubuntu 16.04LTS.
Once we connect, let’s list block devices available:
Here we see that, there is 8G size on xvda block device and all 8GB is allocated to xvda1 partition as we expect.
Let’s display the amount of disk space used and available on Linux filesystem.
As can be seen, we have a 7.7G disk space available on
/dev/xvda1 which we will increase by 2G. AWS allocated remaining nearly 0.3G space to
One more thing to go, we need to determine whether the disk use
xfs file system:
We checked initial state of our EC2 instance; let’s continue by resizing the volume using AWS Management Console.
Modifying Volume on AWS Management Console
I will show you how to modify the root volume using AWS Management Console. On our EC2 dashboard, click on
ELASTIC BLOCK STORE section on the left. Here, we need to select the volume attached to our instance and click on
Modify from the
Actions. You can see the screenshot below.
Simply, increase the size in the modal window opened. In my case I will resize it to 10G.
After clicking on Modify, AWS will display an approval window to avoid unintended actions, click
Yes on the modal. A success message will be displayed which you can ignore by clicking
After getting volume increase request, AWS will resize the EBS volume in a few seconds. You can see the process finished after clicking refresh button after a while on the top-right.
As our volume is resized. However, now we need to extend OS file system for it to take effect.
Extending OS Filesystem (ext3, ext4)
Remember that we listed block devices and saw that all 8GB of xvda was allocated on xvda1. Now, let’s display after resizing the volume and see what it shows us:
Please, see how the size of xvda increased from 8G to 10G. Unfortunately, only 8G is used by
xvda1. We need to allocate all 10G to
We do this using growpart as our filesystem is
We can confirm that all the storage is allocated to
xvda1 by listing block storages again:
We increased block storage, but we also need to increase filesystem:
Let’s confirm it by redisplaying filesystem disk space usage.
As we can see, the size of
/dev/xvda1 became 9.7G with a net 2G increase. Now, our resizing of EBS volume is complete.
In the lifetime of our EBS backed EC2 instances, we may need to increase root or other volumes of our instances. In this blog post, I tried to demonstrate how you can do this on an Ubuntu instance with ext4 filesystem. For ext3, the process is also the same. If your instance is running Amazon Linux or Centos with ext3 or ext4 filesystem; you can apply the same process again.
If your filesystem is
xfs, you will need to do the filesystem extension part using
xfsprog. You can find the details in AWS documentation in the references section.
Thanks for reading!