Increase the size of EBS volume in your EC2 instance
In this post, I will guide you on how to increase disk size for an EC2 instance on AWS.
Many times for DevOps Engineers needed to increase EC2 EBS volume due to:
1. Given default 8GB EBS volume at the time to launch EC2 instance.
2. The given EBS volume gets full due to too many docker images and other prod files.
First, we need to log in AWS console and select the ec2 instance which is running out of space. click on volume and follow the steps;
Create snapshot
It is best practice to create a snapshot of your volume in case something bad happens. 1. Go to your EBS volume list from your EC2 Dashboard.
2. Right-click the volume.
3. Click Create Snapshot link.
4. Add the description value snapshot-my-volume.
5. Add key: Name and value: ec2-ebs-snapshot.
6. Click the button Create Snapshot.
7. wait for some time while it is in progress.
Create a snapshot
Increase the volume
This is how we will increase the volume size. Make sure your snapshot is finished.
1. Let’s assume that the previous volume size is 8GB and we want to increase it to 100GB.
2. Right-click on the volume you wish to increase.
3. Add your desired size; In our example type 100.
4. Click Modify.
5. You will get confirmation to extend the OS file system.
6. Click Yes.
Increase volume
After you finish modifying volume, you need to extend the EC2 file system in order to see your increased volume size. The example below is the command I used for Ubuntu OS.
1. SSH into your EC2 instance.
2. Type df -h to check volume size; You will still have 8GB of volume size.
3. Type lsblk ;
4. Your increased volume will be shown just above your current volume, e.g. xvda1/nvme0n1 is your current volume with 30GB size and xvda/nvme0n1 with 100GB size.
5. Extend the partition by typing
sudo growpart /dev/xvda 1 ;
sudo growpart /dev/nvme0n1 1 for other type voume
sudo xfs_growfs -d / for other type voume
Note that dev/xvda is the partition name and 1 is the partition number.
6. Extend the volume by typing
sudo resize2fs /dev/xvda1 . or
sudo resize2fs /dev/nvme0n1
7. Type df -h to check volume size; It will show 100GB of volume size.
We have successfully increased the size of EBS volume from 8GB to 100GB in the EC2 instance.
0 Comments
Post a Comment