Reclaim disk space for OS X guest

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
tsp1965
Posts: 10
Joined: 26. Sep 2015, 10:47

Reclaim disk space for OS X guest

Post by tsp1965 »

Hi all

I regularly do the disk cleanup/sdelete/vboxmanage thing to compact my windows guest vdi files, but I can't find any info on doing the same to Mac OS or OS X guests on a High Sierra host machine. I keep an El Cap virtual machine for running non-64 bit legacy software and would like to delete the surplus stuff and get back the disk space. Can anyone advise how to do this please?
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Reclaim disk space for OS X guest

Post by mpack »

The process is exactly the same, except you need to use the OS X disk utility in the guest to erase unused sectors in the filesystem.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Reclaim disk space for OS X guest

Post by socratis »

tsp1965 wrote:I can't find any info on doing the same to Mac OS or OS X guests on a High Sierra host machine
Tried the manual? See ch. 8.23 VBoxManage modifymedium at the "--compact" option:
For Mac OS X guests, use the "diskutil secureErase freespace 0 /" command line from an elevated Terminal.
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.
tsp1965
Posts: 10
Joined: 26. Sep 2015, 10:47

Re: Reclaim disk space for OS X guest

Post by tsp1965 »

Thanks for the reply - only small snag is that Apple removed the Secure Erase function in the disk utility app for El Cap on the grounds that it wasn't relevant for SSDs. My VM is on a Mac Pro, which has an SSD so presumably the VM thinks its VHDD is SSD also. So do I use command line to do this?

If so syntax seems to be:
diskutil secureErase freespace 3 "/Volumes/Macintosh HD"

Replacing the HDD name if it's not the default Macintosh HD

Does that look right?
tsp1965
Posts: 10
Joined: 26. Sep 2015, 10:47

Re: Reclaim disk space for OS X guest

Post by tsp1965 »

Sorry, that should be
diskutil secureErase freespace 0 "/Volumes/Macintosh HD"
not 3 - forgot to change is from my cut-and-paste before posting.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Reclaim disk space for OS X guest

Post by mpack »

I can't see why a secure wipe isn't relevant to SSD. I can see why wear leveling would make it difficult.

If Apple has removed that feature then you need to find a third party tool. I've seen it done on Linux without a tool using file copy from null until space runs out.

Note that this is an OS X support problem: VirtualBox doesn't provide such a tool for any OS, even supported ones - which OS X is not.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Reclaim disk space for OS X guest

Post by socratis »

tsp1965 wrote:Apple removed the Secure Erase function in the disk utility app for El Cap on the grounds that it wasn't relevant for SSDs
Not true. I can still use it on all my 10.5 through 10.13 VMs. So, I'm not quite sure what exactly you're talking about. The only thing that changed in 10.11 is that Apple removed it from the "Disk Utility", not from the command line.

In fact, I had to re-open my original ticket #11175 for 10.11, specifically to remove the reference to the "Disk Utility" that was in the manual, and change it to the equivalent command-line option.

And when given a specific command, I expect that command to be executed as is. I never mentioned the "/Volumes/Macintosh HD". I specifically said "/", without the quotes, i.e.:
  • 
    diskutil secureErase freespace 0 /
mpack wrote:I've seen it done on Linux without a tool using file copy from null until space runs out.
That's right, you can always run:
  • 
    dd if=/dev/zero of=/tmp/empty.tmp bs=1048576; rm /tmp/empty.tmp
It works on every filesystem, even the ones that other tools can't handle, like Btrfs, APFS, XFS, etc...
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.
Post Reply