Highlighted
Enthusiast
Enthusiast

Shrink an APFS virtual disk

Jump to solution

I'm running VMware Fusion 10.1.1 on High Sierra. 

I have a High Sierra guest and I'd like to shrink the virtual disk to reclaim space.

With Sierra (and older) guests, I would execute the following command inside the guest to shrink the disk:

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

But when I run that command inside the High Sierra guest (APFS virtual disk), I get the following error:

    Partition / is not shrinkable

What command should be used to shrink an APFS disk?

Thank you.

Tags (2)
1 Solution

Accepted Solutions
Highlighted
Contributor
Contributor

Working solution is:

cat /dev/zero > wipefile; rm wipefile

after this you can shrink volume using vmware-vdiskmanager.exe:

"c:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager.exe" -k macos.vmdk

View solution in original post

22 Replies
Highlighted
Enthusiast
Enthusiast

Could someone from VMware please answer this question: Does Fusion 10 support shrinking an APFS disk?

The only workaround I've found for the shrinking problem is to use HFS+ (Journaled) instead of APFS.  I accomplished that by creating a Sierra guest, then upgrading the guest to High Sierra with this command:

   "Install macOS High Sierra.app/Contents/Resources/startosinstall" --converttoapfs NO

Shrinking works correctly in the High Sierra guest with HFS+ (Journaled).

0 Kudos
Highlighted
Hot Shot
Hot Shot

Not that it's of any help but I've just run into the same issue. However, I'm using Fusion 8.5.9 with a guest upgraded to macOS 10.13.3 and the host is El Capitan running on a third party SSD. What surprised me is that Fusion 8 supports an APFS file system in a guest at all and I doubted High Sierra's Disk Utility telling me that before seeing your post. I have to wonder how well HFS+ gets along with a portion of it formatted in APFS, although Yosemite's Disk Utility finds no problem when verifying the drive.

0 Kudos
Highlighted
VMware Employee
VMware Employee

Please review KB Defragmenting, shrinking, and cleaning up VMware Fusion virtual machine disks (1001934) - https://kb.vmware.com/s/article/1001934.

Sincerely, Rahul Parmar VMware Support Moderator
0 Kudos
Highlighted
Enthusiast
Enthusiast

parmarr​ :   Thank you for the link, but that KB article appears it be inaccurate.

I have a new High Sierra guest with a sparse APFS disk, no encryption, and no snapshots. 

Attempting to shrink via the command line results in an error:

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

     Partition / is not shrinkable

The list command indicates that shinking is disabled:

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

     Shrink disk is disabled for this virtual machine.

     Shrinking is disabled for linked clones, parents of linked clones,

     pre-allocated disks, snapshots, or due to other factors.

     See the User's manual for more information.

None of those exceptions apply to my VM, so why is shrinking disabled?  Does "due to other factors" mean that shrinking is not supported for APFS?

Please assist.  Thanks.

0 Kudos
Highlighted
Enthusiast
Enthusiast

joemath,

Here is what I do for my 10.13 VMs

  1. From inside the VM using a terminal session I issue the following command (Replace HD name with yours)
    diskutil secureErase freespace 0 Machintosh\ HD
  2. Shutdown the VM and exit VMware Fusion
  3. Execute the following command to defragment the disk (substitute VM name/Disk Name)
    /Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -d macOS\ 10.13\ 64-bit.vmwarevm/Virtual\ Disk.vmdk
  4. Execute the following command to shrink the disk (substitute VM name/Disk Name)
    /Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -k macOS\ 10.13\ 64-bit.vmwarevm/Virtual\ Disk.vmdk

Hope this helps,

Carlin Smith

Highlighted
Enthusiast
Enthusiast

CarlinSmith​,

That worked.  Thank you!

0 Kudos
Highlighted
Contributor
Contributor

Carlin Smith's answer is perfect on my system.

I had just used Fusion 10.1.2 to create a MacOS X 10.13.4 VM. I created this VM by upgrading an existing 10.12 VM. Part of the upgrade converts the files system from HPFS to APFS. The bad news is that the install vmware tools wouldn't shrink the drive. CarlinSmith's post came to the rescue.

The basic procedure is to zero out the the empty space from within the OS, and then to use the VMware Fusion host based utilities to defrag and then shrink the vmdk. It worked great. Click the helpful button on that guy's post.

Cheers

0 Kudos
Highlighted
Contributor
Contributor

Just a quick heads-up, that this no longer works on High Sierra nor Mojave if your system is using APFS.

A 150GB disk that has 20GB of data on it, zeroed inside maOS from Terminal under Recover Mode, shrunk outside of Fusion, and defragmented using your previous suggestions, results in a 150GB .vmdk after all operations have completed.

It seems like an enormous waste of space, but it is what it is.

0 Kudos
Highlighted
Enthusiast
Enthusiast

This approach still works great for me. 

The host is a 2018 MBP running Fusion 11.0.2 and Mojave 11.14.3 with APFS .  I shrank two guest VMs running Mojave 11.14.3 with APFS.  In total, the shrink process freed up ~60GB of space on the host.

0 Kudos
Highlighted
Contributor
Contributor

I too can confirm that this solution works despite documentation alluding to the fact that shrinking is only supported for Windows hosts. This solution took my image from ~27GB down to ~17GB.

Thanks CarlinSmith​ !!!

0 Kudos
Highlighted
Contributor
Contributor

I had to use

diskutil secureErase freespace 0 /Volumes/Macintosh\ Macintosh HD

(note not Machintosh)

0 Kudos
Highlighted
Enthusiast
Enthusiast

The solution from CarlinSmith​ appears to be broken in macOS Catalina virtual machines.

This command no longer works:

diskutil secureErase freespace 0 Machintosh\ HD

Catalina creates separate APFS volumes for the OS and Data.  You can see this by running diskutil list:

     /dev/disk1 (synthesized):

        #:                       TYPE NAME                    SIZE       IDENTIFIER

        0:      APFS Container Scheme -                      +214.5 GB   disk1

                                      Physical Store disk0s2

        1:                APFS Volume Macintosh HD - Data     3.8 GB     disk1s1

        2:                APFS Volume Preboot                 83.7 MB    disk1s2

        3:                APFS Volume Recovery                528.9 MB   disk1s3

        4:                APFS Volume VM                      1.1 MB     disk1s4

        5:                APFS Volume Macintosh HD            10.6 GB    disk1s5

I tried these commands...

diskutil secureErase freespace 0 Macintosh\ HD

diskutil secureErase freespace 0 Macintosh\ HD\ -\ Data

diskutil secureErase freespace 0 /System/Volumes/Data

diskutil secureErase freespace 0 /Volumes/Macintosh\ HD

...but each results in one of the following errors:

Erasing freespace only works on mounted and writable volumes

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)

Anyone have an idea?

I'm running Fusion 11.5.0 on Catalina 10.15 host with Catalina 10.15 guest.

0 Kudos
Highlighted
Champion
Champion

I suspect it's related to the virtual volume for MacIntosh HD Data - haven't found a workaround yet, but it looks like we're stuck.  You'll also want to make sure you delete local snapshots before shrinking too.

0 Kudos
Highlighted
Enthusiast
Enthusiast

Thanks for the feedback, dlhotka​.

I posted to the Apple Developer Forums...

     "diskutil secureErase freespace" does... |Apple Developer Forums

...but I haven't received any feedback.

0 Kudos
Highlighted
Contributor
Contributor

Any updates?

How to fo this under Catalina?

0 Kudos
Highlighted
Contributor
Contributor

Working solution is:

cat /dev/zero > wipefile; rm wipefile

after this you can shrink volume using vmware-vdiskmanager.exe:

"c:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager.exe" -k macos.vmdk

View solution in original post

Highlighted
Enthusiast
Enthusiast

Has anyone confirmed alaska332​'s solution for Catalina?

I reverted to Mojave, so I can't easily test it myself.

The steps for Catalina would be:

  1. From inside the VM using a terminal session I issue the following command
    cat /dev/zero > wipefile; rm wipefile
  2. Shutdown the VM and exit VMware Fusion
  3. 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
  4. Execute the following command to shrink the disk (substitute VM name/Disk Name)
    /Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -k macOS\ 10.15\ 64-bit.vmwarevm/Virtual\ Disk.vmdk
Highlighted
Champion
Champion

Haven't tried it, but I expect it'll have one side effect and temporarily expand the virtual disk to it's full size, so make sure you have enough disk space on the host to handle it (and the extra space for the shrink process).

0 Kudos
Highlighted
Contributor
Contributor

Hi!

I tried yesterday, and the quick answer is that it works.
Host is Mojave and guest is Catalina.
You have to zero the empty space first. It’s mandatory. Should I add that this has to be made in the guest? Then stop the guest system. It doesn’t grow the size as asked before.
Next: defrag.
And finally: shrink.
Note that you need the size of free space equal of the original VM disc!

Thanks for your attention, and congrats for the right answer.
Hugs.