How to Resize EBS Volumes with Linux EC2 Instances
We have an EC2 instance perhaps a small application that doesn’t require many resources. But we there is requirement to increase disk space.
Since this application uses little storage, a small, 20GB general purpose AWS EBS volume has been attached.
First, go to your volume and choose “Modify Volume” under “Actions.”
You are then given the option to change both the disk size and the volume type.
You can also switch to Provisioned IOPS SSD (io1), increase the size to 100GB, and have the IOPS set to 5000 if your requirements necessitate this step.
Remember that if you are resizing your root volume, you won’t be offered the option to change to Throughput Optimized HDD (st1) or Cold HDD (sc1).
Starting the EBS resizing process
In this example, we’ll extend the volume to 30GB and retain the volume type. To do this, adjust the values and start the resizing process by clicking on “Modify.” The volume will now begin the optimization process, which you can follow on the console.
The time it takes to optimize the volume depends on the volume’s size. In this case, the process took 5-10 minutes. After it was over, the volume state color turned green again, showing that the resizing was finalized.
After the volume has been extended, the EC2 instance and the system both need to be adjusted to adapt to the new size. Note that you can do this adjustment either as a root or a user with sudo privileges.
The first step in this process is checking the partition size.
The screenshot above shows that the volume has been extended; however, the primary partition is still at the volume’s original size. To expand the partition, use the command shown in the screenshot below. After you do so, you will see that the partition has grown to match the volume size.
Note that there is a space between “/dev/xvda” and “1.” “1” refers to the partition number.
Checking the file system size
Next, the file system size needs to be checked. In the screenshot below, you will notice that it is still only registering 20GB, even though both the volume and partition have been resized.
If you were using an ext4 (or even older ext2 or ext3) file system, you could extend it using the “resize2fs /dev/xvda1” command.
In our case, since the file system is XFS, we have to rely on the “xfs_growfs” tool, which should already be in the system. If not, you can install it yourself as part of the “xfsprogs” package.
Using this, we can proceed to extend the file system to match the volume and the partition size of 30GB. We will target the “/”, since that is where “/dev/xvda1” has been mounted.
The volume is now fully resized and ready to be used. No downtime resulted from this process.