VirtualBox does not support resizing its virtual storage devices. As a workaround, a new bigger VDI is created and the existing partition(s) are moved to the larger drive. This tutorial gives instructions on how to expand storage for Ubuntu Linux guest machine.
- create a new larger virtual hard disk in VirtualBox. Attach it to the VM
- boot the VM from a Live CD .iso (I used Ubuntu 10.10 desktop)
- check the device names using e.g. ‘sudo fdisk -l’. As expected, my old disk is /dev/sda, new is /dev/sdb. Change the names in the next step if needed
- copy the whole disk: ‘sudo dd if=/dev/sda of=/dev/sdb bs=1M’. Since the whole drive is copied, it should also take care of the boot sector, partition table, bootable flag etc.
- when complete, shutdown the VM, detach the old disk and start the system from the Live CD again
- move/resize the partition(s) using gparted utility. When finished, run file system checks. In my case, gparted refused to move the extended partition containing swap, so I deleted and created a new one in the end of free space
- if partitions were only moved or resized, their UUIDs should remain unchanged. If in doubt, list them with ‘ls -l /dev/disk/by-uuid’, mount the root partition and edit the contents /etc/fstab configuration there
- reboot