Resize a Linux Virtualbox Virtual Hard Disc on Windows

Resizing a virtual hard disc for Oracle's Virtual Box on Windows takes a few steps.

These are the steps that worked for me to expand the size of a .vdi for a Linux virtual running in VirtualBox under Windows 10.

Step 0: Backup your .vdi file.

No excuses folks - make sure you backup your .vdi file with your virtual machine in a powered off state.

Step 1: Disconnect the drive.

Go into the Settings of your virtual machine and, under "Storage", remove the disc from the machine

Step 2: Resize the drive

This is the tricky part, as Windows won't know about your VirtualBox files or utilities. It needs to be done from the command line, so start by running powershell.

The command you need is

.\VBoxManage.exe modifyhd 'C:\Users\chris\VirtualBox VMs\Ubuntu\Ubuntu.vdi' --res
ize 40000

inputting the path to your .vdi file as necessary. The command above expands the drive to 40GB.

This command must be run from within the C:\Program Files\Oracle\VirtualBox folder, so remember to cd to this.

Step 3: Reconnect the Drive

Back to VirtualBox settings, now reattach the drive to the virtual machine.

Step 4: Expand your partition(s)

Assuming you just have two partitions (/ and swap) then the swap partition is mostly likely in the way of you expanding your / partition. You'll need to remove it before you can expand the root partition.

I prefer to do this operation with a visual tool like gparted

sudo apt-get install gparted

Once you have gparted installed, run it as root

sudo gparted

Now, follow these steps to expand your root partition.

  1. Right click on the swap partition and delete it.
  2. Right click on the extended partition, that contained the swap partition, and remove it.
  3. Right click on the root partition and expand it, remembering to leave enough unused space for a new swap partition
  4. When the root partition has been expanded, right click on the unused space and create a new extended partition
  5. Right click on the new extended partition and create a new swap partition inside it

This will leave you with a number of changes to be applied by gparted. Click the green tick to apply them, sit back, and wait.

If this operation is successful, you should end up with an expanded root partition and a working swap partition.

Comments and Feedback on
"Resize a Linux Virtualbox Virtual Hard Disc on Windows"