We have a bunch of micro EC2 instances for some of our services. These have a default storage size of 20GB which sometimes is too little. To increase the storage disk size, follow these steps:
- Locate the instance in your EC2 dashboard and click on the Instance ID.
- Click on the Storage tab and then on the Volume ID
- In the Actions dropdown at the top of the page, click Modify Volume
- Set the new size and save.
Now you have increased the size of the disk, but not the current partition. To do so you need to SSH into your server and run:
This will give you something like this:
nvme0n1 259:0 0 30G 0 disk └─nvme0n1p1 259:1 0 20G 0 part /
This information tells us that we can increase the
nvme0n1p1 partition with 10G. Run:
sudo growpart /dev/nvme0n1 1 and then run
nvme0n1 259:0 0 30G 0 disk └─nvme0n1p1 259:1 0 30G 0 part /
If we now run
df -h we still get:
Filesystem Size Used Avail Use% Mounted on /dev/root 20G 20G 91M 100% /
Bah! Still 20G?!
Apparently we need to extend the filesystem for each volume to use all space the partition has which we can do by running:
sudo resize2fs /dev/nvme0n1p1. If we run
df -h again, we get:
Filesystem Size Used Avail Use% Mounted on /dev/root 30G 20G 9.8G 67% /
Et voila! We now have increased the EC2 storage volume from 20G to 30G.