Oh no! You server is running out of disk space?
Don't worry this article will guide you through the steps to increase the disk size/ storage of your AWS EC2 server.
The following steps are for Ubuntu 20.04 EC2 server and volume type ext4.
STEP 1: Create Disk Snapshot for Backup
Remember, it is always recommended to take a snapshot of your EC2 volume for safety and backup, just in case anything goes wrong.
Go to Instances. Then on the bottom menu, go to Storage tab and click on the Volume ID you want to extend. In our case, the Volume ID is vol-0fc70720b58a3ac9a
On the newly opened page, right click on the volume and click Create Snapshot.
If you go to Elastic Block Store > Snapshot, you will see your newly created snapshot.
STEP 2: Check Current Disk Size
Let's check the current disk size of our EC2 instance.
Connect to your EC2 instance and run the following commands:
df -hT
lsblk
blkid
In the image above, we are interested in extending the 7.7GB(~8GB) /dev/root
which has a filesystem type of ext4 which is a standard EBS Volume. (In this article, we will also partially discuss how to extend a NVMe EBS volumes.)
Take note of the block id /dev/xvda1/
, we will be using this reference id when we extend our filesystem after we increase our disk size.
(For NVME EBS volumes block id will be /dev/nvme0n1p1
)
STEP 3: Increase EC2 Instance Disk Size
On the same Volumes page opened in Step 1, right click on the volume and click Modify Volume.
From 8GB we will increase the volume disk size to 15GB (An extra 7GB).
Click refresh and you will see that disk size is now 15GB.
(Note: You can only modify volume size every 6 hours, so double check the size modification before proceeding.)
STEP 4: Extend the Instance Filesystem
Although we have increased the our EC2 instance's disk size to 20GB. We still have to extend the filesystem to be able to utilize it. Re-execute the following commands:
df -hT
lsblk
blkid
Here you can see that /dev/root
size is still 8GB. Although block xvda
is 15GB due to the increased disk size. xvda1
which is our root filesystem is still 8GB.
To utilize the increased disk size run the following commands:
For Standard EBS Volumes:
sudo growpart /dev/xvda 1
sudo resize2fs /dev/xvda1
(For NVME EBS Volumes):
sudo growpart /dev/nvme0n1 1
sudo resize2fs /dev/nvme0n1p1
Running the same following commands again:
df -hT
lsblk
blkid
You will see that our root filesystem is utilizing the full 15GB disk space.
Closing Notes:
You an extend disk space of the boot volume(root partition) up to 1634 GB. If you need more, then it is recommended to attach extra storage space via Amazon Elastic Block Storage (EBS).
For more details on increasing disk space check the official AWS documentation: docs.aws.amazon.com/AWSEC2/latest/UserGuide..
Stay stoked and code.