Suppose you have created an EC2 instance and attached an EBS volume to it.
Lets first check how can we increase the storage capacity of the EBS volume.
To do so go to the volume section, select the volume whose storage capacity you want to increase then click on action and then click on modify volume.
Now you can increase the storage size to your desired size.
(My present size is 15Gb I am going to convert it to 20 Gb)
PLEASE NOTE THAT YOU CAN ONLY INCREASE THE SIZE HERE,YOU CAN NOT DECREASE THE STORAGE SIZE FROM HERE.
Now after changing the size click on modify and then again click on modify.
Now wait until the volume to optimize 100%, you can check it by going to the volume section
Once its optimized 100% you can go to Xshell and type lsblk. You can see that the storage size have increased to your desired size.
But if you type df -h then you will see that the size of the external storage is still 15gb.
This is because we have not resized the size of volume in the instance end. So, we can resize by typing a command in the Xshell.
Just write resize2fs /dev/xvdf and then if you type df -h then you will find that the size of your volume is increased.
This is how you can increase the size of your EBS volume.
Procedure to decrease the size
The process to decrease the size of the EBS volume is totally different form that of increasing the size. But this is also quite easy.
Suppose your current volume size is 20Gb and you want to convert it to 10Gb then you just need to go to the volume section and create a EBS volume of 10Gb at the same Availability Zone as of your EC2 instance.
Now give it a name tag(its optional) then click on create volume.
Then select the newly created volume and click on action and then press on attach volume.
Then select the instance and then press attach volume.
Now do the same old process of formatting and mounting the new volume in the instance.
Now we just need to sync all the data from the previous external storage to the new reduced external storage. The command to do so is rsync -aHAXxSP /ext_vol /red_ext_vol/
Now all the data from the previous External storage is transferred to the new external storage, so now we need to unmount the previous external storage. The command to do so is** umount /dev/xvdf**.After doing that go the volume section and select external volume and click on detach volume.
Now once its status become available just select the volume again click on action and click on delete volume.
This is the whole process by which we can reduce the size of an EBS volume.
Top comments (0)