How to Increase AWS EBS Volume Size on EC2 Instances with Zero Downtime
Follow our step-by-step guide to expand an EBS volume efficiently without affecting uptime.
In this guide, we’ll explore how to increase EBS volume size in AWS EC2 Linux or Ubuntu instances without any downtime.
If you’re using AWS EC2 instances, which are among the most popular cloud servers for various operating systems, defining AWS EBS volume size is an essential step for persistent storage. However, as application logs and system logs accumulate, you may encounter insufficient memory in your root EBS volume. Fortunately, AWS EBS provides a way to resize EBS storage dynamically, allowing you to adjust your storage needs on the go.
What is AWS EBS Volume?
AWS Elastic Block Store (EBS) is a scalable, cloud-based block storage solution for EC2 instances that securely retains data across sessions. You can think of it as a virtual hard drive for EC2 on the cloud, offering flexible storage that can grow with your needs. Each EBS volume type caters to different workload requirements and can be attached or detached as needed.
EBS volumes support creating file systems, running databases, saving application files, and mounting to one or multiple EC2 instances.
They are highly durable and available, stored across multiple AWS Availability Zones.
AWS offers an easy way to increase EBS volume size without rebooting your EC2 instance — but note that shrinking the volume is not supported.
You can take EBS snapshots to back up your data and even use them to launch new EC2 instances across AWS regions.
Steps to Increase EBS Volume Size from the AWS Console
Let’s go over the step-by-step process for modifying EBS volume size without stopping or detaching the EC2 instance:
- Log in to the AWS Console: Open the AWS Management Console, navigate to EC2, and choose the instance you want to resize.
At EC2 Dashboard, select Instances from the left navigation panel. It will show all available instances in your account. You can also see the instance’s status either running or stopped.
Select the EC2 instance whose root volume size you want to increase, and it will open up the window below with all relevant instance configurations. Importantly, you don’t need to stop that EC2 instance or detach the volume from the instance
- At the EC2 dashboard, the Storage tab will list all the volumes attached to your EC2 instance. Select the root volume.
Once you select the volume, AWS will open up the EBS Dashboard with your volume filtered by default.
To modify the volume’s size, select the EBS volume and click on the Action dropdown in the upper corner. Select Modify Volume from the pop-up menu.
- This routes to a new window that displays your volume’s current configurations and also offers the options to update the volume type and volume size
For this article, let’s update the Volume Size from 8 GB to 20 GB under the size label and select Modify.
Again, select Modify on the confirmation dialog. Changing the volume size might take some time, depending on the amount of data in your volume.
Steps to Increase EBS Volume Size from the AWS Console
Modifying the volume will not necessarily increase the EC2 Linux file system or server’s partition size. Increasing the partition size can be done by logging into the EC2 instance via SSH, which does not require you to stop or reboot the instance to take effect.
Log in to EC2 via SSH: Use your SSH key pair to access the instance.
After successful login, use the command df -hT, to check the file system in your instance. The below output shows that the instance has a boot volume with an ext4 file system and still using 8 GB of data even though we have increased the volume size to 20 GB.
- Furthermore, you can use the command lsblk to check the block storage information connected with your instance
As you can see, root volume /dev/xvda has a partition /dev/xvda1
While the size of root volume is 20GB, but partition size is still at 7.9GB which we are going to extend
Now, execute the command “growpart /dev/xvda 1” at the terminal.
This command will extend the partition size of the root volume as the root volume has 20GB of size, but the partition still uses 8 GB of space.
To validate if the partition size has extended successfully, execute the command “lsblk.”
As you can see, the volume’s partition size is now at 20GB.
- Once we successfully increase the partition size, last but not least, we also need to expand the file system.
If you are using an ext2, ext3, or ext4 filesystem,
execute the command “sudo resize2fs /dev/xvda1“
If you are using the XFS filesystem,
run the command “sudo xfs_grows /dev/xvda1“
- Again, to validate if we successfully expanded the file system, execute the command “df -h”, which shows file system size has been extended to 20 GB.
Best Practices for Managing AWS EBS Volumes
Increasing AWS EBS volumes in EC2 instances is a straightforward process that ensures persistent storage. However, consider these best practices to maximize efficiency:
Backup EBS with Snapshots: Before making changes, take an EBS snapshot to safeguard your data.
Monitor EBS and EC2 Utilization: Regularly check storage and memory usage to avoid unexpected resource constraints.
Optimize Volume Size Based on Needs: Adjust the volume size only as needed to keep storage costs manageable
Conclusion
Scaling storage for AWS EC2 instances by increasing EBS volume size can be a straightforward task when following the correct steps. This guide demonstrated how to achieve a seamless EBS volume resize, ensuring continuous availability without any downtime. By properly expanding both the EBS volume and filesystem, you can dynamically manage storage to meet growing application needs.
Hi, I’m Himanshu Gupta — here to help you learn AWS Serverless, Cloud Computing, Programming, and System Design!
🚀 Want to build efficient, scalable, and resilient applications without the stress? I share easy-to-follow tutorials and insights that help you navigate the cloud and coding confidently. Join my community by subscribing to get posts straight to your inbox!
Thanks for reading, and see you in the next one!
Subscribe to my newsletter
Read articles from Himanshu Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Himanshu Gupta
Himanshu Gupta
Hi, I’m Himanshu Gupta – here to make AWS, Cloud Computing, Serverless, Programming, and System Design approachable for everyone!