When you set up a VirtualBox HDD you get two options, a fixed size disk, or a dynamically expanding one. Despite having no good reason for doing so, when I set up my OpenSuSE 11.1 VirtualBox VM I opted for the former; I created a 12Gb virtual disk and installed OpenSuSE 11.1 onto that. Long story short, it was a big mistake, 12Gb was nowhere near enough. So what to do? I didn’t want to have to do a clean install and set up a new development environment, so I looked for a way port my existing VM into a new dynamically expanding virtual HDD – I found one too, but since the process wasn’t as straight forward as you might think, I have included the steps that I used here.
- Create a new virtual HDD in VirtualBox. I would recommend that you create a dynamic one and set the capacity to something far larger than you will ever need – remember that it won’t actually take up this much space on your host system unless you actually fill it with stuff.
- Download SystemRescueCd.
- Modify the settings of your existing VM to have the new virtual HDD as its “IDE Primary Slave” and the SystemResuceCd iso as its CD.
- Boot the VM from the CD. If your VM won’t automatically boot from the CD, don’t forget to press
<F12>to enter the Boot Menu and select it.
<Enter>to boot SystemRescue.
startxat the command prompt, this will start X Windows.
- When X Windows starts, type
gpartedin the terminal that is open on screen, this will start gparted.
- In gparted, right click on the first partition, /dev/sdb1, and select “Copy”.
- Select the new, larger HDD from the drop down (top right).
- Right click on the empty representation of the HDD and select “Paste”, you can use the slider to set the new size of the partition.
- Repeat steps 8-10 for the other partitions, /dev/sdb2 and /dev/sdb3.
- Select “Apply” (big green tick) from the toolbar.
- Wait for SystemRescue to do its stuff.
- Right click on the /dev/sdb2 partition on the new disk and select “Manage Flags”. Make sure the “boot” option is checked.
- Exit gparted.
- Exit the SystemRescue CD.
- Power off the VM.
- Download OpenSuSE 11.1.
- Create a new VM with the new HDD as its “IDE Primary Master” and the OpenSuSE 11.1 iso as its CD.
- Boot the new VM from the DVD and select “Rescue Mode”.
hdparm -i /dev/sdaat the command prompt, this will pop up a bunch of information including the serial number of the new HDD – note this down.
mount /dev/sda2at the command prompt, this will mount /dev/sda2 to /mnt.
- Using the editor of your choice (I used Vi), modify /mnt/etc/fstab and /mnt/boot/grub/menu.lst, replace all references to the old HDDs serial number with the new HDDs serial number. Be careful not to delete the
-partxfrom each entry.
umount /mntat the command prompt, this will unmount /dev/sda2. Make sure you aren’t in /mnt otherwise this command will fail.
- Power off the VM.
- Modify the settings of the new VM to remove the OpenSuSE 11.1 iso.
- Power on the new VM, which should now boot happily.