Tuesday, February 19, 2013

VMWare Fusion and system_profiler fail

One of the newest additions to my toolset is VMWare Fusion 5. While I've attempted to use VMs in the past for development and testing, I've never really liked the environment. It always seemed slow and difficult to manage when I attempted to bend it to my needs. Luckily, I've had plenty of spare Macs to test on when needed.

I decided to give the tool another shot, as I really think the rollback feature would be helpful when testing software packages. It certainly seems quicker to revert to a snapshot instead of re-installing the OS every time I need to test an installer.

I started my test of VMWare Fusion 5 by booting from a USB drive to restore an OS disk image. I followed this article from VMWare on booting from an external USB drive. Once completed, the machine rebooted as I expected. However, what I didn't expect was the failure of my first boot script to correctly install a few packages.

Looking closer at the logs, I noticed that my script used this line to set the internal drive variable "HD_Path", which is used to tell the installer command the path to install the packages to:
HD_Path=`system_profiler SPSerialATADataType|awk -F': ' '/Mount Point/ { print $2}'|head -n1`
(Side Note: The above command has always worked to get the internal disk of a Mac, even when multiple internal and external disks were present OR even if booted from a the network!)

Running the system_profiler command in the terminal of the virtual machine showed me why it failed. Because "system_profiler SPSerialATADataType" returns blank for virtual machines! I found a bug posted here from 2008 that discusses the problem, but does not provide a solution.

So, I may still try to find a place that using VMWare works for me, this doesn't seem to be it. I am not currently wanting to re-writing scripts just to take advantage of snapshots, although I may find it necessary eventually.

If you're in this spot, try using tools like 'diskutil list' and 'df' to get the disk lists.

5 comments:

Edward Marczak said...

You should be using diskutil :-)

At the very least, when parsing system_profiler output, you should be using XML and some sane XML library (bringing it into a python dictionary, etc.). Apple is free to change the text output at any time.

I don't think your example system_profiler command will output anything on CoreStorage-based disks, either.

Rusty Myers said...

I think I'll have to start using diskutil. You're correct in saying CoreStorage-based disks do not output anything either.

Thanks for the comment!

Unknown said...

Does Virtualbox behave the same way, or is it a VMWare Fusion/Mac OS X combo issue?

Edward Marczak said...

Since a VM is 'faking' (most of) the real hardware, each tend to have its own way of reporting the hardware it supplies. (Try to use system_profiler to get the serial number of a machine under different VMs.)

So, I can't speak for VB per se, but this likely happens under all VMs. There are other tools that will get you the info you need. Also, good programming with error trapping is pretty essential.

Ben Loree said...

I run a lite 10.8.2 VM for packaging on Fusion 5.0.1. Instead of using an external disk, you may have better results using a local disc image. Run Show Package Contents on the Install OS X Mountain Lion.app (from the app store) and copy out /Contents/SharedSupport/InstallESD.dmg.

When you create your new virtual machine, select Continue without disc. I recommend creating a custom machine and specifying the OS/Version. Select customize settings and name your VM. Enable the CD/DVD drive and change Autodetect to Choose a disc image. Select the InstallESD.dmg file.

I also recently discovered that Fusion supports NetBooting. Change the network adapter to bridged. Change the startup disk to network. Boot the VM and hold the N key until you get the spinning globe.