Resizing an Ubuntu Guest VM Disk

Just today I needed to expand a disk again on a couple of VirtualBox VMs running Ubuntu 20.04. The docs on Ubuntu say there is a Disks app that provides a GUI. But even after resizing the virtual hard disk in the VM media manager, and following those steps, Disks did not resize it, nor did it show any error.

Specifically, after clicking the red Resize button, nothing happened.

A couple years ago I wrote a post on dev.to, "Expand disk in virtualbox Ubuntu 18 guest". The steps were basically: shutdown VM, resize hard disk in VM manager, boot VM, resize extended partition using gparted GUI, then 3 more complicated command line commands involving pvresize (physical volume resize), lvresize (logical volume resize), and resize2fs.

But with gparted 1.0, it is possible to do everything after booting in the GUI, which is a lot simpler than my original post on dev.to. Here are the steps:

Resize virtual disk in VirtualBox

  1. Power down the VM

  2. Go to Virtual Media Manager (VMM)

  3. Select the disk that corresponds to your VM and resize the disk file (this is possible only on powered down VM)

  4. Start VM

Resize partition in guest using gparted:

  1. If you don't have gparted 1.0, install gparted: sudo apt install gparted. As of June 30, 2023 this installed 1.0.0.

  2. Backup any data, in case something goes wrong. I just cloned the disk in virtualbox media manager.

  3. Start gparted

  4. Select the extended partition (/dev/sda2 in my case, see snapshot). This extended partition must be resized first, as it is the "physical partition" and contains your actual root logical partition (/dev/sda5 in my case). Right-click it and select Resize...

  1. You can enter any number larger than the total size of the hard disk, gparted will automatically compute the correct max value. Click OK.

    • After you OK this, you will see a pending operation in the bottom section, and the unallocated portion will now be child of the extended partition.

    • You will also notice how the dashed box, which represents that parent partition, now includes the unallocated portion.

  1. Now select the actual root partition to resize.

  1. Right-click and select Resize, this time you will have the option to increase logical volume size. Enter a large value, let gparted compute the max. Click OK. You will now see a second pending operation, and the graph reflects the new (unapplied) size.

  1. When you are ready, click the green checkmark to apply all pending operations. Success:

Indeed, df now shows new size of root partition (/dev/sda5 in my case), hurray!

Last updated