How to extend AWS EBS Volume with zero downtime
AWS EBS Volume is a durable and block-level storage device that is attached to an EC2 Instance. It is used as a physical Hard Drive, but one thing that other physical Hard Drive does not have and EBS Volume has is its flexibility.EBS Volumes are highly flexible, you can dynamically increase size, change Volume type, and modify the provisioned IOPS capacity on live Server.
Block-Level Storage is nothing but blocks of storage created on SAN(Storage Area Network) and each block are treated as an individual hard drive.
This tutorial Contains:
- How to Extend/resize AWS Elastic Block Store(EBS) Volume in Windows Instance
- How to extend/resize AWS Elastic Block Store(EBS) Volume in Linux Instance
Before Starting I would recommend you take AMI backup of the instance or Snapshot of the Volume. Taking backup is recommended for safety purposes.
Recommended Article: AWS EC2 AMI backup and restore
Also Read: AWS EBS Snapshot Backup and Restore
Extending AWS EBS Volume in windows Instance
Step 1– Login to your AWS account and navigate to Instances in EC2 Service. Select the Instance whose Volume to be modified. Click on Block Devices say /dev/sda1 to be extended.Click on EBS ID looks like vol-xxxxxxxxxxxxxx.
Step 2-As soon as you click on EBS ID in the above screenshot, it will redirect you to the Volume tab in Elastic Block Store. Now click on Actions and then click on Modify Volume.
Step 3– Increase the size of the Volume. Here Current Size is 30 GB and we are extending it to 50 GB.
Step 4– Click on Yes to confirm the modification.
Step 5– Refresh the page and you will see the size of the volume is modified.
Step 6– Login to the Windows Server and open Computer Management.
Step 7– Right-click on the Volume to be extended and click Extend Volume.
Step 8– Click on Next
Step 9 – The following prompt will appear. Click on Next.
Step 10– Click on Finish.
Step 11 – Now you can see the size of the Disk is increased from 30 GB to 50 GB.
Extending AWS EBS Volume in Linux Instance
Step 1 – 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.
Note: If you have multiple EBS Volumes attached to your Instance and want to see which Block Device you have to choose, you can find this by the following command, by login into your Linux Instance.
$ df -h
df -h shows here we have only one EBS Volume attached i.e /dev/xvda with one partition /dev/xvda1. If you have multiple EBS Volumes attached such as /dev/xvdb , /dev/xvdc etc. that can be also seen by “dh -h” command only. So use this command to find out the Block device name so that you can select the same on AWS console to resize.
Step 2 – As soon as you click on the EBS ID looks like vol-xxxxxxxxxxxxxx as shown in the screenshot in Step 1, it will redirect you to the following screen. Select Actions and click on Modify Volume.
Step 3– Increase the size of the Volume. Here, the current Size is 8 GB and we are extending it to 15 GB.
Step 4– Click on Yes to confirm the modification.
Step 5 – Refresh the page and you will see the size of the volume is modified.
Step 6 – Login to your Linux box and enter the following command.
You can see the size of the partition is still showing 8 GB.
The following command will give you more clarity.
Here you can see the size of the EBS Volume is already increased to 15 GB, but the size of the partition is still showing 8 GB.
Step 7 – 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. You need to modify your file system as well.
Step 8 – Extend the File System.
Check your File system by following commands
$ file -s /dev/xvd* (This command works for T2 based Instances)
$file -s /dev/nvme* (This Command works for Nitro Based Instances)
As a result, the file system may be EXT2,EXT3,EXT4 or XFS.
See the below example, where the file system is XFS for /dev/xvda1.
i)Extend XFS File System.
Use the following command to extend the 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 run df -h again. You can see the size of the partition is extended now.
ii) Extend EXT2, EXT3 or EXT4 File Systems.
Use resize2fs command to extend EX2,EXT3,EXT4 files systems on each Volume
$ sudo resize2fs /dev/xvda1
$ sudo resize2fs /dev/xvdf1
Now run dh -h command again and you can see the File System is modified now.
I hope you enjoyed this tutorial and learned how to extend AWS EBS Volume with zero downtime. If you think this is really helpful, please do share this article to others as well. Please also share your valuable feedback, comment, or any query in the comment box. I will really happy to resolve your queries.