Resize The Disk Space of EC2 Instance (Zero Downtime)

Search for a command to run...

No comments yet. Be the first to comment.
Why your reactive state fails structured clone, and the fix I shipped.

I built a recipe keeper called Recipe Jar. You paste a recipe link, it gives you a clean card with just the ingredients and steps, and you can save as many recipes as you want. No account, no ads, wor

My Ubuntu server kept freezing. No warning. No error. Just completely stuck. Screen frozen, keyboard dead, only option was to hold the power button and force restart. This happened randomly. Sometimes

Let me tell you about this week(Obv. mine). I pressed the power button on our officeâs Ubuntu server. Fans started spinning. CPU light turned on. Everything sounded normal. But the monitor? Completely black. Nothing. Not even the BIOS screen showed u...

I was casually checking one of my server logs one evening(around 9:30 PMđ) and saw something annoying. Hundreds of failed SSH login attempts. From Nepal, China, Russia, Brazil, everywhere. Bots were hammering my SSH door (port 22), as it owed them m...

Looking for a step-by-step tutorial on how to increase disk space on your AWS EC2 instance?
I get it, I spent a lot of time trying to find the perfect guide myself. So I wrote this to save you the trouble I went through. (Now this article is always a go-to solution for me toođ)
Youâve landed in the right place.
In this tutorial, youâll learn how to resize your EC2 instanceâs disk without detaching the volume or restarting the server(Easily). AWS provides a block storage solution, EBS, for the instance. EBSâ Elastic Volumes feature allows you to increase volume size while the volume is still in use, making the resizing process much easier and faster without any downtime of the server.
Before extending the size of your EBS volume, Itâs good to take a backup of your data with EBS Snapshot. Itâs the best practice as if anything goes wrong, you can always restore the data.
To take a snapshot of your volume,
Go to EBS volume attached to your instance from EC2 Dashboard.
Click on Actions and Create Snapshot.
Add the description value as you wish.
You can add tags also.
Click on Create Snapshot. It may take some time.
After creating a snapshot of your volume, now itâs time to increase your disk space.
Steps:
First Go to Services > EC2 > Instances.
Go to the EBS volume attached to your instance.
From Actions click on Modify Volume.
Add your desired size, I will be replacing 8 with 30.
Youâll get a confirmation pop-up. Click on Modify.
You have successfully added a new volume size to your instance, but you arenât using the new volume size. For this, SSH to your server or instance and run: df -h
Here, you can see our disk partition is still using 8GB. Check the partition size by running commands lsblk and blkid.1
Here, xvda1 is your current volume with 8GB and xvda with 30GB.
<aside> đ *xvda1 or similar is for Xen Virtual Machine based server. For NVMe (Non-Volatile Memory Express) solid-state drive (SSD) based device, it will be nvme0n1p1 or similar.*
</aside>
Now extend the partition:
# For xvda1 partition
$ sudo growpart /dev/xvda 1
# For nvme0n1p1 partition
$ sudo growpart /dev/nvme0n1 1
And, extend the volume:
$ sudo xfs_growfs /dev/xvda1
$ sudo xfs_growfs /dev/nvme0n1p1
Type df -h to check the volume size, it must show 30GB.
In our case, since the file system is XFS, we have to use xfs_growfs tool.
For file systems ext4, ext2, and ext3 you have to use sudo resize2fs /dev/xvda1 OR sudo resize2fs /dev/nvme0n1p1.
In this way, the volume is now resized and ready to be used without any downtime.
Thank you!