Hi All,
I want to shrink my Ventura Guest VM. But I find no way to erase the free space on the guest system.
sudo diskutil secureErase freespace 0 ...
does not work. I always get the message
Error with secure disk erase: Secure erase by writing a run of bytes to an APFS Volume makes no sense due to its possibly-unbounded size (-69489)
I understand, what it means, but finally this results in a 27 GB disk for a system without any installed apps and no data, without a change to reduce this size.
I'd be happy if someone has an idea how to resolve this problem.
Greetings and thank you!
Not Fusion snapshots - time machine/APFS snapshots inside the guest OS.
The command to find them is
tmutil listlocalsnapshots /
from terminal inside the guest
then you
tmutil deletelocalsnapshots /
to purge them
I am still using these instructions I got from an older message in this forum I think:
You would need to substitute your VM folder's names in there. I usually navigate to the VM folder so I do not have to type all that out to run the commands. I have had some problems with Big Sur VMs but everything else shrinks.
IMO APFS with its copy-on-write behavior, snapshots, lack of defragmentation (remember APFS is built for SSDs where defrags are not necessary) and multiple volumes sharing the same APFS container disk space is a poor candidate for shrinking with VMware's vmdk implementation.
You might be better off writing a file full of zeros (cat /dev/zero > filefullofzeros) until the APFS file system fills up, delete the file, then manually run vmware-vdiskmanager -k after shutting down the VM and Fusion. However this might not get you as much back as you think.
the only other thing I'd add is to remove any snapshots in the guest using tmutil from terminal both and after doing the zero out.
Thank you! But there are no snapshots.
Not Fusion snapshots - time machine/APFS snapshots inside the guest OS.
The command to find them is
tmutil listlocalsnapshots /
from terminal inside the guest
then you
tmutil deletelocalsnapshots /
to purge them
I am still using these instructions I got from an older message in this forum I think:
You would need to substitute your VM folder's names in there. I usually navigate to the VM folder so I do not have to type all that out to run the commands. I have had some problems with Big Sur VMs but everything else shrinks.
@Technogeezer wrote:You might be better off writing a file full of zeros (cat /dev/zero > filefullofzeros) until the APFS file system fills up, delete the file, then manually run vmware-vdiskmanager -k after shutting down the VM and Fusion. However this might not get you as much back as you think.
Writing a file of this size would first produce a VM of 80 GB because this is the minimum size that vmware allows for a macOS VM. Or am I wrong?
@gringley wrote:I am still using these instructions I got from an older message in this forum I think:
Execute the following command to defragment the disk (substitute VM name/Disk Name)
/Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -d macOS\ 10.15\ 64-bit.vmwarevm/Virtual\ Disk.vmdk
But doesn't defragmenting a VM on an SSD do a lot of unnecessary write access on the disk? I ask because SSD's don't have an endless life.
@TomsCat wrote:
Writing a file of this size would first produce a VM of 80 GB because this is the minimum size that vmware allows for a macOS VM. Or am I wrong?
You are not wrong. VMware’s virtual disks do not implement anything like the “TRIM” functions present on physical disks. TRIM enables an operating system to tell storage that a given area of disk is unused. Unfortunately without TRIM support VMware has to resort to this copy method in conjunction with defrag to release the most amount of space space back to the host OS.
Shrinking virtual disks will hurt SSD lifetime if you do it frequently. Doing it rarely won’t be as bad.
As a side note, Windows will no longer perform a full defrag on a file system it knows resides on SSD media for the same reason. It’s unneccary and shortens SSD life span.
Maybe...but I am only doing this 2-3 times a year so it is not high on my list for SSD wear. I looked today for the first time and after 3.5 years my VM SSDs are at 99% so I think its OK.
@gringley I definitely would consider what you do as “rarely”. I would be concerned about someone doing shrinks daily or weekly.
Thank you very much for these great hints!
I did what you described, but copied the VM to a hard drive to preserve my SSD, and copied it back after the whole process. Reduced the Ventura VM from 27GB to 19GB. This is fine for a VM that I back up and use infrequently for some software development testing, etc.
BTW, the VM boots faster after this.
Do you mind showing screenshots?
The command cat /dev/zero > wipefile; rm wipefile does not work for me.
It says cat: cannot find path 'c:/dev/zero because it does not exist.
i have 2 partition here C: drive consist of window 11 and E: drive as backup to save additional files, i have shrink about 40GB from E drive and they are now shown as grey or "Recovery Partition" under Disk Management.
Screenshots of what? And who do you mean?
Well, it won't work for you because that is a *nix command and you are attempting to run it on a Windows machine.
You may be able to reclaim space in a Windows VM if you are running the VM with the default of splitting disks:
If you wish to prevent the VM from using the entire allocated amount of the virtual disk, try reducing the size of the C: (and E:) partitions using WIndows Disk Management. Right click on the partitionin Disk Management, and select "Shrink". Don't shrink the size too far or else you'll run out of space - leave the partition reasonably sized so that you can accommodate reasonable anticipated growth.
Then run the steps again (you can skip the defrag). The VM won't consume disk space for unallocated partitions because it won't write anything there.
Thank you for your guidance, you are a Legend! The solution worked like a charm. I have recently started using VM and still getting my head around it, it makes much more sense to me now.
Regarding your other comments about reducing the size of a virtual disk, you were absolutely correct: it's not possible to shrink or reduce the pre-allocated space under 'Hard Disks.' Fortunately, this shouldn't be a concern as it only affects the C: drive space. This space is pre-allocated when you install the Window to the VM. The remaining space on the E: drive functions as shared storage between your VM and Mac without occupying space in the same way the C: drive does. So you can allocate the entire space and it still wouldn't really affect your Mac.
-Ben