July 6, 2020 / Nirav Shah
Extend Disk space with ZERO Downtime !! Yes, you read it right.
Sometimes clients ask our AWS Team that how they can extend disk space of AWS EC2 Linux/Ubuntu Instance with zero downtime. So let us come to the solution, a secret.
But first I highly recommend you to please take AMI backup of the instance or snapshot of the volume. Just for safety purposes.
In AWS EC2, instances contain block-level storage that is EBS. Sounds familiar right !! So basically EBS is like a physical Hard Drive and it’s attached to your running instance . EBS Volumes are highly flexible, you can dynamically increase size, change Volume type and modify the provisioned IOPS.
Now let’s see how to extend disk space of your running instance.
Login to your AWS account. Go to Services and then navigate to EC2 service. Select the EC2 Instance ,navigate to Block Devices and select the Block device to be modified.
Click on actions and go to modify volume.
Increase the size of the Volume. Here I can extended the volume size is to15gb.
And click on “yes” button
Wait for a minute and Refresh the page so you will get the new size of volume
Log in to your instance via SSH or Putty and apply the following command
Now you can see the size is still showing 8GB
Here you can see the EBS size is already increase but the size of the partition is still showing 8 GB
Use the following command to increase the partition size.
$ growpart /dev/xvda 1
Now run “lsblk” again and check the partition size. You can see the size of the partition is increased to 15 GB now. But in “df -h” the size is still 8 GB. This is due to the reason that you have extended your EBS volume and also increased your Partition Size but File System on the Volume is still not modified.
Now time to extend file system
$ file -s /dev/xvd* - (This command works for T2 based Instances) $file -s /dev/nvme* - (This Command works for Nitro Based Instances)
The system may be EXT2, EXT3, EXT4 or XFS. In my case here the file system is XFS for /dev/xvda1
use below command to extend XFS file system on the volume.
$ sudo xfs_growfs -d /
Note: Using / in the above command as /dev/xvda1 is mounted on / , you can see this my df -h or lsblk command. If in case /dev/xvda1 would have mounted on /data, we need to use command the following command.
$ sudo xfs_growfs -d /data
Now apply df -h and you can see the size partition is extended now
Also Read :
As a Director of Eternal Web Private Ltd an AWS consulting partner company, Nirav is responsible for its operations. AWS, cloud-computing and digital transformation are some of his favorite topics to talk about. His key focus is to help enterprises adopt technology, to solve their business problem with the right cloud solutions.
Have queries about your AWS project ideas and concepts? Please drop in your project details to discuss with our AWS experts, professionals and consultants.