Expanding an EBS disk on Ubuntu 20.04 in AWS

Carl Hayes
4 min readMar 19, 2022

--

Let’s pretend you are new to AWS and asked by your manager to expand the disk size of one of the production servers. If you’re a cloud engineer, system administrator, etc.. You may find yourself in this predicament more often than you can count (possibly). Therefore, I want to quickly walk you through how to complete this– within 5 mins.

Modify disk size of the volume

Locate the instance ID of the affect instance & copy

In the menu located on the left, under “Elastic Block Store (EBS), then select “volumes”.

Enter the instance ID in the search column, and locate the associated volume.

Prior to conducting any changes, please, please, please…. Take a snapshot!

This can be done by right clicking the volume and selecting Create Snapshot.

  • Give it a description, label it whatever you want.
  • After the snapshot is finished, give it a name.
  • Select “volumes” again, under the “EBS” field on the left. Then find the referenced volume and right click to “modify volume”.
  • Here you are able to modify the contents in the Size field to the desired EBS size. After your change has been made, please select Modify to submit the update.
  • There will be instructions associated with how to modify/extend the OS file system on the volume. As it stands with Linux, simply acquiring more disk space from AWS doesn’t quite cut the mustard. So with that being said, we are going to have to log into our server and leverage some commands, but if this is your first time doing such a task– please select the “Learn more about resizing” link (depending if you use Linux or Windows).

For your viewing pleasure I’ll leave the links provided below:

Linux: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html

Windows: https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/recognize-expanded-volume-windows.html

Now, if you view the EBS volume, it should be reflective of the change you initiated.

Extending the filesystem

Disclaimer: Engaging in this part means you have already researched the file system-specific commands to extend the file system to a larger size.

Next we will want to access the server to verify the disk space.

  1. ssh root @instanceip
  2. df -h ; this command will provide insight on disk space. As we currently see, the volume still has GB.
  3. To properly check if the volume has a partition that needs to be extended, type lsblk to display info block devices attached to your instance/server.
  4. If we are interested in checking file system type, enter blkid. From the command you can see we have an ext4 type.

I ran into an issue and simply running sudo resize2fs /dev/xvda1 did not get the job done, so I simply rebooted the instance from the command line by sudo reboot and the file system extension worked successfully.

However, I checked the documentation, because my goal was to extend the filesystem without having to reboot the instance.

Lesson Learned

After scanning the AWS EC2 documentation, I found what I was looking for.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html

It turns out that my disk had a partition and prior to running the resize2fs command mentioned above, I needed to use the growpart command to extend the partition.

Only after running the growpart command would I be able to leverage the resize2fs command to properly extend the filesystem while the instance was running.

There are more ways to extend a volume, but the purpose was to give you a reference point to start. Hopefully, you found this helpful.

Sincerely,

Carlintheclouds

--

--

Carl Hayes
Carl Hayes

Written by Carl Hayes

An avid techie, hip-hop music enthusiast and photo taker. If it involves a terminal, there is a high chance you will find me in it.