How to Reduce the Size of a VMware Server 2.0 Virtual Disk

From Virtuatopia
Revision as of 20:21, 27 October 2008 by Neil (Talk | contribs)

Jump to: navigation, search

This HowTo covers the steps necessary to shrink a VMware Server 2.0 virtual disk. Two techniques are available, one involving VMware Tools and the another using the commandline vmware-vdiskmanager tool. Both approaches will be covered in this guide.

Before beginning this process it is important to understand a few points:

  • Shrinking currently only appears to be supported on Windows hosts. The VMware documentation states that shrinking is not available on Linux hosts.
  • There must be no current snapshots of any virtual machines which utilize the virtual disk.
  • If the virtual disk is configured as Independent it must be in Persistent Mode.
  • Shrinking involves discarding the majority of any unallocated space within the virtual disk. As such, it is not possible to dictate the amount by which the disk should be shrunk.
  • Shrinking reduces the amount of space a virtual disk currently occupies on the host system. It does not reduce the size of the disk as far as any guest operating systems using the disk are concerned. When more disk space is needed by a guest, VMware increases the size of the virtual disk image to accommodate the guest. This process is repeated in increments as more space is needed until the maximum specified virtual disk size is reached.





Shrinking a Virtual Disk from the Command Line

The size of a VMware virtual disk may be reduced from the command line using the vmware-vdiskmanager. If the disk to be shrunk is pre-allocated it must first be converted to a growable disk, the syntax for which is:

vmware-vdiskmanager -r <oldfilename>.vmdk -t <type> <newfilename>.vmdk

where <oldfilename>.vmdk is the name of the virtual disk image file to be converted, <type> is the number from the above table indicating the target virtual disk type, and <newfilename>.vmdk is the name of the new, converted file.

For example, to convert a virtual disk image file called win2008-1_2.vmdk to a growable disk called new.vmdk the following command would need to be executed:

vmware-vdiskmanager -r  win2008-1_2.vmdk -t 0 new.vmdk

The next step is to prepare the virtual disk for shrinking. To do this, the disk must be mounted with a drive letter on the Windows host. This can be achieved using the VMware DiskMount Tool which is available for download from www.vmware.com/download/ws/#utilities. Once installed, a virtual disk may be mounted using a command similar to the following:

vmware-mount G: "D:\VirtualMachines\Win2008\Win2008.vmdk"

Once the virtual disk is mounted using a suitable drive letter (G: in the above example), the disk must be prepared for shrinking:

vmware-vdiskmanager -p G:

Once the disk has been converted and prepared, the size may be reduced, using the -k command line option. For example:

vmware-vdiskmanager -k new.vmdk 

To subsequently unmount the virtual disk from the host, run the following vmware-mount command:

vmware-mount G: /d

Shrinking Virtual Disks Using VMware Tools

If VMware Tools are not currently installed on the guest operating system, steps to perform the installation are outlined in Understanding and Installing VMware Tools.

Accessing the VMware Tools Control Panel

Once the VMware Tools are installed into the guest operating system of a virtual machine using the virtual disk, the shrink process is initiated using the VMware Tools Control Panel.The VMware Tools control panel provides a graphical environment in which a variety of VMware Tools settings may be configured and virtual disks reduced in size (although this feature is not available for pre-allocated virtual disks).

The default configuration for VMware Tools on Windows should have placed a VMware Tools icon in the Windows notification area in the bottom right hand corner of the Windows task bar (where the date and time are typically displayed) and also as an icon in the Windows Control Panel (accessed via Start->Control Panel).

The following figure illustrates a taskbar from a Windows server 2008 desktop containing the VMware Tools icon (the second icon from the left in the notification area):


The Vmware Tools icon in the Windows notification area


Once the taskbar icon has been located, double click on it to invoke the VMware Tools control panel interface. When loaded, the control panel will appear as follows:


The VMware Tools Control Panel

Shrinking the Virtual Disk

The shrink tab of the VMware Tools control panel allows virtual disks associated with the virtual machine to be reduced in size by reclaiming unused areas on the disk. In the first instance, free space on the disk is reclaimed within the guest operating system. Subsequently, the virtual disk image on the host file system is then reduced in size by the VMware Server software.

To shrink the disk, select the Shrink tab of the VMware Tools Control Panel. Within the Shrink page, select the disk and click on the Shrink button. A number of confirmation dialogs will be displayed seeking confirmation that the size of the disk is to be reduced. Once confirmation has been received, VMware Server will reclaim unused space on the disk and reduce the size of the physical virtual disk image (.vmdk) file on the host system.