Increase the size of EBS volume (Root Volume )in your EC2 instance
If you are familiar with Amazon EC2 and EBS volume, you might have experiences modifying the size of EBS volume. AWS provide an easy way to increase the size of your EBS volume. In fact, we could increase it without detaching the volume or restarting the instance. That’s quite a nice work done there because we would not need to have a downtime for our instance.
Let’s exercise. Assume we have volume name test.
It is best practice to create a snapshot of your volume in case something bad happens.
- Go to your Create Snapshot in Elastic Block Storage from your EC2 Dashboard Left side menus.
- Click Create Snapshot link.
- Select Resource Type Volume
- In Volume section choose volume which you want to take snapshot
- Click button Create Snapshot.
- Go grab some snack while it is in progress.
Increase the volume
This is how we will increase the volume size. Make sure your snapshot is finished.
Let’s assume that previous volume size is 8GB and we want increase it to 10GB.
- Go to your Volume in Elastic Block Storage section from your EC2 Dashboard Left side menus.
- Select volume which you want to increase the size (In our case volume name is test so select test volume) and got to Action Drop down and choose Modify instance as shown in below image
Now fill up the storage which you want to increase as shown in following image
Extending OS file system
After you finish modifying volume, you need to extend OS file system in order to see your increased volume size. The example below is the command I used for Ubuntu OS.
- SSH into you instance.
df -hto check volume size; You will still have 8GB of volume size.
lsblk; Your increased volume will be shown just above your current volume, e.g.
xvda1is your current volume with 8GB size and
xvdawith 10GB size. (NOTE:
- Extend the partition by typing
sudo growpart /dev/xvda 1; Note that
dev/xvdais the partition name and
1is the partition number.
- Run The following command to check root filesystem:
[ec2-user ~]$ sudo file -s /dev/xvda1
if filesystem is belong to ext4 thenExtend the volume by typing
sudo resize2fs /dev/xvda1.
and if filesystem belongs to xfs then run following commandExtend the volume by typing
[ec2-user ~]$ sudo xfs_growfs -d /
df -hto check volume size; It will show 10GB of volume size.