Resize EBS volume without rebooting in AWS

This article guide you to 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.

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.

lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0     7:0    0   91M  1 loop /snap/core/6350
loop1     7:1    0   18M  1 loop /snap/amazon-ssm-agent/930
loop2     7:2    0 89.4M  1 loop /snap/core/6818
loop3     7:3    0 17.9M  1 loop /snap/amazon-ssm-agent/1068
xvda    202:0    0  150G  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.

apt install cloud-guest-utils
growpart /dev/xvda 1
lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0     7:0    0   91M  1 loop /snap/core/6350
loop1     7:1    0   18M  1 loop /snap/amazon-ssm-agent/930
loop2     7:2    0 89.4M  1 loop /snap/core/6818
loop3     7:3    0 17.9M  1 loop /snap/amazon-ssm-agent/1068
xvda    202:0    0  150G  0 disk
└─xvda1 202:1    0  150G  0 part /

3. Resize the file system

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.8G  4.9G  2.6G  62% /
resize2fs /dev/xvda1
df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      146G  4.9G  141G   3% /

So we have increased the EBS volume without rebooting and zero downtime.

Vote on HN

comments powered byDisqus