Saturday, March 1, 2014

VirtualBox Virtual Drive not Expanding!

Setup:


  • VirtualBox 4.3.6 r91406
  • Host OS: Mac OS X 10.7.5
  • Guest OS: Ubuntu 12.04 32-bit

Problem:

I have an Ubuntu guest OS with a Dynamically allocated storage type virtual harddrive (.vdi). Initially, the capacity of the drive was 8GB, but after installing a couple of stuff, Ubuntu complains that there was no more space left!

Troubleshooting:

So I loaded Gparted to check the drive. Turns out, the virtual harddrive were partitioned into 6GB of primary partition and 2GB of swap. Not sure who did this (VirtualBox or Ubuntu), but reading around indicates that Ubuntu does this. To this day, I still don't know WHY VirtualBox didn't automatically expand the drive as I expected it to, which it did in the past (previous versions of VirtualBox). I couldn't find the answer online, but if anyone knows, please let me know.

Solution:

NOTE: this only applies to dynamically-allocated storage types. If your virtual harddrive was created as a fixed storage type, this does not apply.

1. Resize the drive using VBoxManage modifyhd

Use the VBoxManage modifyhd command in Terminal to manually resize the drive. 

 VBoxManage modifyhd     uuid|filename  
                         [--type normal|writethrough|immutable|shareable|  
                         readonly|multiattach]  
                         [--autoreset on|off]  
                         [--compact]  
                         [--resize megabytes|--resizebyte bytes]  
( --resize units in megabytes, --resizebytes units in bytes)
[source]

In my case, I resized the .vdi to 15GB (15360 MB):
  path_to_my_vdi$ VBoxManage modifyhd Ubuntu1204.vdi --resize 15360  

Output:
 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%  


2. Rearrange the partition using GParted

Just in case, you may want to backup your data if necessary. (Sorry, no screenshots for now)
  1. Shut down the Guest OS if not already
  2. Mount the GParted .iso file to your virtual CD/DVD drive
  3. Make sure the CD/DVD drive is prior to the Virtual Hard Drive in the boot sequence
  4. Boot the virtual machine
  5. GParted will ask a few options as it loads. Just hit Enter to all of them to get through the options - I think that works in most cases.
  6. Once GParted loads, you can see the partitions in the virtual drive
  7. I deleted my swap partition (Note: don't worry - none of these changes will be made to the drive until "Apply" is clicked. So it's safe to make/undo any changes.)
  8. Then I increased the capacity of my primary partition using the Resize/Move button (or right-click on the partition and choose Resize/Move).
  9. I left 2GB at the end of the partition as swap. To do this:
    1. Since my capacity is now 15GB, I resized my primary partition to 13GB
    2. Then, the remaining 2GB will say "Unallocated". Click on that partition and click "New" from menu.
    3. On the "New" window, on the lower right side, choose "swap" as the partition type.
  10. On the lower half of the GParted window, there's the list of actions queued. If you're happy with the results, hit "Apply" to apply the changes (NOTE: there's no turning back after this point!).
And that's how I work around manually resizing my dynamically allocated storage virtual hard drive in VirtualBox 4.3.6.

No comments:

Post a Comment