Posts Tagged virtual

Increase Size of Hard Disk in VirtualBox

I quite like VirtualBox, originally from Sun, now Oracle – probably because it is free!  But seriously, it isn’t a bad little system and desperately needed for desktop use if nothing else (I truly welcome the day when every PC comes pre-installed with a standards-based virtual machine and the operating system is installed inside that virtual machine – allowing one to (a) install other operating systems to execute concurrently very easily, and (b) to move a nicely setup environment from one PC to another without the enormous hassle of re-installing and re-configuring everything all over again.  Anyway, back to the story at hand).

I very easily created a Ubuntu 9.04 virtual machine, and like many other people, I set the virtual hard disk size too small, as I found out in the end.  I set it to 8Gb, thinking that for “test” purposes that would be fine.  As is always the case, I loaded software after software package, et voila, the 8Gb is almost completely gone, to the stage that ubuntu starts complaining about not enough disk space to do things or upgrade to 10.04.

So, I dive into the world of trying to increase the size of a virtual hard disk in VirtualBox.

Firstly, the VirtualBox documentation does say that you can not do it.

The documentation also has references to other possible solutions, such as VBoxManage clonehd etc etc – all of which appear to be red herrings.

Searching across forums etc reveals the following basic pattern:

  1. Create a new empty virtual hard disk of the required (new larger) size, using the VirtualBox Virtual Media Manager (under the File menu of the main VirtualBox program).  This can be a dynamically expanding or fixed size disk;
  2. Attach this new disk to the existing virtual machine image, as a secondary disk.  For ubuntu purposes, the original diskj should generally be /dev/sda and the newly attached disk should be /dev/sdb, assuming that you only originally had a single disk in your setup and only attached this new disk as the next disk;
  3. Restart the virtual machine and copy everything from the old disk to the new disk using the command: dd if=/dev/sda of=/dev/sdb  Note that you must copy the whole disk, since the boot sectors etc must be copied across.  I did try to just copy the main os partition (ie /dev/sda1 to /dev/sdb1 but because the boot information was obviously not copied, when I came to reboot using the new disk it failed (obviously);
  4. Run ‘gparted’ (may need to install on the ubuntu system).  The new disk should be ‘sdb’.  You will see that it has a partition with the old disk on it, but also partitions for the boot sectors and for the linux swap and unallocated space.  The idea is to allocate the unallocated space to the end of the partition with the old disk in it, but in my attempts, gparted would not allow me to do so, since the linux-swap partition was in the way and could not be moved to the end or another position.  The old disk partition could also not be unmounted or mounted, since I think it was mounting to ‘/’, which was already used by ‘sda’.
  5. This then was the end of the road for me.  I decided that it would be more effective to install a new ubuntu in a new larger virtual hard disk (since I had already downloaded the new version of ubuntu) and jsut re-install whatever packages I had installed in the old disk.
  6. Obviously this would not be effective if the old disk contained systems and data of importance, rather than just test packages etc.  In this case, it is a relatively simply matter to attach the old virtual hard disk as a secondary disk to the new machine, then mount that disk from /dev/sdb and copy across (or re-use) whatever one needed.

, , ,

No Comments