Tuesday, August 6, 2013

Expand Your VirtualBox VM Disk Size

VirtualBox ver: 4.2.10
Virtual Machine (VM): Windows 7 pro, guest additions installed
Requirements: Ability to run a command prompt and VirtualBox as administrator (the usual problem with accessing VBoxManage).

Scenario:
I have a Win7Pro Virtual Machine (VM) with a 20 GB dynamically allocated storage disk (VDI) which only has about 2 GB of space left. I need to install a program on the VM which requires 2.5 GB of disk space. In short, I cannot install this program unless I increase the disk size.

So, in this post I’m going to increase the same disk (disk 0 or drive C) from 20 GB to 30 GB. This will give me the space I need with room to grow.

Start:
The only way to do this (currently) is to use the VBoxManage command prompt. Start VirtualBox as an administrator (right click on VirtualBox and select “Run as administrator”). Also, run a Windows command prompt as an administrator:

Right click on cmd.exe and select “Run as administrator”:

clip_image001

Now, find out where your VirtualBox installation resides (we are looking for the VBoxManage.exe file). For me it’s:

C:\Program Files\Oracle\VirtualBox

Here I can find the VBoxManage.exe file but upon double clicking it a command prompt quickly runs and disappears. That’s okay, this ‘executable’ file works in a Windows command prompt. In the windows explorer window, right click the address and copy the location.

clip_image003

Now you will need to go to this location in a windows command prompt (navigate to this directory). For me, the command is: cd C:\Program Files\Oracle\VirtualBox

And I just typed “cd”, a space and then right-clicked and pasted the address (from “Copy address” above):

cmd 1

As I’ve already mentioned, the machine I want to convert has a dynamically allocated storage size of up to 20 GB and is a Normal (VDI) type. I need to change this to 30 GB.

clip_image005

You can use the name of the VirtualBox but if there are spaces in the name you will need to surround it (the name) in quotes when you type it into the command prompt. You can also use the VirtualBox UUID. To find this, run:

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe list hdds

I did this since the name of the virtual machine I want to configure has spaces in it and it was just easier to find the UUID, copy it and paste it into the command prompt.

**UPDATE**

To help clarify:

  1. You need to close out of the VirtualBox GUI before running the below commands or else you’ll get thrown an error
  2. To find your UUID (as there are usually two listed in the command above), it should be the first set:
UUID

The UUID f or MY virtual machine is: c57c339f-0e9e-4c2e-9ba7-486ac5ff02e7

Your UUID will be different.

My final command:

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd c57c339f-0e9e-4c2e-9ba7-486ac5ff02e7 --resize 30720

Or: VBoxManage modifyhd <UUID>|<filename> --resize <megabytes>

Since I want to expand the VDI from 20 GB to 30 GB I typed in 30720 (30GB = 30720MB). Upon executing the command:

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd c57c339f-0e9e-4c2e-9ba7-486ac5ff02e7 --resize 30720
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
C:\Program Files\Oracle\VirtualBox>

it worked

Now you need to start the virtual machine and use a partition tool to adjust the main partition size. Since my VM is running Win7:

Right click: Computer > Manage

Navigate to disk management.

Here you can see that I now have 10.00 GB of Unallocated disk space available on Disk 0 (or drive C).

clip_image006

I right-clicked on the C: partition and selected “Extend Volume..”

Follow the windows wizard and bame! I just expanded my 20GB VirtualBox Windows 7 machine to 30GB.

clip_image007

Easy Peasy!

For more information, see:
http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi

-Cheers!

No comments:

Post a Comment