Monday, April 14, 2014

Expanding an Existing VirtualBox Disk

Issue

You have spent ages installing an operating system onto a VirtualBox virtual disk, but now find that after updates and software installations that most of the disk space has already been used. 

What to do?

Reinstall on a new larger VirtualBox virtual disk?
No!

Fortunately existing VirtualBox virtual disks can be resized with VBoxManage and then GParted can be used to resize the existing partition to fill up the extra space created by VBoxManage from within the virtual machine.

This page describes a simple procedure to use to increase the storage capacity of an existing VirtualBox virtual disk.

Procedure

This example procedure demonstrates how to increase the capacity of an existing virtual disk used in a Windows Virtual Machine.

Ideally you want your existing VirtualBox virtual disk to be in vdi format, but even it if it is in another format (vmdk in this example) its capacity can still be expanded by simply cloning the disk from vmdk to vdi format. A vmdk disk simply means an additional step (Step 1) not needed for a vdi disk.

Step 1
Skip this step if your virtual disk is already in vdi format.

VBoxManage clonehd Input.vmdk Output.vdi --format vdi

Step 2
VBoxManage modifyhd Output.vdi --resize 40960

Note --resize expects the new disk size in MegaBytes, here we show 40960 MB which is equivalent to 40 GB.

Step 3
Remove the original virtual disk from the Virtual Machine and replace it with the newly created (expanded) vdi virtual disk.

Step 4
Download the GParted.iso and then use it as bootable CD in the Virtual Machine.

Step 5
Boot up the Virtual Machine, which will then run GParted, resize the existing partition to fill the now larger disk. Then close down the Virtual Machine.

Step 6
Remove the GParted.iso from the Virtual Machine so that it will boot up normally.

Boot the Virtual Machine. Assuming it is a Windows Virtual Machine then Windows will give an error message.

Don't do anything!

Let Windows automatically update the virtual disk to the new size.

Let Windows make the necessary corrections.

Once Windows boots up you should have an expanded virtual disk that fully utilises the extra space you created in Step 2.

Finished!

Well Done!

======================================================

Further Reading

How-to-Geek : How To Enlarge a Virtual Machine’s Disk in VirtualBox or VMware

How to resize a VirtualBox vmdk file

Resize your /dev/sda1 disk of your Vagrant / VirtualBox VM

How to increase hard disk size after installing a guest OS?

======================================================