This article will teach us how to increase EBS volume size in AWS EC2 Linux or Ubuntu instances without downtime.
If you are familiar with AWS EC2 instances, the most preferred Webservers of any OS type on the cloud, you need to define the EBS volume when you launch the EC2 instance to provide persistent storage to the server.
However, you may have encountered insufficient memory issues in your root EBS volumes because application logs, system logs, etc., rapidly fill up your root volume.
AWS provides an easy way to increase the EBS volume size for Linux or Ubuntu servers with zero downtime.
In this blog post, we will go through the process resize the EBS volume size in AWS for EC2 Instances. Increasing the EBS volume size is a two-step process:
- Modify the EBS Volume size without rebooting\stopping EC2 Instance from AWS Console, CLI, or SDK
- Increase the Linux’s disk Partition size and expand to the file system
What is AWS EBS Volume?
An AWS EBS (Elastic Block Store), often mistakenly referred to as Elastic Block Storage, is a cloud-based block storage solution for AWS EC2 instances to save the instance’s persistent data. You can think of EBS volume as a Physical hard disk for your EC2 instances on the cloud.
- EBS volumes are flexible, durable, and highly available storage solutions as AWS EBS stores data across multiple Availability Zones in an AWS Region.
- AWS EBS offers multiple types of volume suited according to your application workload and performance.
- EBS allows creating a file system on top of the volume and lets you run your database application, save your application files or run your applications.
- AWS offers the flexibility to mount single or multiple EBS volumes to a single instance.
- AWS allows you to resize the EBS volume size without downtime or reboot your EC2 instances.
- But AWS does not allow you to shrink the EBS volume size from the original size.
- You can take EBS’s snapshot and use the same image to launch a new EC2 Instance in multiple AWS regions.
Let’s dig into the steps to increase the AWS EBS root volume in AWS EC2 Linux instances.
Before starting the process, take a snapshot of your EBS volume before extending the volume size; if something goes wrong, you can use your backup to recover your data or launch a new EC2 instance.
Steps to increase EBS Volume Size from AWS Console
- Log In to AWS Management Console, Search for EC2 service and select the same. Or, if you recently visited the EC2 service, it should be displayed on your console home.
- 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 volume 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 Volumen 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.
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.
Steps to Increase the AWS EBS File system for EC2 Linux instances
- Log in to the AWS EC2 instance via SSH using the key-pair created during launching and the public IP address or DNS name created.
- 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.” As you can see, the file system size has been extended to 20 GB.
Since this is a common scenario where your instances used up all your root volume spaces, using an EC2 detailed monitoring tool to monitor the EC2 Memory should be a best practice.
This article teaches you how to increase the EBS volume size without rebooting or stopping the AWS EC2 instances, offering zero downtime to your application.
Furthermore, it provides a brief introduction of various concepts related to it & helps the users understand them better to set up the notifications.
Feel free to provide feedback at [email protected].
Do not forget to subscribe to our newsletter for upcoming posts and hands-on exercises.