paazmaya.fi

The Website of Juga Paazmaya | Stories about Web Development, Japanese Martial Arts, Hardware prototyping and travelling

Resizing VirtualBox guest disk space

Sometimes the disk space in the guest OS just becomes too small.

These example commands are tested with Windows 7 OS as host environment, running VirtualBox 3.6.8 and Ubuntu Linux OS 32bit as guest environment.

Getting information of the virtual machine:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" showhdinfo \
  "C:\Users\paazmaya\VirtualBox VMs\Ubuntu 2013-05\Ubuntu 2013-05.vdi"

Which results something similar.

UUID:           42004b4c-9a4b-40e3-b0cb-53393c547303
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       C:\Users\paazmaya\VirtualBox VMs\Ubuntu 2013-05\Ubuntu 2013-05.vdi
Storage format: VDI
Format variant: dynamic default
Capacity:       12480 MBytes
Size on disk:   11429 MBytes
In use by VMs:  Ubuntu 2013-05 (UUID: 56fa9690-7d36-4e4c-b07b-31856881fc57)

For the sake of curiosity, how much does compacting the virtual disk file reduce its byte size?

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd --compact \
  "C:\Users\paazmaya\VirtualBox VMs\Ubuntu 2013-05\Ubuntu 2013-05.vdi"

Output is somewhat similar to:

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Checking the showhdinfo again, would show possibly changed size on disk, which in this example case got ~8 MB reduction:

Size on disk:   11421 MBytes

The --resize parametre expects MegaBytes, thus adding ~2 GB to the existing capasity would become 14480 MegaBytes.

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd --resize 14480 \
  "C:\Users\paazmaya\VirtualBox VMs\Ubuntu 2013-05\Ubuntu 2013-05.vdi"

Now showhdinfo states the capasity of that new size:

Capacity:       14480 MBytes

Once starting the VirtualBox Manager, there should be seen the new disk size for the given virtual machine, in its “Storage” info window.

After Ubuntu has started, it will still use the earlier sized disks, as it has no way of knowing how the increased hardware cabability should be used. While anything is running from the disk, it cannot be resized, thus some boot disk with partition editing tools should be used.

Gnome Partition Editor offers a Live CD which can be used exactly for this.

Download iso file, mount it as “Live CD/DVD” in the “Storage” settings section of the given virtual machine while is is stopped. At the time of writing, the latest CD image version was gparted-live-0.18.0-1-i486.iso, released in 20th Feb 2014.

Please note that the boot order needs to be changed so that the CD is used first.

Once the GParted has loaded, use it to resize the existing partition over the new empty space. There might be swap inside extended partition which needs to be moved first to the end of the empty space.

Grow /dev/sda1 from 11.19 GiB to 13.14 GiB