Amazon EC2 is one of the most preferred platforms used to provision web servers due to its flexibility. You can launch a web server with limited resources, and later you can scale your web server’s resources when necessary. This blog explains the procedure of increasing the disk space on an EC2 instance using the following steps.

  • Backup EBS volume
  • Increase EBS volume size
  • Increase partition size
  • Extend filesystem
    • Extend ext4 filesystem
    • Extend XFS filesystem

Backup EBS volume

Before increasing the size of the EBS volume, it is always a good practice to have a backup of the EBS volume; in case something goes wrong, you have the backup of the EBS volume, and you can restore your data. Visit the following link to login to the AWS management console.

https://console.aws.amazon.com

After logging into the AWS management console, go to the EC2 services.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/1-50.jpg" data-lazy- height="254" src="data:image/svg xml,” width=”671″>

Before starting, make sure you use the new EC2 console because the old EC2 console may differ slightly. In order to switch to the new EC2 console, turn on the ‘New EC2 Experience’ button on the top left corner of the EC2 service.

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/2-48.jpg" height="253" src="data:image/svg xml,” width=”223″>

After switching to the new EC2 console, select the ‘Volumes’ option from the left side panel under ‘Elastic Block Store’.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/3-47.jpg" data-lazy- height="402" src="data:image/svg xml,” width=”227″>

It will display all the available EBS volumes there. Select the EBS volume of the instance you want to resize and click on the ‘Action’ button on top.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/4-44.jpg" data-lazy- height="295" src="data:image/svg xml,” width=”580″>

Select the ‘Create Snapshot’ option from the dropdown menu, and it will ask for the description for the snapshot. Add a description and click on the ‘Create Snapshot’ button at the bottom right corner.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/5-43.jpg" data-lazy- height="395" src="data:image/svg xml,” width=”1134″>

Select the ‘Snapshot’ option from the left side panel under the ‘Elastic Block Store’ section, and it will show a snapshot being created there.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/6-39.jpg" data-lazy- height="321" src="data:image/svg xml,” width=”650″>

Increase EBS Volume size

After taking the snapshot of the EBS volume, the first step is to increase the EBS volume size of your EC2 instance from the EC2 console. Select the ‘Volumes’ option from the left side panel under ‘Elastic Block Store’.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/7-38.jpg" data-lazy- height="402" src="data:image/svg xml,” width=”227″>

It will display all the available EBS volumes there. Select the EBS volume of the instance you want to resize and click on the ‘Action’ button on top.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/8-32.jpg" data-lazy- height="308" src="data:image/svg xml,” width=”471″>

From the dropdown list, select the ‘Modify Volume’ option, displaying a pop-up.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/9-28.jpg" data-lazy- height="438" src="data:image/svg xml,” width=”702″>

From the pop-up, it is clear that the volume type can also be changed along with the volume size. The size field shows the current size of the EBS volume, i.e., 8 GB. Increase the size of the EBS volume to the desired value and clicks on modify.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/10-26.jpg" data-lazy- height="436" src="data:image/svg xml,” width=”698″>

After clicking on the ‘Modify’ button, a new pop-up appears, asking for your consent to apply the changes.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/11-22.jpg" data-lazy- height="314" src="data:image/svg xml,” width=”699″>

Click on the ‘Yes’ button, and it will start modifying the EBS volume. It can take some time to modify the volume. Check the state of volume and wait for the optimization to complete.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/12-18.jpg" data-lazy- height="87" src="data:image/svg xml,” width=”626″>

Increase partition size

After increasing the EBS volume size, connect to your instance over SSH to check the EBS volume size.

Now use the df command to list all the filesystems mounted on your disk.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/13-16.jpg" data-lazy- height="249" src="data:image/svg xml,” width=”644″>

The root filesystem size (/dev/xvda1) is still 8 GB, and its type is ext4. Now use the lsblk command in the terminal to check whether the disk has an extended partition.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/14-15.jpg" data-lazy- height="166" src="data:image/svg xml,” width=”643″>

The root volume (/dev/xvda) has a partition (/dev/xvda1). The size of the volume is 20 GB, but the size of the partition is still 8 GB. Now use the growpart command in the terminal to extend the partition size.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/19-8.jpg" data-lazy- height="249" src="data:image/svg xml,” width=”596″>

Again use the lsblk command in the terminal to verify if the partitions size extended.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/16-13.jpg" data-lazy- height="164" src="data:image/svg xml,” width=”556″>

Extent filesystem

So far, the volume size and the partition size have been extended. Use the df command to check if the root filesystem has been extended or not.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/17-9.jpg" data-lazy- height="265" src="data:image/svg xml,” width=”596″>

The size of the root filesystem is still 8 GB, and it needs to be extended. To extend different types of filesystems, different commands are used.

Extend ext4 filesystem

In order to extend an ext4 filesystem, the resize2fs command is used.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/18-9.jpg" data-lazy- height="147" src="data:image/svg xml,” width=”596″>

Now again, list all the filesystems on your EC2 instance using the df command.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/19-9.jpg" data-lazy- height="249" src="data:image/svg xml,” width=”596″>

After running the resize2fs command, the size of the filesystem is increased.

Extend XFS filesystem

To increase the XFS filesystem size, the xfs_growfs command is used. If the XFS tools are not installed on your EC2 instance, use the following command to install.

After installing the XFS tool, extend the XFS filesystem using the xfs_growfs command.

Conclusion

As a cloud solution architect or system administrator, limited resource provisioning on the cloud initially and later scaling the resources with increased traffic is a good practice. Almost all cloud service providers provide the ability to scale the resources when needed. This blog explains the step-by-step procedure of increasing the disk space on an AWS EC2 instance.

About the author

<img data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/Zain-150×150.jpg" height="112" src="data:image/svg xml,” width=”112″>

Zain Abideen

A DevOps Engineer with expertise in provisioning and managing servers on AWS and Software delivery lifecycle (SDLC) automation. I’m from Gujranwala, Pakistan and currently working as a DevOps engineer.