Sunday, December 16, 2012

Extend a Virtual Box Virtual drive

I manage some laptops that run a small application in an Oracle VirtualBox (VB) Virtual Machine.  The VMs run Win 7 64bit and are built on a 60G fixed size vmdk drive.  Recently it became evident that 60G is not large enough to the do job anymore.  I had several  options for moving this VM to a larger drive.  I could build a new version of the VM from the ground up on a larger virtual drive.   The next option I could use would be to image the VM with Clonezilla, Acronis etc then lay that image down on a larger drive and then if necessary use gparted to grow the system into the larger virtual drive.  The last option was to use VB commands to grow the drive then use gparted to expand the OS to use the extra space. I chose the last option.  

First my virtual disk was a 60gig fixed vmdk which VB can not expand, the disk needs to be dynamic vdi.  Luckily VB has a way to deal with that situation using the “Virtual Media Manager”

In VB open the Virtual Media Manager from the File menu.  
Select the target disk from the list
Click the copy button on toolbar
Click Next (here you can select a different drive if necessary)
Select VDI> Next
Select Dynamically Allocated>Next
Change copy name if necessary and or browse to a different folder
Click the copy button

Depending on the source virtual drive size this can take a while.

Next grow the copied virtual drive to the desired size: For example grow mydrive.vdi to 90Gig

C:\Program Files\Oracle\VirtualBox\VBoxManage.exe  modifyhd --resize 90000 "C:\path\mydrive.vdi”

Next
Create a new vm in VB and select “use an existing drive” when creating the new system.  Browse to your newly expanded drive and finish the configuration.

If you boot the newly created vm at this point Windows will still show the original size of the virtual disk and if you use disk manager you will see the new space as unallocated.  You can use that unallocated space to make a new drive or you can use a tool such as GPARTED to grow the C:\ drive to use the space.

No comments:

Post a Comment