Enlarge your Virtual Machine’s Hard Drive!

The other day I had need to re-size a VMWare hard drive.  Following the sagely advice of www.googleityoumoron.com I turned to the Internet and was surprised no-one put forward a simple effective way (without resorting to third party applications) to perform this operation.

In the end, it turned into four simple steps, interspersed with insane amounts of mucking about, finding out and working around the caveats the various tools required.  So, my civic Internet duty this week is to present the simple steps.

As per all Internet references, I’d like to put in a disclaimer and say that you try these steps at your own risk.  There is no substitute for proper back-ups and I take no responsibility for the outcomes that occur if you attempt to follow my instructions.

I should also point out that I was trying to re-size a drive on a Windows XP Virtual Machine, with an NTFS drive.  Some of the steps I use will not work with other sorts of file-systems.

Step 1: Clone the machine with the drive you wish to re-size. 

This serves several purposes:

  • You should always backup your work, especially if you are going to be doing file operations beyond the ordinary. 
  • You will need a second virtual machine for one of the later steps in the process.
  • The disk re-size step will not work, if you have taken snapshots of the virtual machine.  For this reason, we will actually be resizing the cloned VM, not the original.

Step 2: Open a command prompt and run the vmware-vdiskmanager.exe tool. 

  • This should be located in the folder where VMWare installed to. 
  • The tool itself can perform all sorts of operations on the disk, such as defragmenting and renaming. 

It’s command line driven, and you will need to know the file-name that represents your HDD.  This is slightly harder than you may think.  In the VMWare workstation, edit the virtual machine settings.  This will display a settings dialogue with a list of the Devices specified for the VM.  Select the Hard Disk you wish to re-size and note the Disk file indicated on the right hand side.  It’s bound to be a long and cryptic name, so copy and paste the name. 

I actually recall that this quite often wasn’t the file name the utility wanted, but it was a good starting point…  (I had to run this several times until I got past the caveats of shutting down the machine / ensuring there were no snapshots etc – so my memory may be a little blurry on this point – Sorry!)

The command line itself is fairly simple:
vmware-vdiskmanager.exe -x 20Gb "disk file name.vmdk"
(of course you should substitute the size and file names appropriately.)
When this works, you will get a message that includes the heartening:

Disk expansion completed successfully


The command itself took around two seconds on my machine and most of this time is actually the time it took me to acknowledge that the command worked!  (I was kind of “punch-drunk” from the number of unhelpful errors I had received leading up to this point in time)

Step 3: Install the virtual disk to a different virtual machine.
The diskpart tool that ships as part of Windows will not allow you to extend the partition of the boot drive.  Here’s where the original VM is useful.
3a. In VMWare workstation, edit the virtual machine settings for the original VM.
3b. Click “Add” to add Hardware, and choose to add a Hard Disk.


3c. Click “Next” and choose to use an existing virtual disk.
3d. Click “Next” and then stumble around until you choose the right Virtual disk.
3e. Finish the wizard and start this virtual machine, after you have verified that both disks are now added.

Step 4: Re-partition the drive so you can use the extra space.
The next steps require an administrator account on the virtual machine with the two virtual disks.  If you want, you can verify that the disks are both recognised in the virtual machine, by referring to the Microsoft Management Console.  (found in Start Menu | Administrative Tools | Computer Management)
Select the “Disk Management” node of the tree view found under the “Storage” node.

MMC Disk Management

You will see that the second drive “Disk 1″ has an unallocated space after the “Healthy (Active)” partition.

4a. Start a command prompt (Start | Run | cmd) and/or run the diskpart command.
4b. Determine which drive we wish to extend, by typing list volume from the DISKPART prompt.
4c. Select the appropriate disk volume, by typing select volume # (where # is substituted for the correct drive number)
4d. Extend the partition to the full available space by using the extend command.  If we wanted to not use the whole partition, we could have specified the number of megabytes.
4e. Exit diskpart by typing exit.  (Who would have guessed that, eh?)

Diskpart in action

The extend command also left me dumbfounded by how quickly it completed!  A complete reference for diskpart and its many commands can be found in the Windows help file, and is worth checking before running the process.

And that is all there is to it!  Re-run the Microsoft Management Console to verify that the disk is now correctly partitioned.

MMC Again 

Shutdown this virtual machine, remove the second hard drive and then restart the machine where this drive is the system drive. You should now have an enlarged Virtual Machine Hard Drive.