Resize EBS volume without rebooting in AWS

So you need to resize an 8GB boot Disk in AWS after the EC2 is created. In this article we resize the EBS volume without rebooting.

1. Modify volume in AWS EC2 UI
After login to AWS console, navigate to EC2 -> Elastic Block Store -> Volumes. Click on the volume that you wist to resize, then select Actions -> Modify Volume. It will open a popup.

Enter the new size in the size field. Lets says we are resizing from 8 GB to 30 GB.
Click Modify button
Click Yes button in the confirm popup.
Now the volume has been resized, but it won’t reflect in the system. We need to do some more steps to make it work.

2. Resize the partition
Lets ssh into the machine.

List block devices attached to the machine.

# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0     7:0    0 88.5M  1 loop /snap/core/7270
loop1     7:1    0   18M  1 loop /snap/amazon-ssm-agent/1455
loop2     7:2    0   89M  1 loop /snap/core/7713
xvda    202:0    0    8G  0 disk
└─xvda1 202:1    0    8G  0 part /

You can see that xvda1 is still 8 GB. Lets increase the partition to disk size.

Install cloud-guest-utils

# apt install cloud-guest-utils

Grow the partition

# growpart /dev/xvda 1

Let’s check the partition size (you can see /dev/xvda1 is now 30 GB):

# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0     7:0    0 88.5M  1 loop /snap/core/7270
loop1     7:1    0   18M  1 loop /snap/amazon-ssm-agent/1455
loop2     7:2    0   89M  1 loop /snap/core/7713
xvda    202:0    0   30G  0 disk
└─xvda1 202:1    0   30G  0 part /

3. Resize the file system
Check the file system size. (Still it shows only 8 GB)

# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            481M     0  481M   0% /dev
tmpfs            99M  840K   98M   1% /run
/dev/xvda1      7.7G  6.9G  805M  90% /
tmpfs           492M     0  492M   0% /dev/shm
tmpfs           5.0M   24K  5.0M   1% /run/lock
tmpfs           492M     0  492M   0% /sys/fs/cgroup
/dev/loop0       89M   89M     0 100% /snap/core/7270
/dev/loop1       18M   18M     0 100% /snap/amazon-ssm-agent/1455
/dev/loop2       90M   90M     0 100% /snap/core/7713
tmpfs            99M     0   99M   0% /run/user/1000

Resize the filesystem

# resize2fs /dev/xvda1
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 4
The filesystem on /dev/xvda1 is now 7864059 (4k) blocks long.

Check after resizing

# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            481M     0  481M   0% /dev
tmpfs            99M  840K   98M   1% /run
/dev/xvda1       30G  6.9G   23G  24% /
tmpfs           492M     0  492M   0% /dev/shm
tmpfs           5.0M   24K  5.0M   1% /run/lock
tmpfs           492M     0  492M   0% /sys/fs/cgroup
/dev/loop0       89M   89M     0 100% /snap/core/7270
/dev/loop1       18M   18M     0 100% /snap/amazon-ssm-agent/1455
/dev/loop2       90M   90M     0 100% /snap/core/7713
tmpfs            99M     0   99M   0% /run/user/1000

The disk is now resized.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.