Extend a Linux file system after resizing a VM volume

After you increase the size of a VM boot disk volume, you must use file system–specific commands to extend the file system to the new, larger size. You can do this as soon as you have resized the VM in the detail page.

To extend a file system on Linux, you need to:

  1. Extend the partition, if your volume has one.
  2. Extend the file system.

Resize Partition

Use the following procedure to extend the file system for a resized volume. Check whether the volume has a partition. Use the lsblk command.

loop0     7:0    0 63.3M  1 loop /snap/core20/1879
loop1     7:1    0 91.9M  1 loop /snap/lxd/24061
loop2     7:2    0 53.2M  1 loop /snap/snapd/19122
loop3     7:3    0 73.9M  1 loop /snap/core22/864
loop4     7:4    0 59.9M  1 loop /snap/go/10389
loop5     7:5    0 40.9M  1 loop /snap/snapd/20290
loop6     7:6    0 63.5M  1 loop /snap/core20/2015
sda       8:0    0   40G  0 disk
vda     252:0    0  151G  0 disk
├─vda1  252:1    0 79.9G  0 part /
├─vda14 252:14   0    4M  0 part
└─vda15 252:15   0  106M  0 part /boot/efi
vdb     252:16   0    1M  0 disk

Extend the partition. Use the growpart command and specify the partition to extend. In the following example, we want to grow disk /dev/vda in partition 1.

sudo growpart /dev/vda 1

The output will be similar to:

sudo growpart /dev/vda 1
CHANGED: partition=1 start=227328 old: size=167544799 end=167772127 new: size=316442591 end=316669919

Recheck the volume partition with lsblk command.

Extend the file system

Use df -hT command to check the file system.

df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  3.7G     0  3.7G   0% /dev
tmpfs          tmpfs     759M  1.7M  757M   1% /run
/dev/vda1      ext4       78G   24G   55G  30% /
tmpfs          tmpfs     3.8G     0  3.8G   0% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs     3.8G     0  3.8G   0% /sys/fs/cgroup
/dev/loop1     squashfs   92M   92M     0 100% /snap/lxd/24061
/dev/loop0     squashfs   64M   64M     0 100% /snap/core20/1879
/dev/loop2     squashfs   54M   54M     0 100% /snap/snapd/19122
/dev/vda15     vfat      105M  6.1M   99M   6% /boot/efi
/dev/loop3     squashfs   74M   74M     0 100% /snap/core22/864
/dev/loop4     squashfs   60M   60M     0 100% /snap/go/10389
/dev/loop5     squashfs   41M   41M     0 100% /snap/snapd/20290
/dev/loop6     squashfs   64M   64M     0 100% /snap/core20/2015
tmpfs          tmpfs     759M     0  759M   0% /run/user/1000

Awanio uses Ext4 file system, so for that, use the resize2fs command and specify the name of the file system that you noted in the previous step.

sudo resize2fs /dev/vda1

The output will be similar to:

sudo resize2fs /dev/vda1
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old_desc_blocks = 10, new_desc_blocks = 19
The filesystem on /dev/vda1 is now 39555323 (4k) blocks long.

Use df -hT command again to check the final size.