Lately I've been setting up a lot of virtual machines. It is time-consuming and frustrating but the end results are extremely useful. I discovered that using Windows 2003 R2 consumes a lot of hard disk space. I started with an 8 Gb virtual hard drive and before I knew it I ran out of space. Of course, depending on the VM I needed Microsoft Office, or Visual Studio, or SharePoint, or SQL Server, or BizTalk, or all of the above. I developed my base virtual machine first and then sysprep-ped it and then started installing all of the requisite software.

Once I realized there was no way the VM would survive with limited disk space, I set out to increase the virtual disk capacity. Unfortunately you can't resize the partition through Windows but you need to download a partition editor to do this.

Step 1: Resize the virtual hard disk with "vmware-vdiskmanager"

Open a command prompt (I like Console2) and change the directory to your VM image location. Use the "vmware-vdiskmanager -x" command to increase the hard disk size. I preferred to add the VMware directory to the path so I didn't have excessively long commands. For example, the command I used was:

SET PATH=%PATH%;C:\Program Files\VMware\VMware Server

vmware-vdiskmanager -x 16GB win2k3-sql.vmdk

vmware-vdiskmanager-grow

When the disk manager is finished resizing the disk, it looks like the following:

vmware-vdiskmanager-done

For reference, the help text from "vmware-vdiskmanager --help" is at the end of this post.

Step 2: Download GNU Partition Editor (GPartEd)

There were several recommendations on the VMware web site, but the GNU Partition Editor seemed to be the smallest and easiest way to edit the partition table.

Step 3: Mount the gparted ISO in VMware

Select the VM\Settings menu item

vmware-settings

vmware-console

Step 4: Reboot the VM and select the Boot Menu

You have to act fast when you reboot the VM. Click on the main window area to set the window focus and then press 'Esc' key to open the boot menu and then from the CD-ROM Drive. You need to click on the window to set focus because at this point in the boot process, the vmtools isn't loaded and can't provide the normal integration features.

gparted-boot

Step 5: Resize the partition

Select the primary partition and right-click on the partition and select "Resize".

gparted-main

Expand the partition

gparted-resize

When it is finished, it displays the results

gparted-results

Step 6: Reboot the VM

The VM will most likely check the disk since the dimensions have changed.

win2k3-chkdsk

Once it has finished, you should be done. Congratulations!


Reference

Here is the "vmware-vdiskmanager --help" output:

VMware Virtual Disk Manager - build 56528.
Usage: vmware-vdiskmanager.exe OPTIONS diskName | drive-letter:
Offline disk manipulation utility
  Options:
     -c                   : create disk; need to specify other create options
     -d                   : defragment the specified virtual disk
     -k                   : shrink the specified virtual disk
     -n <source-disk>     : rename the specified virtual disk; need to
                            specify destination disk-name
     -p                   : prepare the mounted virtual disk specified by
                            the drive-letter for shrinking
     -q                   : do not log messages
     -r <source-disk>     : convert the specified disk; need to specify
                            destination disk-type
     -x <new-capacity>    : expand the disk to the specified capacity

     Additional options for create and convert:
        -a <adapter>      : (for use with -c only) adapter type (ide, buslogic or lsilogic)
        -s <size>         : capacity of the virtual disk
        -t <disk-type>    : disk type id

     Disk types:
        0                 : single growable virtual disk
        1                 : growable virtual disk split in 2Gb files
        2                 : preallocated virtual disk
        3                 : preallocated virtual disk split in 2Gb files

     The capacity can be specified in sectors, Kb, Mb or Gb.
     The acceptable ranges:
                           ide adapter : [100.0Mb, 950.0Gb]
                           scsi adapter: [100.0Mb, 950.0Gb]
        ex 1: vmware-vdiskmanager.exe -c -s 850Mb -a ide -t 0 myIdeDisk.vmdk
        ex 2: vmware-vdiskmanager.exe -d myDisk.vmdk
        ex 3: vmware-vdiskmanager.exe -r sourceDisk.vmdk -t 0 destinationDisk.vmdk
        ex 4: vmware-vdiskmanager.exe -x 36Gb myDisk.vmdk
        ex 5: vmware-vdiskmanager.exe -n sourceName.vmdk destinationName.vmdk
        ex 6: vmware-vdiskmanager.exe -k myDisk.vmdk
        ex 7: vmware-vdiskmanager.exe -p m:
              (A virtual disk first needs to be mounted at m:
               using the VMware Diskmount Utility.)
kick it on DotNetKicks.com