How would I shrink a macOS guest VDI?

Discussions about using Mac OS X guests (on Apple hardware) in VirtualBox.
granada29
Volunteer
Posts: 691
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: How would I shrink a macOS guest VDI?

Post by granada29 »

SteveMacGeek wrote:@granada29 -- So -- to be clear -- in the following diskutil list, APFS Volume Prezdrive is my mounted boot volume. Its Device ID is disk1s1 -- what Disk Utility refers to as the "BSD device node", correct?
Yes that is correct - I would strongly advise against touching any of the 'hidden' volumes - those which don't show up in the Disk Utility application and definitely steer clear of any 'Container' volumes.

I would also suggest (as in fact I did) that you make a copy of the .vdi file before making any changes. It is safe to delete the copy after you have succeeded with the "compact" and verified that the VM still boots.
SteveMacGeek
Posts: 72
Joined: 15. Oct 2019, 22:11

Re: How would I shrink a macOS guest VDI?

Post by SteveMacGeek »

@granada29 -- not sure if you can see the image / screenshot I made, but I had the exact same failure attempting to do:

First, I checked the device ID in Disk Utility. It was disk1s1.
Then I confirmed it using diskutil list (see image, below).

Then:

Code: Select all

sudo su -
diskutil secureErase freespace 0 disk1s1
It started an erase, got 34.4% of the way through the process, then the VM hung and was completely dead.

The volume I was secure erasing was supposedly only 13.1 GB, and Get Info said there was 29.29 GB of available space (out of a capacity of 42.74 GB). So I don't think it ran out of space creating that temporary file.
Image from secure erase failure
Image from secure erase failure
SecureErase failure.jpg (120.02 KiB) Viewed 5751 times
So I think there's still a missing piece here. (fortunately, I had done this on a clone!)

ADDITIONAL NOTE: I WAS able to re-start that VM. Not sure if it is somehow damaged. Or not.

Stephen
Last edited by SteveMacGeek on 28. Oct 2019, 01:33, edited 3 times in total.
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: How would I shrink a macOS guest VDI?

Post by socratis »

SteveMacGeek wrote:the IMG tag appears not to be working
The IMG tag works only for files in the forums, no 3rd party sites allowed, to prevent spam.
SteveMacGeek wrote:but here's a link to a JPG of the image
Please attach the image locally in your response (see the "Upload attachment" tab below the reply form). Not a lot of people will go to 3rd party sites. Plus, it's more convenient if the image goes along with the message...

That's a picture of a Terminal output BTW. Best if you copy/paste the text instead of the image...
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
SteveMacGeek
Posts: 72
Joined: 15. Oct 2019, 22:11

Re: How would I shrink a macOS guest VDI?

Post by SteveMacGeek »

Best if you copy/paste the text instead of the image...
Wish I could. But, as I mentioned -- the vm froze. So all I could do was take a screen shot.

Stephen
SteveMacGeek
Posts: 72
Joined: 15. Oct 2019, 22:11

Re: How would I shrink a macOS guest VDI?

Post by SteveMacGeek »

@granada29
@socratis

SUCCESS!

Not sure if I should've just edited my above longer posting, but...

...it APPEARED TO WORK. In that, after making sure the frozen VM booted and passed a Disk Utility scan, I shut it down and tried to --compact.

The ORIGINAL .vdi (that I tried to secureErase freespace) was 27 GB.

The size of the .vdi AFTER the --compact operation: 18.3 GB.

So regardless of whatever went wrong with the secureErase freespace command, it now was able to compact by 8.7 GB.

AND -- as a note: this was on a CLONE of the VM, which also had a 27 GB .vdi. The clone operation should've done a --compact, but since that had no effect, I guess it's safe to assume the secureErase must've worked (to some extent). -- even if it appeared to freeze.

Thanks for all your help!

Stephen
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: How would I shrink a macOS guest VDI?

Post by socratis »

Great, it seems that the command:
  • 
    diskutil secureErase 0 <DeviceID>
would be the way forward. The disadvantage is that the User Manual would have to stop using the specific command and move to something more generic, something similar to what it talks about for the Linux and Windows counterparts, because the User Manual can't have specific cases.

I still insist that the problem is with Apple. When I want to secureErase with zeroes my "/", that means I want to secureErase my main HD and all its locally mounted partitions and their children, like "/Users" and "/tmp". Simple. It's just that someone forgot to check that aspect when they migrated to the APFS scheme.

Someone should file a bug report with Apple. 'SteveMacGeek', how 'bout it? ;)
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
rpmurray
Volunteer
Posts: 918
Joined: 3. Mar 2009, 00:29
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Windows 7, Mac OS X (various flavors)
Location: Between Heaven and Hell

Re: How would I shrink a macOS guest VDI?

Post by rpmurray »

socratis wrote:[*]If this finding of yours works with previous guests, from 10.16 to 10.13, and it works for 10.14/15 as well, then it's something to definitely consider! It's going to make the instructions in the User Manual a tad more awkward, but who cares... ;)
10.16? Has Apple already released a beta of the OS that comes after Catalina? :D
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: How would I shrink a macOS guest VDI?

Post by socratis »

Hey 'rpmurray', besides the "Thank you" and the acknowledgment in the original post, I have one word for you:
  • :P
Seriously now, thanks for spotting that. And AFAIK, we're in the 15.1 beta for the developers, I'm pretty sure that a 10.16 is out there already; it's got to be ready for sale release in 11 months... ;)
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
ant
Posts: 334
Joined: 9. Jul 2007, 20:02
Primary OS: MS Windows other
VBox Version: OSE other
Guest OSses: Windows and macOSes
Location: An Ant Farm
Contact:

Re: How would I shrink a macOS guest VDI?

Post by ant »

I'd like to see VirtualBox have a compress VM GUI option like VMware Fusion does. IIRC, it had this option for all guest OS VMs including Windows.
Defective
Posts: 6
Joined: 10. Jun 2020, 03:34

Re: How would I shrink a macOS guest VDI?

Post by Defective »

Just wanted to report that granada29's method above worked perfectly for me, no errors at all. Virtualbox 6.1.10, MacOS 10.15.5 Host, MacOS 10.14.6 Guest.

Reduced a 97 GB .vdi file down to 61 GB.

Thank you!
Post Reply