Workbench

October 20, 2023

Expanding disk space for virtual Elementary OSx machine in VirtualBox

All my experiments and development are happening in virtual machines on Virtualbox. Up to last month, I never had a problem with disk space in my virtual machines This time I got OS warnings that my root disk space was filling up and the dynamically allocated disk space did not increase itself. After trying to figure out, what was going on, I decided to manually expand the drive.

Unfortunately it was not that simple as just expanding the virtual disk. You also needed to expand the partition, logical volume and file system.

Disclaimer: Use at own risk. I’m not responsible for any loss of data or damage that might occur by following the proposed steps.

Expand the virtual disk

The most simple task.

  • Shutdown the virtual machine.
  • Backup the disk file.
  • Open Virtualbox and goto ‘File -> Tools -> Virtual Media Manager’

Virtual Box Screen

  • Select the disk and move the slider towards the right to expand your disk, then press ‘Apply’ to execute.
  • Relaunch your virtual machine.

Expand the partition

Next step is to expand also the partition to use the newly defined space. This is best done by using a partition manager like GParted.

  • To install GParted:

sudo apt install gparted

  • Open the tool and select the data partition

GParted

  • Right-click on the visualization and select ‘Resize/Move’ from the menu.

GParted Resizing

  • Move the black arrow to the right, to claim free space and expand the partition. Take note of the added size in Gb, you will need it later.
  • Click on ‘Resize’ and then execute the action by clicking the green checkmark in the toolbar.

Expand the logical volume

  • Open your terminal and let us note the filesystem name:

sudo df -k

df command

  • Look for the filesystem that is mounted on root (/): /dev/mapper/data-root.
  • We’ll expand now the logical volume with the size your noted before and the filesystem name:

sudo lvextend -L +1G /dev/mapper/data-root

lvextend command

Expand the file system

  • Last step is to expand filesystem to the boundaries of the logical volume:

sudo resize2fs /dev/mapper/data-root

resize2fs command

Check your work

  • To check if it is successful we can re-use the df command and look at the size of the filesystem. This should have increased with the correct amount.

sudo df -k

check df command

← Return to all blog posts