Increase EBS volume size in AWS EC2

Overview

Instead of adding a large EBS volume size initially, we usually set the minimum required size and when needed we can increase EBS volume size in AWS EC2 Instance. With this approach, AWS costs can be minimized.

Now, when we try to increase EBS volume size in AWS EC2 instance it does not increase automatically.

Hence, let’s start how to do it.

Disclaimer

You will be fully responsible if anything goes wrong and you lose your data with the steps provided here. Make sure to create a snapshot of your volume before you start the steps. So that you can restore from it if anything goes wrong.

Let’s follow the steps to increase EBS volume size in AWS EC2 instance

  1. Stop your EC2 instance
  2. Go to the Elastic Block Store menu on the left side and click on volumes.
  3. Find the correct volume listed and click on it. If you don’t know how to find the correct volume that uses by our instance then you can click this link.
  4. Go to Actions -> Modify Volume. (Make sure to create the snapshot of your volume before clicking Modify Volume). After clicking Modify Volume you may see the new window like the following.
Increase EBS volume size in AWS EC2 modify volume 1
Remember: Once, you increase the size you can’t decrease.
  1. Increase the size of the volume and click Modify. You may see the info message. You can ignore it.
  2. Now, start your instance and SSH to it.
  3. Execute the command df -h and you may see the following output.
ubuntu@ip-172-31-26-225:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            964M     0  964M   0% /dev
tmpfs           196M  3.2M  193M   2% /run
/dev/nvme0n1p1   15G   15G     0 100% /
tmpfs           978M     0  978M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           978M     0  978M   0% /sys/fs/cgroup
/dev/loop0       34M   34M     0 100% /snap/amazon-ssm-agent/3552
/dev/loop1      100M  100M     0 100% /snap/core/11167
/dev/loop2      100M  100M     0 100% /snap/core/11187
/dev/loop3       33M   33M     0 100% /snap/amazon-ssm-agent/2996
/dev/loop4       56M   56M     0 100% /snap/core18/2074
/dev/loop5       56M   56M     0 100% /snap/core18/2066
tmpfs           196M     0  196M   0% /run/user/1000

Here, you can see that it is still showing the size 15 GB in the /dev/nvme0n1p1 File System and is 100% utilized.

I have changed the Volume size to 25 from 15 but this change is not working.

  1. To see where is our remaining 10 GB. Execute the command lsblk
ubuntu@ip-172-31-26-225:~$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0         7:0    0 99.2M  1 loop /snap/core/11167
loop1         7:1    0 55.4M  1 loop /snap/core18/2066
loop2         7:2    0 99.4M  1 loop /snap/core/11187
loop3         7:3    0 55.5M  1 loop /snap/core18/2074
loop4         7:4    0 32.3M  1 loop /snap/amazon-ssm-agent/2996
loop5         7:5    0 33.3M  1 loop /snap/amazon-ssm-agent/3552
nvme0n1     259:0    0   25G  0 disk
└─nvme0n1p1 259:1    0   15G  0 part /

Here, we can see the full disk size at nvme0n1 but our original partition has still 15 GB.

  1. To avoid a No space left on the block device error, mount the temporary file system tmpfs to the /tmp mount point. This creates a 10 M tmpfs mounted to /tmp. (This is optional, but if you see the error in the next step you can execute the following script)
sudo mount -o size=10M,rw,nodev,nosuid -t tmpfs tmpfs /tmp
  1. Now, execute the growpart command to grow the size of the root partition. Replace /dev/nvme0n1 with your root partition. In my case my root partition name is /dev/nvme0n1. Hence, see the example below:
ubuntu@ip-172-31-26-225:~$ sudo growpart /dev/nvme0n1 1
CHANGED: partition=1 start=2048 old: size=31455199 end=31457247 new: size=52426719,end=52428767
  1. Now, execute the lsblk command and you will see the size changed. You can compare following output with the output in step 8 above.
ubuntu@ip-172-31-26-225:~$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0         7:0    0 99.2M  1 loop /snap/core/11167
loop1         7:1    0 55.4M  1 loop /snap/core18/2066
loop2         7:2    0 99.4M  1 loop /snap/core/11187
loop3         7:3    0 55.5M  1 loop /snap/core18/2074
loop4         7:4    0 32.3M  1 loop /snap/amazon-ssm-agent/2996
loop5         7:5    0 33.3M  1 loop /snap/amazon-ssm-agent/3552
nvme0n1     259:0    0   25G  0 disk
└─nvme0n1p1 259:1    0   25G  0 part /
  1. Now, the final step is to execute the resize2fs command for your root partition. In our example our root partition is /dev/nvme0n1p1
ubuntu@ip-172-31-26-225:~$ sudo resize2fs /dev/nvme0n1p1

You may see the output like below:

resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/nvme0n1p1 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 4
The filesystem on /dev/nvme0n1p1 is now 6553339 (4k) blocks long.
  1. You can verify the disk size with the command df -h and the output will be like:
ubuntu@ip-172-31-26-225:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            964M     0  964M   0% /dev
tmpfs           196M  3.2M  193M   2% /run
/dev/nvme0n1p1   25G   15G  9.7G  60% /
tmpfs           978M     0  978M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           978M     0  978M   0% /sys/fs/cgroup
/dev/loop0      100M  100M     0 100% /snap/core/11167
/dev/loop1       56M   56M     0 100% /snap/core18/2066
/dev/loop3       56M   56M     0 100% /snap/core18/2074
/dev/loop2      100M  100M     0 100% /snap/core/11187
/dev/loop5       34M   34M     0 100% /snap/amazon-ssm-agent/3552
/dev/loop4       33M   33M     0 100% /snap/amazon-ssm-agent/2996
tmpfs           196M     0  196M   0% /run/user/1000
tmpfs            10M     0   10M   0% /tmp
  1. If you have mounted to your temp directory then execute following command to unmount it. If you haven’t mounted you can ignore this step.
ubuntu@ip-172-31-26-225:~$ sudo unmount /tmp

Conclusion

Here, we learn to increase the size of Elastic Block Storage (EBS) volume.

Sharing Is Caring:
Subscribe
Notify of
2 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments