Extend Your EC2 Storage Volume Size

Published by Wayne on

So you’ve created an EC2 but not given it enough storage. Now you’ve run out and are wondering how you change it.

EC2 With 8GB Storage
An EC2 With 8GB Storage

Here’s how you do it.

First SSH into your EC2 (Make sure your security groups are set that you can access port 22, you have the SSH Keys and replace the IP with that of your own EC2)

ssh ec2-user@34.243.248.159

Next run this command to show your available space

lsblk
lsblk command showing 8gb

Here you can see that your root block device, and it’s only partition are of 8GB

To change this, go to your EC2 Instance in the AWS Console and look for the root device. Hover over this /dev/xvda link:

AWS ec2 management page
Hover over /dev/xvda

Next click the link which should be the EBS ID, to be taken to the volumes page.

From here you can click Actions > Modify Volume

Volumes Page

You’ll then have a window where you can change the 8GB to whatever you want. Let’s use 100GB, and press modify.

This may take some time to take effect, so go grab a cuppa.

After a couple of minutes, you should be able to view the storage on your EC2 again using the same command, and this time see the 100GB:

lsblk two
Now showing 100GB

This is great, but we’re not done yet, since the root volume is 100GB but our default partition is still 8GB, so we need to expand it.

Assuming your root volume is named the same as mine, you’ll issue this growpart command to tell it to expand it’s first partition:

 sudo growpart /dev/xvda 1

Another lsblk command will this time show your expanded partion

lsblk

Now WAIT! You may think you’ve finished and can happily go ahead and use your 100GB…but that’s not the case.

You’ve created a bigger volume, extended your partition but your file system still doesn’t know about this extra size and will be 8GB. Don’t believe me? Run this command:

df -hT
df -ht 8gb

See, the /dev/xvda1 file system is still 8GB. The way to extend this depends on the type. If, like here, yours is XFS, run this command:

sudo xfs_growfs /dev/xvda1

or if your system shows ext, run:

sudo resize2fs /dev/xvda1

Now perform your df command again:

df -hT
df -hT success
Boom, 100GB.

Now you can see 100GB and you’re good to go and use this space for all your cat memes.

Image result for cat coding

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *