How to: make your OpenSuSE 11.1 VirtualBox VM bigger

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.

  1. 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.
  2. Download SystemRescueCd.
  3. 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.
  4. 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.
  5. Hit <Enter> to boot SystemRescue.
  6. Enter startx at the command prompt, this will start X Windows.
  7. When X Windows starts, type gparted in the terminal that is open on screen, this will start gparted.
  8. In gparted, right click on the first partition, /dev/sdb1, and select “Copy”.
  9. Select the new, larger HDD from the drop down (top right).
  10. 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.
  11. Repeat steps 8-10 for the other partitions, /dev/sdb2 and /dev/sdb3.
  12. Select “Apply” (big green tick) from the toolbar.
  13. Wait for SystemRescue to do its stuff.
  14. Right click on the /dev/sdb2 partition on the new disk and select “Manage Flags”. Make sure the “boot” option is checked.
  15. Exit gparted.
  16. Exit the SystemRescue CD.
  17. Power off the VM.
  18. Download OpenSuSE 11.1.
  19. Create a new VM with the new HDD as its “IDE Primary Master” and the OpenSuSE 11.1 iso as its CD.
  20. Boot the new VM from the DVD and select “Rescue Mode”.
  21. Enter hdparm -i /dev/sda at the command prompt, this will pop up a bunch of information including the serial number of the new HDD – note this down.
  22. Enter mount /dev/sda2 at the command prompt, this will mount /dev/sda2 to /mnt.
  23. 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 -partx from each entry.
  24. Enter umount /mnt at the command prompt, this will unmount /dev/sda2. Make sure you aren’t in /mnt otherwise this command will fail.
  25. Power off the VM.
  26. Modify the settings of the new VM to remove the OpenSuSE 11.1 iso.
  27. Power on the new VM, which should now boot happily.