Resizing Ubuntu 20.04 partition on AWS

June 19, 2020
LinuxUbuntuAWS

If you resized an EBS volume attached to your EC2 instance on AWS you may have noticed it’s not immediately visible by Ubuntu. In order to be able to use the newly assigned disk space, the parition on that volume needs to be extended first.

Start by connecting to your server over SSH and listing all partitions which Ubuntu can see. You can do this by running the following command in the terminal:

df -h

You may see output like this:

Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G     0  2.0G   0% /dev
tmpfs           395M  952K  394M   1% /run
/dev/xvda1       78G   23G   55G  30% /
tmpfs           2.0G  8.0K  2.0G   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/loop0       18M   18M     0 100% /snap/amazon-ssm-agent/1566
/dev/loop1       18M   18M     0 100% /snap/amazon-ssm-agent/1480
/dev/loop4       94M   94M     0 100% /snap/core/9066
/dev/loop3       98M   98M     0 100% /snap/core/9289
tmpfs           395M     0  395M   0% /run/user/1001

In this case, the volume is mounted under /dev/xvda1.

You can also view the list of block devices:

lsblk

Ubuntu has a handy tool called growpart that can automatically extend a partition in a partition table to fill available space. Let’s run it:

growpart /dev/xvda 1

As you can see it takes two arguments - the first one is the device or disk to operate on and the second one is the number of partition to resize. (important note here, the first partition has number 1, not 0 which you may have expected)

Next, extend the file system using resize2fs command. It works with ext2/ext3/ext4 file systems.

resize2fs /dev/xvda1

That’s it, Ubuntu should now see all available space on the resized volume. Make sure by running lsblk and df again.

lsblk
df -h

StackScout gives you a 24/7 insight into the state of your servers. Start your free trial now.

Start your Free Trial

We use our own and third-party cookies to improve your experience and our services, and to analyse the use of our website. By clicking Accept we take that to mean that you accept our privacy policy.