This might initially increase the size of your VMDK, but you can make it smaller eventually.
- In the Virtual Machine: "sudo pmset hibernatemode 0; sudo rm -f /var/vm/sleepimage"
- Defragment the "Macintosh HD" partition inside your VM. There are tools for that such as iDefrag. If you don't want an extra license for your VM, convert your virtual disk to monolithicFlat (Preallocate enabled and without the split), temporarily rename your "-flat.vmdk" to "-flat.dmg", mount it in the host system and Defragment it from the host system.
- Eject the DMG file and rename it back to vmdk. In VMWare Fusion, disable preallocation of the disk space and add back the "split into 2GB files"
You can also for Fusion 6, which might be of more help with the AHCI controller, but I haven't checked since I always preallocate my virtual machines (for performance reasons).
I can also for Fusion 6 what? It feels like there's a word missing there.
My bad, I really should read the post again before submitting. "You can also wait for Fusion 6".
Logic for that:
- Fusion presents the virtual disk drives to Mac OS X as AHCI disks
- Mac OS X uses the TRIM command to clear the unused sectors
- (Not verified, but expected) VMWare Fusion actually uses the sectors listed in the OS to reduce the size of the VMDK files.
The best thing you could do here is to ask the VMWare Fusion Beta community if AHCI trim actually reduces the VMDK file sizes.
One more note: from what I know, Mac OS X only enables TRIM for SSDs that have Apple in their name. So, in the VMDK you might want to add:
@disk:diskModel=APPLE SSD TS256B,diskSerialNumber=000000000000,diskSize=500107862016,diskVendor=APPLE
I loaded the VM into the Tech Preview and upgraded the vm hardware. Nothing's changed. Dunno how long I need to leave it, although I'm seriously doubting this will automatically reduce VMDK size as that doesn't seem to be a feature of any other guest.
I've checked, disklib in Fusion doesn't react to @disk or @partition entries. It only works for bootcamp disks (createType="partitionedDevice"). I'm attempting right now to create a new VMDK that does that. Interesting hack if it works.
First make sure you have a proper* backup of the Virtual Machine.
Delete any Snapshots.
In a Terminal from within the OS X Guest OS use the following command to prep for shrinking:
cat /dev/zero > wipefile; rm wipefile
After the prompt returns shutdown, not suspend, the Virtual Machine.
From a Terminal on the OS X Host use the following command to shrink the virtual hard disk.
vmware-vdiskmanager -k <Fully Qualified Pathname to the Virtual Hard Disk>
/Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -k /Users/WKZ/Documents/Virtual\ Machines.localized/Mac\ OS\ X\ 10.8.vmwarevm/Virtual\ Disk.vmdk
* It is a known fact that Time Machine is not 100% reliable backing up/restoring Virtual Machines under all circumstances/conditions. Also backing up Virtual Machines via Time Machine is disk/time intensive and wastes a tremendous amount of space for something that may be corrupt and worthless come time to restore it. At a minimum I would exclude Virtual Machines from Time Machine and with the Virtual Machines shutdown, not suspended, and VMware Fusion closed then manually copy the Virtual Machines Package(s) to an alternate location, preferably on to a different physical hard disk. Then keep the User Data that is stored within the Virtual Machine backed up off of the Virtual Machine on a regular basis so as to always have a current User Data Backup. If you have to restore a properly backed up Virtual Machine that is not as current at least you'll have a working Virtual Machine and current User Data to go forward with when you find out your Time Machine Backup of the Virtual Machine fails.
Figured this out last night, forgot to post back (it was 1AM by that time)
Nonetheless, thanks WoodyZ!
A slightly easier method - the shrink functionality is built into the VMware Tools command-line utility:
sudo /Library/Application\ Support/VMware\ Tools/vmware-tools-cli disk shrink /
This will first do a wipe of empty space one the file system (same as creating a zero-filled file) and show a progress in the guest Terminal. When that's done, the VMDK shrink will be invoked without shutting down the VM, and show up as a progress bar over the VM window.
The / is a path to the file system to wipe empty space on. If you have multiple partitions, you can wipe them individually and do a final shrink at the end:
vmware-tools-cli disk list to see the available locations for wipe
vmware-tools-cli disk wipe <location> to wipe each location (repeat multiple times), without the shrink operation
vmware-tools-cli disk shrinkonly to do the final shrink operation.
This is also explained by vmware-tools-cli help disk
I posted the old school method because I have a OS X 10.8 Virtual Machine that vmware-tools-cli disk shrink / refuses to function in and there are no Snapshots, so that not the issue and VMware Tools are up to date, even uninstalled/reinstalled. None of the disk commands will work so I assumed that it doesn't work in OS X. So I just now created a new OS X 10.8 Virtual Machine, installed VMware Tools and low and behold it worked. I'll have to examine the two Virtual Machine to see why one is working and the other is not!
FWIW, I just stumbled on sudo /Library/Application\ Support/VMware\ Tools/vmware-tools-cli disk shrink / in a MacInTouch posting as an alternative to vmware-tools-cli disk shrinkonly for shrinking Mac OS X VM's and tried it with remarkable results on Mac OS X 10.5 Server, 10.6 Server, 10.7 and 10.8 VM's. One of them even shrank close to two thirds, at least when used in conjunction with sudo pmset hibernatemode 0; sudo rm -f /var/vm/sleepimage at least once. And that's without needing to become root. Subsequent searching in the VMware Community for vmware-tools-cli disk shrinkonly brought me here.
I also tried vmware-tools-cli disk shrinkonly after plain shrink and found virtually no additional improvement. Altogether, I got a good 60 GB back! I discovered this just after I upgraded to Fusion 6.0.0 so I don't know if it'll work as well in Fusion 5. I had tried vmware-tools-cli disk shrinkonly alone in Fusion 5.0.3 and obtained almost no shrinkage so the effectiveness of plain shrink is really good news.
If it helps at all, the exact method I did was run Erase Free space in the VM via Disk Utility, then shut down the VM and did this at Terminal:
cd /Applications/VMware\ Fusion.app/Contents/Library/
./vmware-vdiskmanager -k /Users/Entegy/Documents/Virtual\ Machines.localized/OS\ X.vmwarevm/OS\ X.vmdk
I just compared VM sizes before and after running just the sleepimage and disk shrink commands in 10.7.4 and 10.8.5 VM's using a bootable backup for "before."
10.7 went from 24,691,617,585 bytes to 8,982,231,754 and 10.8 went from 41,680,058,903 bytes to 13,146,938,120 bytes! What kind of size reductions did you see using your method?
In VMware Fusion 6.0.4 with Mac OS X 10.9.4 as the host, Mac OS X 10.10 as the guest, and VMware Tools installed in the guest OS, of course, you can shrink the virtual disk at once with the following command issued in the command line of the guest OS:
sudo /Library/Application\ Support/VMware\ Tools/vmware-tools-cli disk shrink /
The command is no different than the suggestions provided so far in this and other discussion threads, it will zero out the virtual disk, but then the difference is that it will automagically launch the virtual disk shrinking process from the virtual machine without need for user intervention. Once complete you can shut down the virtual machine or keep it powered.
For reference, the equivalent command for Linux as a guest OS in VMware Fusion is as follows:
sudo vmware-toolbox-cmd disk shrink /
If you are interested on variants just issue the verb help disk, as in :
sudo vmware-toolbox-cmd help disk (in Linux)
sudo /Library/Application\ Support/VMware\ Tools/vmware-tools-cli help disk (in Mac OS X)
You should get an output similar to this:
disk: perform disk shrink operations
Usage: /Library/Application Support/VMware Tools/vmware-tools-cli disk <subcommand> [args]
list: list available locations
shrink <location>: wipes and shrinks a file system at the given location
shrinkonly: shrinks all disks
wipe <location>: wipes a file system at the given location
Good luck everyone with your shrunk virtual machines.