04 October 2015

"Erase Free Space" on OSX to reclaim space

Being a heavy VMWare user, my laptop disk is always very close to being full. In a perennial search for space-saving tips, I've found a few sources mentioning the "Erase Free Space" command in Disk Utility could help reclaim a few GBs.

What is this command? Most operating systems "cheat" when deleting a file: they just mark sectors containing the file as free, without actually deleting any data. "Erase Free Space" is meant to actively write zeroes on all disk sectors reported as free, in order to actually erase content that might have been written to such sectors at some point in the past. It's a privacy / security feature, not supposed to reclaim space, but hey, it won't hurt to try! So I decided to give it a spin.

My experience was as follows:
  1. Verified that I had 34 GB of free space (out of 500).
  2. Launched Disk Utility selected the disk partition  i.e. the lowest "Macintosh HD" leaf item in tree menu.
  3. Selected the Erase tab, clicked on Erase Free Space in the lower-left area. Because I have an SSD disk, I chose the "fastest" level: excessive wear should be avoided on SSD disks as much as possible, and I was not performing this operation for security reasons anyway so I didn't really care.
  4. Observed disk free space dropping to zero in about a minute. Received message that disk is full (fair enough) and then another that Disk Utility failed to erase free space. Reported free space was now 34 GB again.
  5. At this point, retrying the operation or going to First Aid -> Verify Permissions returned all sorts of errors about the disk being locked. One error was this: "This disk needs to be repaired using the Recovery HD. Restart your computer, holding down the Command key and the R key until you see the Apple logo. When the OS X Utilities window appears, choose Disk Utility."
  6. I duly followed the procedure; however, when I launched Disk Utility in Recovery mode, almost everything was greyed out except "Verify Disk". This is because I use FileVault (i.e. total disk encryption) so the generic recovery utility, by design, has no access to the actual filesystem, which it sees as a single huge chunk of garbage data spanning the entire drive. It was a welcome surprise: it looks like this security feature actually works as it should.
  7. I clicked Verify Disk where I could (on the top disk item) and it didn't report any problem. Closed Disk Utility and went to the Apple menu -> Restart.
  8. After logon, all permissions-related commands in Disk Utility were usable again.
  9. Most importantly, I now had 39 GB of free space.
Conclusion: it was a slightly scary experience, but got me back a nifty 5GB (or 1% of drive), so I guess I'll do it again in a couple of months.  I suspect the saving might actually be due to OSX reacting to a sudden lack of free space by flushing all the semi-permanent caches it can find; either that, or it forces some sort of defragmenting/fscheck routine at the following startup that results in a more optimized filesystem. To be honest I'm not terribly curious, I'm just happy I have another trick up my sleeve!

1 comment:

zanta klaus said...

Ahoi Pythonaro,

please try out to startup your Mac in Safe Mode, within hold down SHIFT-key. It clean up caches and repair your system folders.

An other way is to trying in /system preferences/spotlight/prificy --> choise any folder you want and disable this privity folder after two hours. After rebooting, maybe u have got more free space! ;-) klaus