Ubuntu 20.04 & 22.04 VM increase disk size

Recently I was running out of disk space on one of my NextCloud installations and I needed to increase the disk space. As I was not familiar with the partition commands I pinged my friend stsimb. Thanks!!!

I have tested this procedure on Hyper V and on ESXi but I guess it will work also on other Hypervisors.

First, shutdown the VM and increase/expand the disk size to the desired value.

Start up the VM and SSH to it. Of course we need root access

sudo su

Then let’s make sure we can see the increased size of the sda

lsblk

The lvm is under sda3 so in order to increase the size of sda3 and resize the volume

growpart /dev/sda 3

pvresize /dev/sda3

And increase the capacity of the lvm

lvextend --extents +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv -r

Verify with

lsblk

 and

df -h

and you are done

Comments

  1. stsimb

    If your hypervisor can extend the disk while the VM is running, then you don’t even have to reboot, you can do it online..

    After you increase the disk size in your hypervisor, you can use this command to rescan the disks…

    for d in /sys/class/scsi_device/* ; do echo 1 > $d/device/rescan ; done

    1. Post
      Author
      pargyrak

      Depends on the Hypervisor.

      Hyper V on a failover cluster does not allow the increase if the disk is IDE. Also if you have a snapshot then you cannot increase.

Leave a Reply

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