VMware Communities
trgeraedts
Contributor
Contributor

Cannot automate "VM->Manage->Clean Up Disks" from commandline or script

In my development area we make use of a frequent generation of a virtual machine that contains our latest software version installation.

I have recently automated the whole generation, including the zipping and distribution of the final virtual machine version.

I have come to notice that the virtual machine is about 55 GB large after installation and it compresses by ZIP to 25 GB,

but when I run the clean up tool in the VMWare Workstation (in the UI menu under "VM->Manage->Clean Up Disks"),

I can bring back the total size of the virtual machine to 45 GB after installation, and now it compresses by ZIP to 15 GB!

My problem is that I can only do this "Clean Up Disks" post step from within the VMWare Workstation UI and I haven't found a way to automate it in my scripting, either from the guest or the host.

With vmware-vdiskmanager I have tried to apply the '-d' and '-k' commands on all the *.vmdk files of the generated virtual machine, but this does not seem to give any size reduction.

With VMWare Tools I have tried to run a 'cleanup' script on the guest itself, but this does not seem to be possible due to the way it is set up I think.

Currently I'm almost out of ideas. The last resort would be to write a UI controlling script like AutoIT to control the VMWare Workstation UI.

I think that it must be possible with vmware-vdiskmanager, but I don't seem to get it right. Since I have to distribute the generated virtual machine over a 100mbit network, the impact of the 25 to 15 GB size reduction is huge!

I'm using VMWare Workstation Pro 12

0 Kudos
2 Replies
wila
Immortal
Immortal

Hi,

It helps if you mention what kind of guest OS you are running.

Windows / Linux / Something else?

If you want to use the vmware-vdiskmanager feature then you first have to zero out all the unused space from within in the guest OS.

Easiest really is to run the vmware-tools option from within the guest OS.


See: Shrink guest on hosted platform - VI-Toolkit  for the steps on each option.

As you say, there is no public API for the "VM->Manage->Clean Up Disks" alternative.

--

Wil

| Author of Vimalin. The virtual machine Backup app for VMware Fusion, VMware Workstation and Player |
| More info at vimalin.com | Twitter @wilva
0 Kudos
trgeraedts
Contributor
Contributor

Hi Wil,

Thank you for your reply Smiley Happy

I'm running Windows 10 on the guest system, and Windows 7 on the host system.

I have managed to shrink the disk from within the guest by using VMwareToolboxCmd.exe with the 'disk shrink' option,

but only after I cloned the original VM into a new version without snapshots.

The shrinking process takes quite some time, but the result is what I expected with a significant disk size reduction.

0 Kudos