Jump to content

[REQ] Tips for Optimizing Disk Images' Free Space?

4 posts in this topic

Recommended Posts

First off, I did my best to try to put this thread in a reasonable part of the forum but this was the only place that seemed suitable to me. Sorry if there was a better place for it.


Like most, over the years I have become a creature of habit when using computers for my daily tasks and find myself using the same methods for the same tasks that i've used since I can remember. I almost hope that my methods have become obsolete and outdated and i'm curious to hear how you guys/girls handle similar tasks now, hoping to find a better method for my tasks and to hopefully become more productive in the process.


Ultimately, I am looking for a method to remove (preferably all) as much free space as possible from disk images so that when I need to restore those images to devices with enough space for the actual content, they actually succeed instead of failing because they don't have enough space to hold the empty free space too.


As I mentioned before, i've been using the same method for image "shrinking" since about Leopard, which is when a major contributor to my method was introduced, the sparseimage. Before 10.5 though my method was more complex and way more annoying, but i'll spare you the details of how that went. This is a quick rundown of what i've been going through in order to "shrink" my images and remove as much free space as I could before archiving them away for later use.


1) Create sparseimage/bundle

2) Copy/transfer data to sparse using diskutil (Sometimes CCC)

3) Remove any unwanted or leftover files using Terminal (.hidden files, etc.)

4) While still mounted, erase partition free space using a 7-pass secure removal

5) Repeat step 3

6) Unmount/eject partition

7) Run compact command using hdiutil on sparse

8) Run resize command using hdiutil to minimum size on sparse

9) Mount again to verify free space changes

10) Repeat step 3

11) Repeat step 6

12) Convert sparseimage/bundle to compressed disk image

13) Verify contents for compressed .dmg


Well, there it is. As you may have noticed it's a tedious, time consuming and usually very demanding of disk space process that I go through. My process would probably go a lot faster too though if I wasn't such an anal-retentive perfectionist. As you can tell I spend a lot of time removing unwanted or leftover files (usually created by OS X). I absolutely hate having leftover .com.apple.timemachine.supported .fseventsd .Trashes .Spotlight-V100 and .TemporaryItems files that sneak past me and get on my final compressed .dmgs. So much so that if I have one i'll usually redo the same image over and over again until I get it just the way I want it. That's my problem though and I have gotten pretty good at getting around it. On average i'd say my process is pretty good and usually achieves a 90-98% free space reduction on the final compressed .dmg. Of course though, i'd prefer if I could completely remove all the free space on my final, compressed .dmgs. That's hopefully what I am here to find out. :)


Anyway, that pretty much boils it down. I hope all that babble makes sense to everyone. If not, i'll try to rephrase it upon request. If any additional info is needed or could be helpful i'll do my best to get it. After all, i'd love to see this one get a nice, simple and solid answer sometime soon. Someone out there must have a more reliable method than mine. I'd love to hear how everyone else performs these tasks. Thanks for reading! ^_^

hmm, a problem most probably wouldn't see as a problem.....Those can be tricky. I would suggest either writing a script using applescript or even Automator to take care of most if not all of that for you in 1 click. Or when using CCC, uncheck the junk files you don't want so you can start off a bit cleaner. But I think scripting it would be the way to go, at the very least you could make one to remove all the junk files in one swoop.

Yeah I forgot to mention that this might not even be considered an issue for most people but to me it is extremely drawn out. Especially since I have to do it so frequently and if it could be simplified into a single Terminal command or at the least, a single disk image instead of needing to create a sparse and then a dmg afterwards. Thanks for the suggestions though. I've considered a script and Automator both for at least making the process smoother but the purpose of the thread is to see if anyone else has a cleaner, more updated method and not so much to automate my own.


That's actually the thing. I can't simply uncheck anything. The annoying files are the ones that OS X auto generates on it's own usually. Such as .fseventsd and .Trashes mostly. Deleting them from Terminal works great but once the image is remounted, they usually respawn. They aren't a huge deal though, like I said I know how to deal with them. Maybe I should remove that part from the post. Anyway, thanks for the suggestions again, I always appreciate any and all assistance I can get.

  • 5 years later...
  • Create New...