VMware Communities
gringley
Hot Shot
Hot Shot

Shrinking APFS?

So in the good old days before APFS I could shrink Mac virtually disks with this script inside the VM:

#!/bin/sh

sudo diskutil secureErase freespace 0 Macintosh\ HD

sudo /Library/Application\ Support/VMware\ Tools/vmware-tools-cli disk shrinkonly

sudo halt

...but now with APFS I have to write 0 to freespace then shut the VM down and do the shrink from the host terminal.  Is vmware-tools-cli going to gain the ability to shrink APFS?

Tags (2)
17 Replies
gringley
Hot Shot
Hot Shot

....and in Catalina Beta the freespace 0 command no longer works?

Reply
0 Kudos
haralds
Enthusiast
Enthusiast

You need to check into snapshots or disable them.

Reply
0 Kudos
ColoradoMarmot
Champion
Champion

Definitely disable snapshots.

But, and more importantly, I'm thinking that secureerase freespace is depreciated for APFS drives.  Even on my host machine, when erasing an external drive, file still show up in recovery software. 

Reply
0 Kudos
gringley
Hot Shot
Hot Shot

The VM does not have any snapshots.

Reply
0 Kudos
TECH198
Hot Shot
Hot Shot

No it's not.. you can still secureerase freespace on APFS drives.. i have done it several times from the on my Mac running Mojave from Terminal:-

Screen Shot 2019-09-25 at 6.05.21 pm.png

(Macbook Air 256GiG SSD). I guess this is the only way since Mac OS guest "Clean up after shutting down virtual machine" only deletes snapshots for MacOS VM's.

I guess you can always create AppleScript, then double click to run.

Reply
0 Kudos
wila
Immortal
Immortal

I think they are talking about apfs snapshots..

and it looks like that you cannot disable it anymore in 10.13 and higher.

How to disable Local Snapshots - Apple Community

But you should still be able to remove local snapshots that have been made.

re. the original question.

Perhaps this thread helps:

Shrink an APFS virtual disk

--

Wil

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

I can do it in Mojave.  I am seeing I cannot do it in Catalina.

gringley
Hot Shot
Hot Shot

I had read that thread and have been using its correct answer to do my Mojave VMs.

Reply
0 Kudos
ColoradoMarmot
Champion
Champion

Yep, I've run that command many times.  Then I've run data recovery software and there's still many files available for recovery, so it's definitely not operating the same on an APFS SSD as it did on an HPFS+ SSD or metal disk.

gringley
Hot Shot
Hot Shot

I am seeing this is quite complicated.  In Catalina there are "Macintosh HD" and "Macintosh HD - Data" APFS volumes that are dynamically expanding and contracting in the existing free space of the disk.  The partition covers the whole disk.  If you have not been here before, Macintosh HD contains the OS, and Macintosh HD - Data contains home folders.

Screen Shot 2019-10-13 at 5.46.30 PM.png

Arguably shrinks could be easier if the VMware utility understood the new scheme and shrunk away the free space?  Maybe even automatic after shut down like the Windows VMs have? Otherwise how would one get into that free space to zero it if the partition already covers it?  Could the current VMware utility even see that?

In Mojave it is still a single APFS Volume and the old ways thus work.

Screen Shot 2019-10-13 at 5.52.48 PM.png

MichalKolar00
Contributor
Contributor

Hello everybody,

did anybody figure out how to shrink Catalina VM? No luck for me... but after the VM upgraded from 10.15 to 10.15.1 it grew a lot so it would be great if she can lose some fat.

Reply
0 Kudos
persfu
Contributor
Contributor

This is what I did:

Clone to a new vmdk using CCC, it will shrink from 25GB to 15GB for a clean installed Catalina OS

Reply
0 Kudos
AlessandroDN
Enthusiast
Enthusiast

This is what I did - essentially going back in the early Linux days 😕

- within the VM create a "zero" file in your home folder:

dd if=/dev/zero of=/Users/alessandro/zero.bin bs=1m

- after the dd completed (you receive a warning that disk is running out of space), delete the zero.bin file

rm /Users/alessandro/zero.bin

- shut down the VM and shrink the VMDK:

/Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -k <VMDK_DISK>

ColoradoMarmot
Champion
Champion

You know, that's brilliant.  I use that to migrate physical to virtual, but didn't even think about it for shrinking.

Reply
0 Kudos
gringley
Hot Shot
Hot Shot

Can you explain how you did this using CCC?  CCC support looked at this thread and they don't how you would have done this?  Thanks!

(Sorry I did not see your reply the first time.  I will see if I can reproduce this over the weekend.)

Reply
0 Kudos
gringley
Hot Shot
Hot Shot

This is solved in Shrink an APFS virtual disk

Reply
0 Kudos
scott28tt
VMware Employee
VMware Employee

Moderator: Comments posted by another user on this thread related to running MacOS on VMware Workstation have been deleted, running MacOS on non-Apple hardware (such as a Windows system) is a violation of the Apple EULA.


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos