How to Increase EBS volume size in EC2 Instances Cover Image
How to Increase EBS volume size in EC2 Instances Cover Image

How to Increase EBS Volume Size in AWS EC2 Instances with Zero Downtime

Learn how to safely increase AWS EC2 EBS volume size with zero downtime in this step-by-step guide. Optimize your storage efficiently and keep your instance online.

Himanshu Gupta

11/5/20245 min read

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.

AWS Management Console
AWS Management Console
  • 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

Running EC2 Instances for which EBS volume size needs to update
Running EC2 Instances for which EBS volume size needs to update
  • At the EC2 dashboard, the Storage tab will list all the volumes attached to your EC2 instance. Select the root volume.

Display EBS volume attached with EC2 instance
Display EBS volume attached with EC2 instance
  • 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..

Modify Volume Option on AWS to change the size of EBS volume
Modify Volume Option on AWS to change the size of EBS volume
  • 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

Menu Options Change of Volume Configuration for EC2 Instance
Menu Options Change of Volume Configuration for EC2 Instance
  • 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.

Out put of f -hT command to check the size of EBS volume at EC2 Instance
Out put of f -hT command to check the size of EBS volume at EC2 Instance
  • 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.

Growpart Command Output on Instance Instance to increase EBS volume Size
Growpart Command Output on Instance Instance to increase EBS volume Size
  • 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.

LSBLK command output after growpart execution
LSBLK command output after growpart execution
  • 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

Resize Command Output on EC2 Instance
Resize Command Output on EC2 Instance
  • Again, to validate if we successfully expanded the file system, execute the command “df -h.” As you can see, the file system size has been extended to 20 GB.

validate the EBS volume size after process
validate the EBS volume size after process

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.