Introduction
Elastic Block Storage known as EBS is a storage type in AWS. It is a block level storage type, we cannot access any files inside the EBS volume from AWS console. EBS volumes can be attached with EC2 instances. We can access files from SSH connection with its attached EC2 Instance. We can increase or decrease the EBS volume size at any time. But whenever you want to resize the volume, make sure to take a copy of that volume. This is a best practice incase of any failure in the resizing process, you can recover your data anytime.
Now we are going to Increase the size of the EBS volume which is attached with an EC2 Instance.
Resize EBS Volume
- First Select the EC2 instance which is attached with the EBS volume that we need to increase size.
- Select the Storage section and you can find the attached volumes with the EC2 Instance. Click the volume.
It will navigate you to the volumes section. Then select the volume, then click Actions followed by Modify volume.
Enter the number of size you want to upgrade the volume. Here I entered 20GiB, then click Modify.
It asks you for confirmation to modify the volume. Click Modify to continue.
Now the volume state is optimizing. It will take a couple of minutes.
Wait until the Volume state is In-use. Now the volume is successfully upgraded to 20GiB.
Update the Resize EBS with EC2
- Login to your EC2 Instance with sudo privileges.
- Type the ‘lsblk’ command in the terminal window.
- In the below picture you can see our volume has been extended to 20GiB. But the primary partition is still the old volume’s size.
To expand the partition use the following command like the screenshot below.
growpart /dev/xdva 1
Now again run the ‘lsblk’ command to see the changes made.
- From the above screenshot our primary partition is successfully extended to new volume size.
- Now we need to check the size of the file system.
- So run the following command: ‘df -h’
- You can notice that it is still with the old 8GiB size.
- Run the following command to see the type of the file system that we used.
file -s /dev/xvd*
- In Amazon Linux 2 EC2 instances’ file system is XFS like the picture below.
For the XFS file system use the following command to extend the file system.
xfs_growfs -d /
Now again run the ‘df -h’ command to see the change happens.
As you can see the above picture shows our file system successfully upgraded to new volume size.
Now the EBS volume is fully resized from 8GiB to 20GiB and ready to used.
In this process there is no downtime on our server.