Here’s the scenario: You want to add storage space to a volume (drive) attached to an EC2 Debian instance.
There are three steps. First, increasing the volume size in the AWS Management Console. Second, the partition needs to be expanded in Linux, and finally, the Linux filesystem needs to register the updated available space.
TL;DR
Here are the three steps in brief:
- Navigate to the AWS console, locate the volume to resize, select Actions -> Modify volume, enter the new target size, and click Modify.
- On the Linux instance, type lsblk to identify the volume to expand and then type sudo growpart [device] [partition] to expand it. In my use case it is: sudo growpart /dev/nvme0n1 1
- Then, on the Linux instance, type sudo resize2fs [device] to expand the filesystem. In my use case, it is sudo resize2fs /dev/nvme0n1p1
That’s all there is to it. For a full walkthrough of the above steps, continue below.
Step 1 / 3 – Increase Volume Size in the AWS Management Console
Sign in to the AWS Management Console and navigate to EC2. You can go directly to the EBS volume, but I prefer to find the target instance first, and then click the link to the relevant volume in the Storage tab.
You’ll likely see a confirmation modal, click Modify to proceed.
Step 2 / 3 – Expand the Partition
Connect to your Linux instance with a terminal, then type lsblk to list details about block devices (volumes). It may look like this. Note: our “15G” shows up as “14.9G” due to the small amount used by the boot partition (127M).
This shows that the primary partition (nvme0n1p1) has 14.9G in size, but the total available partition space is 16G.
To grow the partition, type sudo growpart /dev/nvme0n1 1. The error displayed when you execute this without sufficient permissions is a “not found” error, which isn’t easily associated with insufficient permissions. In the screenshot below I also ran this without sudo so you can see the error displayed when you try to execute this without sufficient permissions.
Execute lsblk again to see the expanded partition. Presto!
Step 3 / 3 – Resize the Filesystem
As you can see in the screenshot below, /dev/nvme0n1p1 still only registers 15G of total size. The command resize2fs [device] can now be executed to expand the filesystem to the total available partition space.
Once again, to highlight what happens if you omit sudo or do not have sufficient privileges, I ran the command without sudo first.
Finally, run df -h to view the system’s reported usable volume space.
Helpful Links
I found the following links/sites helpful when expanding storage.
N2WS – How to Resize EBS Volumes on AWS
https://n2ws.com/blog/how-to-guides/how-to-increase-the-size-of-an-aws-ebs-cloud-volume-attached-to-a-linux-machine
StackOverflow – How to increase AWS EBS NVME size
https://stackoverflow.com/questions/52508038/how-to-increase-aws-ebs-nvme-size