Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a 150 GB disk file (.vmdk, non pre-allocated) where my virtual machine is stored.

The file is currently 20 GB, but it is growing everyday, even though I'm not storing anything new in the guest file system.

I have been looking for hours for a way to reduce the maximum size of this disk, so that it never gets to 150 GB (I'd like to set the limit to 30 GB, and see what happens when the VM reaches this size).

What I have tried:

  • Converting the disk image with VMware Converter → this does not work, the tool only allows creating a full copy or a 'linked clone'.
  • Creating a new blank virtual machine of the desired size in order to copy the 20GB data onto the new .vmdk → I cannot find a way to perform the copy or even connect the new disk to my existing VM (so that I perform the copy using the guest OS).
  • Looking in the .vmx file to check if the maximum size was not set in plain text (it's not).

Although this task seems technically quite simple (there is no tricky shrinking involved, just a simple change of size limit), I'm really out of ideas here...

Is there a solution at all ?

share|improve this question
Since the partitions on the virtual disk are most likely created to fill the advertised space, “tricky shrinking” is indeed involved. – Daniel B Apr 30 '14 at 8:56

The usual procedure for reducing the size of a .vmdk disk is to:

  1. Defragment the disk via the guest, choosing a defragmentation mode that consolidates empty space at the end of the disk. For a Windows guest, you should empty the Recycle Bin and turn off hibernation and paging, returning them after the defragmentation is done.

  2. Zero all unused space on the disk.
    For Windows use sdelete : sdelete -c.
    For Linux : dd if=/dev/zero of=/mytempfile && rm -f /mytempfile.

  3. Shrink the disk (which may take quite a long time to complete).
    VMware Workstation : Menu VM / Manage / Clean up disks.
    Or use : vmware-vdiskmanager.exe -k [VMDK PATH].
    for ESX : vmkfstools --punchzero [VMDK PATH].

Converting the disk from growable to preallocated could stop its growing. This can be done using vmware-vdiskmanager with the -t parameter whose values are:

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

The following command will convert the .vmdk from growable to preallocated :

vmware-vdiskmanager -r current_disk_name.vmdk -t 3 new_disk_name.vmdk

If you wish to change the size of the disk, this should be done while the disk is still in growable format (examples here).

For more information see the Virtual Disk Manager User’s Guide.

share|improve this answer
This doesn’t reduce the internally advertised drive size, though. – Daniel B Apr 30 '14 at 8:54
@DanielB: No, it doesn't reduce the maximal size, just the physical size. Reducing the maximal size can be dangerous, as some OS cannot boot without some free space on the system disk. – harrymc Apr 30 '14 at 9:20
This is a useful technique I used to reduce the space occupied by the VMDK. However, this does not completely solve my problem, as if I want to keep the VMDK always under, let's say 30GB, I will have to periodically repeat the operation (which takes a long time indeed). – Sebastien May 1 '14 at 11:49
If the disk can always be slimmed down to the wanted size, meaning that the procedure above always works to reduce the size, then you could limit the size in the future by converting the disk to fixed-size. – harrymc May 1 '14 at 19:17
@harrymc Converting the disk to fixed size would suit my needs. I just did not find a way to do this with VMWare Workstation or Converter. – Sebastien May 4 '14 at 21:26

The file is currently 20GB, but it is growing everyday, even though I'm not storing anything new in the guest file system.

Because the OS and its application programs temporarily use lots of disk space for temporary files, page files, hibernate file and config files. Once they get deleted depending on the policy of the OS new sectors on disk are used at the next time. The VM allocate storage for the virtual disk from real disk whenever a new sector is used in the virtual disk. As the sector on virtual disk are always not reused by guest OS the VM thinks its a disk usage and give space from real disk and this will lead to growing virtual disk image.

Your question title is less likely to be solved as using such a tool without inspection of image may lead to total disaster. But you can prevent growing of the image beyond 30GB. There are many way to achieve the goal.

A. Use only 30GB partitioned and leave remaining as free space. If you already partitioned more space then you need to shrink/delete it, the create a new partition then dump it with zeros and punch it as described by @harrymc . As the space in unpartitioned area is never used virtual disk will never grow beyond 30GB.

B. Create a snapshot and restore to it after usage. After creating snapshot VM store data into a new image file. If you restore to it, without saving or making new snapshots, all changed data is deleted and thus space is freed.

C. Create a new virtual disk of maximum 30GB, add it as a new disk into your current virtual machine, move all data to the new virtual disk using a backup tool. You may use a live Linux for the cloning.

Recommended option is A

share|improve this answer

Why not simply set the size of the disk involved to 30GB from 150GB.

You'll have to set the sum of all partitions to be less than 30GB. You'll have to shrink the sizes of the partitions down as you go. There is a LOT of documentation on this site on how to shrink partitions down so I will not repeat this here AGAIN.

Why did you create a 150GB (thin partition) if you did not have the space to support it at maximum size? Seems like this is just asking for trouble.

share|improve this answer
I did not personally create the VM, this is why. – Sebastien Jun 29 '13 at 13:34
How do I shrink the disk itself? I have the partitions within the disk shrink down but vdiskmanager.exe -k [VMDK PATH] as suggested in another reply doesn't shrink the drive. – Aaron Franke Jul 10 at 8:35

There is a roundabout way of using VMWare Converter to create a new VM and smaller VMDK size, then convert the original VMDK to the newly created, smaller VMDK.

Shrink VMDK

Detailed steps here.

Note that any changes to the VMDK size will also need a corresponding update to the partition table.

share|improve this answer
This is a VMWare Workstation VM, and these advanced copy options are not offered by Converter for this type of VM. It just won't let me change the size of the disk. – Sebastien Jun 29 '13 at 13:33

This work only for sparse VMDK (NON-Pre-allocated) A defragmentation is required before shrinking to ensure that used space is contiguous

Defragmenting within Windows

In a Windows virtual machine, you must first run a disk defragment from within Windows. Defragmenting within Windows ensures that all of the used spaces are contiguous. You can then reduce the size of the virtual disk.

Shrinking the virtual disk

To shrink the virtual disk:

Open the VMware Tools Control Panel / Toolbox:

In Windows:

Double-click the VMware Tools icon in the system tray, or click Start >Control Panel > VMware Tools.

In Linux:

Open the terminal and run this command:


Note: In Workstation 9.x (Windows) and above, shrinking is automatically done while Cleaning up the disk. Therefore, this option is removed from VMware Tools Panel. Go to VM > Manage > Clean up Disks. This is not available in Linux version of VMware Workstation 9.x and later.

Click the Shrink tab. Select the drive you want to shrink. Click Prepare to Shrink, then follow the onscreen instructions. Caution: Do not shut down your virtual machine or the host machine while the disk is shrinking. Also, do not try to cancel the process. Interrupting this process can cause irreparable damage to your virtual disk and you may not be able to start your virtual machine again.

From VMWare Knowledge Base

share|improve this answer
Reading existing answers first avoids duplicate answers. – harrymc May 4 '14 at 18:23
Sorry, anyway I reposted it with the full procedure and the source. This may help him more – Jalal Mostafa May 4 '14 at 19:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .