Friday, July 27, 2012

Expanding VMWare Disks

If you use VMWare Workstation and regularly develop with VMs, odds are you will need to expand your VMWare Workstation disk at some point in time.

Unfortunately, there is one MAJOR limitation with expanding VMDK files--you cannot have any snapshots!! 

So, if you DO have snapshots in place, you can do one of 2 things:
  1. Clone the existing state of the virtual machine to a new virtual machine
  2. Delete all existing snapshots
Either way you decide, you will eventually have to expand the VMWare Disk to accommodate additional files, programs etc.

So, there are essentially 2 ways to accomplish this:

  1. Use the VMWare Workstation Console
  2. Use the command line (or preferably PowerShell) to accomplish this.
First and foremost, the way to expand the VMWare Disk through the GUI Console is the following:

  1. Open the VMWare Workstation console
  2. Open the target virtual machine
  3. Click on Edit virtual machine settings
  4. Select the Hard Disk for the virtual machine
  5. On the right hand pane, hover over the Utilities menu and select the Expand menu item
  6. When the Expand dialog opens, enter the new target disk size
  7. Wait until the disk is fully expanded


The main problem with the above approach is that the Expand process is modal and thereby blocks all other activities within the VMWare Workstation window preventing the launch of any additional virtual machines while that operation is taking place.

So, of course, a more appealing approach is to instead use the command line utility in conjuction with PowerShell.

The tool responsible for expanding VMWare Disks is called vmware-vdiskmanager.exe which can be found at this path:  "C:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager.exe" 

The sample command can be found by entering /? at the command line:

vmware-vdiskmanager.exe -x 36GB myDisk.vmdk

$vdiskMgr = "C:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager.exe"
$srcDisk = "C:\Virtual Machines\Windows2K8R2\Windows Server 2008 R2 x64.vmdk"
$expandSwitch = "-x"
$targetSize = "80GB"

#Run VMWare Expand Disk Command
Write-Host $vdiskMgr $expandSwitch $targetSize $srcDisk
& $vdiskMgr $expandSwitch $targetSize $srcDisk

No comments:

Post a Comment