December 23, 2024
AWS EBS

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.

Chaliye shuru karte hai

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

Application Server EC2
EBS volume attached to application server

Check the disk status by using below command

df -hT
EC2 disk usage

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.

  1. Click on the EBS volume ID attached to your EC2 instance

2. Select your EBS volume and click on actions > Create snapshot.

EBS volume

3. GIve relevant description and tag to you snapshot

Create snapshot

4. Go to snapshots and wait till your snapshot status shows Completed

Snapshot

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

Modify EBS volume
Modify EBS 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.

  1. SSH into the EC2 instance
  2. Run the below command to check volume size
df -hT
Check volume size

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
`List attached block devices

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
Extend volume partition

5. Extend the volume

sudo xfs_growfs -d /dev/xvda1
Extend EBS volume

6. Check the volume size

df -hT
disk volume

We can see that our volume size has now increased to 15GB 🎉

Abki baar 400 paar (This time, over 400 seats)

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! 💚

Apko acha laga blog? Toh aisay thoda follow par hath mar dijiye aap… (Did you like the blog? Then hit the follow button, if you please…)

Leave a Reply

Your email address will not be published. Required fields are marked *