Yesterday I launched one of my virtual machines to find out that I am low on space. I wanted to expand the static (fixed size) disk but apparently this couldn’t be done on a static disk. Some posts indicated that one could clone the disk as a dynamic one and then resize that.
I wanted to resizing the vdi disk from 7GB to 12GB. To do this I
- converted the static disk into a dynamic disk using
vboxmanage clonehd disk-name.vdi new-disk-name.vdi
- resized the disk using
VBoxManage modifyhd new-disk-name.vdi --resize 12000 #12000 is 12000MB
- replaced the disks in the settings of the machine (ie; removed the old disk and added the new disk)
But this did not solve the problem. Albeit the disk is now dynamic and 12GB in size, still the additional space was detected as unallocated space in the virtual Ubuntu 12.04. Given that the unallocated space was added to the end of the partition table, there was no way of resizing the root partition.
Twenty minutes earlier I thought of it some more and I had another idea that seemed promising but a little risky. It goes as follows.
Since the filesystem is composed of a root partition and followed by a Linux swap I had to get rid of the swap partition first. Here’s what I did:
- Launched the machine and booted a (live) Ubuntu Saucy iso
- Launched Gparted
- Unswaped the linux swap partition (any ideas why it was locked?)
- Deleted the swap and the extended partition it was under
- Resized the root partition
- Recreated the extended and swap partitions
- Restarted the machine and booted into the virtual Ubuntu 12.04 and checked the disk in Disk Utility.
There you have it. It works and all it took was 10 minutes.
I am not sure if someone has written about this solution; I personally haven’t found it during my quick search but inspiration to solve the problem came from reading several thread posts mainly two on askubuntu  and stackoverflow .