If you’ve worked with EC2 instances, you’ve likely encountered situations where disk usage gradually increases as we store large amounts of files and host applications or services. In such cases, it becomes necessary to increase the disk size to maintain business operations. Failure to take action may result in the server becoming unreachable, leaving us with no choice but to restart it.
Increasing disk size may seem complex. Do we need downtime? Should we stop the server? Do we need to detach the volume? These questions may cross your mind.
However, the reality is that we can increase disk size without detaching the volume or restarting the server. Moreover, this process doesn’t require any downtime, though I recommend performing it during off-hours.
Enough theory — let’s get our hands dirty.
Step 1: Check the current disk status
Make sure you have active running EC2 instance in your AWS account or you can spin up the one to follow along with the tutorial.
Here I have my application server instance running with 8GB of EBS volume attached
Check the disk status by using below command
df -hT
The current disk size is 8GB and 20% used. Now, let’s proceed with the next step.
Step 2: Create Snapshot
Creating snapshot is essential in order to keep backup of our existing volume in case anything unusual happens during this activity.
- Click on the EBS volume ID attached to your EC2 instance
2. Select your EBS volume and click on actions > Create snapshot.
3. GIve relevant description and tag to you snapshot
4. Go to snapshots and wait till your snapshot status shows Completed
Step 3: Increase the EBS volume
Make sure your snapshot is created successfully before proceeding with this step.
Go to the volumes section, select the volume attached to the EC2 and click on modify volume
Increase the volume size as per your requirement and click on modify. Here I have changed volume size from 8 to 15 GB.
You could now see that disk volume attached to the server is updated to 15GB
Step 4: Resize the File System
Now we need to extend our OS file system to see our increased volume.
- SSH into the EC2 instance
- Run the below command to check volume size
df -hT
We can see that disk size is still 8GB. 😕
3. Run the below command to see information about the block devices attached to our EC2 instance.
lsblk
Here xvda1 is our current volume that is attached and xvda is the increased volume.
4. Extend the partition xvda by 1
sudo growpart /dev/xvda 1
5. Extend the volume
sudo xfs_growfs -d /dev/xvda1
6. Check the volume size
df -hT
We can see that our volume size has now increased to 15GB 🎉
Conclusion
In this blog, we’ve learned how to seamlessly increase the EBS volume size for our EC2 instance, ensuring smooth operations even as our storage needs grow. By following these steps, we’ve eliminated the need for downtime or server restarts, making the process efficient and hassle-free.
I hope you found this content informative and enjoyable. For more blogs and updates, please consider following and clicking the 👏 button below to show your support. Happy coding! 🚀
Thank you for reading! 💚