Friday, April 29, 2011

Increasing disk size for virtualbox running Ubuntu

Yes, I am running Ubuntu in a VirtualBox, and have been refusing to upgrade to version 10.10 or even version 11, since I have no compelling reasons to do so (actually, I have good reason not to do so). However, end of last week, I hit to an issue with MySQL - a limitation that I will write in another blog entry.

Anyway, I did run out of disk space on my virtualbox guest. Came across a few web entries that discussed on how to overcome it, but most of them are applicable to Windows guest virtualbox setup.

Here are some of my attempts that didn't work out that well, and possible reasons:

1. Used Clonezilla

Strategy
Use Clonezilla to back up the old VM and restore it into the new expanded disk.

Outcome
Yup, I boot up my old version of Ubuntu using Clonezilla LiveCD and make a clone copy. Then boot up my new empty virtual image using Clonezilla LiveCD and tried to restore the image to the expanded disk image.

Reason
I was able to backup image of old Ubuntu VM, and managed to restore the image to the expanded VM volume, but when I boot up, it was not able to start up. This is due to GRUB loader. During the restoration of image, I briefly saw a message that there could be an issue since they detected GRUB and was not able to change to root to change some settings... I guess.

Result
Failed (you might have better luck than me)

2. Use GPart

Strategy

Create an empty (larger diskspace disk) virtual disk using VirtualBox Virtual Media Manager. Attached the larger virtual disk to the SATA port 1 (the old smaller virtual disk on SATA port 0). Mount GPart LiveCD and boot from it. Copy the old disk (/sda1) to the new disk (/sdb). Mark the new disk as bootable. Reboot with the new disk as primary (might also want to unmount the old disk).

Outcome
No problem with the copy and paste using GPart. No problem with the flag "boot" for the new disk. Just didn't boot after when switch to primary boot disk!

Reason
Unknown. Still figuring it out.

Here is what worked for me.

Background

I have the following:

1. Oracle VirtualBox 3.2.12 r68302
2. Ubuntu 9.10.2 (8 GB HD)

What I want to do is to add more hard disk space (increase to 16 GB HD).

4. Reboot the new VM ("MyLargerSecondVM") to see that things are still bootable and in order, but do note that the primary partition is still the same and has not been modified. The extra disk space has not been allocated yet.

5. Shutdown the VM after everything looks fine. Back up the VMs.

I copied all the files under "C:\Documents and Settings\user\.VirtualBox" to another secondary storage.

It is now time to resize the partition to fill up the entire new virtual disk.

6. Ensure that the boot order for the new VM ("MyLargerSecondVM") is (CD/DVD-ROM, Floppy, Hard disk) via Setting > System > Motherboard

9. Enlarge the primary boot partition. You might need to move the swap partition to the end of the disk before enlarging the primary boot partition. I did the changes in a series of small steps rather than applying all changes at one go. I actually hit to a slight problem initially if I will to consolidate all my steps.

10. Once the swap partition is moved to the end, and primary partition has been enlarged successfully, quit GPart and reboot. Remember to unmount the GPart LiveCD through Setting > Storage > IDE Controller > CD/DVD Device > [Select "Empty"]

11. Reboot "MyLargerSecondVM" and login. You can check that you have more disk space now. e.g.

this worked for me with vbox 4.1.18. but i did find a shortcut. instead of creating a new virtual drive in a new vbox, just backup your vbox, and then resize your current drive with the following command:vboxmanage modifyhd mysmallhdd.vdi --resize 50000(this command needs to be run in the same folder as your vbox drive, and you will need to add the path to vboxmanage)this will resize your current drive to 50GB. then boot from gparted image and move the swap to the end and resize main partition.