Working with an OS X virtual machine under Windows presents some interesting challenges that a Windows VM would not. In this particular case, the act of “shrinking” a VMware disc is not a straight-forward process when OS X is the operating system. In this article, I present one way (of probably many) of reducing the footprint of an OS X volume.
Our Story So Far
Up front, I should say I’ve tried a couple of routes that just didn’t work out for me (ymmv). Within VMware, the standard way of “shrinking” a virtual machine’s allocated disc is to first mount it, then prepare it, then shrink it. I won’t go into the process of shrinking a volume using VMware (Google is your friend).
First, I will point out that you can select “shrink” on the volume from within the VMware Workstation GUI, but in my attempts, that had no affect on the final size of the disc image.
I will also point out that, while mounting an OS X disc image under Windows 7 from within the VMware Workstation GUI works, the resulting mounted drive won’t be recognized by Windows. Not being recognized, it cannot then be “prepared” and subsequently “shrunk” using the standard VMware processes.
Failing to affect the image from VMware itself, I then turned my attention to OS X-specific solutions. I first attempted to create an “New Image” from the contents of the disc using the OS X Lion “Disk Utilities” application. This successfully created a “Lion.dmg” file for me. However, any subsequent attempts on my part to use it as a “restore” image always failed.
For example, I booted the OS X Lion VM using the OS X installation ISO, and ran the “Disk Utilities” from within the install GUI. With the “Lion.dmg” file on a USB thumb drive (large enough to hold it, of course), all attempts to “scan it for restore” always failed, even though the “Lion.dmg” file was created directly from the VMware disc image while OS X Lion was running.
Perhaps I’m doing things incorrectly ( I am a PC person, after all 🙂 ). However, the approach I ultimately found that worked was actually to combine some features of VMware and some of OS X.
Combining VMware with OS X
The disc image I’m going to “shrink” is an OS X Lion installation working under VMware Workstation 8.0.2, allocated for 40GB. After some usage, the footprint on disc has reached about 34GB:
while internally, the system is only using about 20GB:
This can happen as you add and delete files to the disc. VMware expands the volume to accommodate new files, but does not actively shrink the volume as you delete them and no longer need the space.
The approach I used to construct a smaller volume is actually fairly simple. However, first a word about backups…
“Backup, backup, backup!”
If you are a software or IT professional, this should be your mantra. You should have backups of any important files or operating system installations (at least one; in my case, I typically have several). In the case of my VMware images, I always preserve a copy, via 7-Zip archive, of any successful image creation from a “difficult” source: OS X in VMware qualifies as a “difficult” source. So, I always have a “pristine” copy of the created VMware image in case I ever need it. In case I accidentally delete my working copy, for example. Or in case I need to “shrink” a working volume *ahem*.
And now, back to your regularly scheduled article…
The approach I’m going to take here is to clone the “working” image to a “pristine” image. This is accomplished in just a few steps.
First, you’ll want to “add” the disc image of your “pristine” (i.e., unused) VM to that of your “working” VM. This is accomplished from within VMware Workstation.
- Open (but do not power-on) your “working” VM in the Workstation GUI.
- Under the “VM” menu, select “Settings…”
- At the bottom of the “Virtual Machine Settings” dialog is a button labled “Add…”. Select that.
- In the “Add Hardware Wizard” dialog, select “Hard Disk” and press “Next”.
- In the next panel, select the “Use an existing virtual disk” option, and press “Next”.
- In the last panel, use the “Browse” button to navigate to the folder containing the files for your “pristine” copy, and select its disc image.
- Enable the “Independent” option, and press “Finish”.
Your settings should now show a second hard disk added to your “working” VM. At this point, press “Ok”, and power on your VM.
If you did everything correctly, once your VM has booted, you will find that you have a second volume available within the operating system:
As you can see, it might be a bit confusing to find two volumes with the same name (this will happen if your “working” VM came from your “pristine” VM, and you never renamed the volume). A simple check of the volume attributes will let you know which is which, but it’s also a safe bet that the top volume is the “working” volume, and the bottom is the “pristine.”
Attack of the Clone
At this point, we’re ready to simply clone one volume to another. I chose to use Carbon Copy Cloner to do the deed:
Of course, you can use whatever tool you wish, as long as it will make an exact clone of one volume to another.
Within the utility, I selected the “top” Lion volume as the source, and the bottom “Lion” volume as the destination:
In addition, on the “destination” side, make sure that “Delete anything that doesn’t exist on the source” is selected to make sure that an exact duplicate is created:
Now press “Clone”, and respond to the subsequent dialogs. The cloning process will begin:
It may take a while depending upon how much disc space your “working” volume is consuming. Mine took about 45 minutes:
Cleaning Up After the Party
Shut down your “working” VM, and return to the “VM -> Settings…” dialog we visited above to add the new hard disk. Select the added hard disk (it should be labeled as “Hard Disk 2” and “(Persistent)”), and at the bottom to the dialog, select the now-enabled “Remove” option. This will unmount the “pristine” disc image from your “working” environment. Press “Ok.”
Once the cloning operation is complete, your “pristine” disc image should be an exact duplicate of your “working” disc image, with all the unused space “shrunk”. For example, from the original 34GB of the “working” disc image, the “pristine” version is now only consuming 20GB:
Of course, you should validate the clone to the “pristine” disc before deleting the “working” copy.
So, using this technique, we’ve been able to reclaim about a third of the disc footprint without having to use any actual Apple hardware. 😉