Sometimes the disk space in the guest OS just becomes too small.
These example commands are tested with Windows 7 as the host environment, running VirtualBox 3.6.8 and Ubuntu Linux (32-bit) as the guest environment.
Getting information about the virtual machine:
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" showhdinfo \
"C:\Users\paazmaya\VirtualBox VMs\Ubuntu 2013-05\Ubuntu 2013-05.vdi"
This yields output similar to:
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)
Out 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"
The output shows a progress bar:
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 parameter expects MegaBytes; adding ~2 GB to the existing capacity results in 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 indicates the new capacity:
Capacity: 14480 MBytes
Upon starting VirtualBox Manager, you should see the updated disk size for the 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 capability 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 it is stopped. At the time of writing, the latest CD image version was gparted-live-0.18.0-1-i486.iso, released on February 20, 2014.
Please note that the boot order needs to be changed so that the CD is used first.
Once GParted has loaded, use it to resize the existing partition over the new empty space. There might be a swap partition inside an 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
