How to expand VirtualBox's Virtual Hard Disk

Last month, I was trying to expand my Ubuntu 12.04 Guest OS's virtual hard disk size from 8 GB to 30 GB. After some time I realized that the process is not so straight forward. Finally I relied on two blog posts to finish my task. 

As mentioned in the first article, it's important to understand the prerequisites. 

Prerequisites:
  • Make sure you have the VBoxManage command-line tool installed on your host system.
  • Download the ISO for a GParted Live CD or else a Linux Live CD using a Linux distribution that includes the GParted partition editor utility.
  • IMPORTANT: If the virtual disk you want to resize is attached to a virtual machine with snapshots, you will need to delete these snapshots so that all disk state information is merged into the base virtual disk VDI file.

 I was using VirtualBox 4.3.4.  And, I partitioned the virtual hard disk by using GParted. Somehow, Linux Live CD didn't work for me. As indicated deleting snapshots is mandatory to proceed further. It may take a while based on the number of snapshots you have. 

Resize Virtual Disk Using Command Line:

As my host system was windows, I ran the following commands to expand the disk size. Syntax of the commands will vary based on the host system.

cd "C:\Documents and Settings\myusername\.VirtualBox\HardDisks"
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd OldDisk.vdi --resize 30000 

Expand the partition in the resized virtual disk:

I found reference#2 very helpful in this regard. The goal is to migrate the newly created space to precede swap partition. 

  1. Resize your extended partition to include free space
  2. Move the swap partition (linux-swap) to the end of extended partition
  3. Shrink (Resize) the extended partition to just fit linux-swap. At this point you can see the unallocated space lying between primary partition and extended partition. As author suggested, apply your steps now. 
  4. Now, resize the primary partition to include the unallocated space. Apply your steps. 
Resize your extended partition to include free space (partition in between ext3 and unallocated)


Move the right arrow until Free Space Following becomes zero

Click resize/move button


Move the swap partition (linux-swap) to the end of extended partition


Move the entire linux-swap block to the end block (until free space following is zero. New size remains the same)



Shrink (Resize) the extended partition to just fit linux-swap
Move left arrow until Free Space Preceding becomes zero



Apply your steps before going forward

Expand Primary Partition to include unallocated space

Resizing of virtual disk is complete. 

References: 

  1. Re-sizing A Virtual-box Virtual Hard Disk http://trivialproof.blogspot.in/2011/01/resizing-virtualbox-virtual-hard-disk.html
  2. Expand a Linux Disk with Gparted http://blog.mwpreston.net/2012/06/22/expanding-a-linux-disk-with-gparted-and-getting-swap-out-of-the-way/ (All the images in this post are from this blog)

Comments

Popular posts from this blog

Updating SourceData/ Data Source of the Pivot Table

Salesforce.com migration tool - Deploying Weblink and migrating files with special characters

Information Architecture - Setup your term store to scale