Solution to 100% CPU Usage by Linux Guest on VMWare Fusion
As part of my testing setup, I have an Intel Mac Pro with Mac OS X 10.6 Server (which runs with the 64-bit kernel) on which I run VMWare Fusion 3.0.1 and several Red Hat virtual machines.
I noticed that even at idle, each VM was taking up a high amount (like 100%!) of a CPU core. Additionally, on one VM top was displaying in near-real-time, which was kind of neat but I doubt the intended behavior. Because of this, I suspected the time management in the kernel was off.
Sure enough, Timekeeping Best Practices for Linux Guests has some hints, and for more information than you'll ever want, try Timekeeping in VMWare Virtual Machines (I was particularly interested in the Clocksource Kernels section).
Making the following modification to /etc/grub.conf on RHEL5 brought my CPU usage down from 100% to barely noticeable:
Before:
kernel /vmlinuz-2.6.18-164.11.1.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
After:
kernel /vmlinuz-2.6.18-164.11.1.el5 ro root=/dev/VolGroup00/LogVol00 rhgb divider=10
I took out quiet because I like to see what's happening when the system boots.
The Note on RHEL 5.4 or CentOS and divider=10 mentions that you do not need this for RHEL 5.4 for accurate timekeeping, but you do need it to prevent the excessive CPU use.
I also modified /etc/ntp.conf as described in the above article, adding
tinker panic 0
to the top of the file and commenting out the following lines:
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
#server 127.127.1.0
#fudge 127.127.1.0 stratum 10
My VMs are down from 100 percent CPU use to practically zero. Think of the energy savings!
APC UPS and Snow Leopard Server Not Communicating
I have used APC (American Power Conversion) power equipment for a long time. I have had both good and bad experiences with their products (a cherished memory is calling their technical support and asking about the "smell of burning plastic" emanating from one of their units).
I've recently upgraded an Intel Mac Pro to Snow Leopard Server (OS X Server 10.6.2) and noticed that the controls in Energy Saver for the UPS are different. Not in a good way.
Here's the relevant screen from OS X Server 10.5.8:

And the same screen from OS X Server 10.6.2:

After reading a thread on Apple's support site about APC UPS Charge Percentage Not Updating I changed the setting on the server to that shown in the second screenshot above; namely, since the computer can't seem to read the charge percentage, it's better to let the computer monitor how long it's been on the battery.
Another annoyance is that I keep getting the dialog Your computer is now running on UPS backup battery power. The UPS is supposed to self-test every 14 days but I'm seeing the dialog more often then this.
It makes me uneasy, and I don't like being uneasy about servers.
See also: http://www.macworld.com/article/140207/2009/05/apc_leopard.html
Eudora, Snow Leopard and Kerberos
I upgraded to OS X 10.6 "Snow Leopard" yesterday. A smooth upgrade except for one thing.
Eudora 6.2.4 for Mac OS X works on 10.6 (provided the optional Rosetta PowerPC-emulation code is installed), but not with kerberos.
To use kerberized POP, Eudora depends on the Code Fragment Manager library "Kerberos" which is part of the MIT Kerberos Extras for OS X package.
The actual library is installed to /System/Library/CFMSupport/Kerberos and is a 983k file last updated in 2003. It's labeled version 4.2.
If the MIT Kerberos Extras for OS X have been installed, and thus this library is installed, Eudora will fail to launch with the following errors:
Launch failed with error code -2821 (cfragInitFunctionErr) for application /System/Library/Frameworks/Carbon.framework/Versions/A/Support/LaunchCFM App
Eudora can be launched by removing the library. But then kerberos-enabled POP cannot be accomplished.
Programmatically suspending, quitting, and resuming Parallels Desktop for scheduled backup
I wanted to do automatic scheduled backups with the awesomely amazing SuperDuper!. The computer to be backed up was a Mac Mini running Mac OS X 10.5 Leopard. But the problem was that Parallels Desktop was running all the time. And everyone knows that when you try to back up open files that may be changing, Bad Things Happen.
"No problem," I thought. Since SuperDuper! allows you to run a script before and after a scheduled backup (have I mentioned how brilliant SuperDuper! is?) I'll use a script to suspend the virtual machine before the backup, and resume it afterward.

So I fired up Script Editor and went to open up Parallels Desktop's AppleScript Dictionary.
Uh.
Apparently Parallels Desktop does not implement AppleScript.
I was stymied until I remembered something that the indefatigable Matt Neuburg had written in AppleScript: The Definitive Guide, Second Edition in a chapter titled Unscriptable Applications. The approach is to cheat by using the Accessibility API built into Mac OS X. From there you can direct mouse clicks, radio button selection...in short, all sorts of mayhem. "Aha!" I thought. "I'll just direct Parallels from the Accessibility API! Sort of like the puppeteer in Being John Malkovich."
First I made sure that accessibility was enabled by going to the Universal Access preference pane in System Preferences.
![]()
Then I made a shell script for SuperDuper! to run before backup. Here's the script:
#!/bin/sh
osascript /Users/john/suspendparallels.txt
sleep 35
osascript /Users/john/quitparallels.txt
sleep 10The shell script first executes the suspendparallels.txt AppleScript to suspend the virtual machine:
-- Suspend a Parallels virtual machine.
-- Assumptions:
-- - only one virtual machine is running
-- - the "Enable access for assistive devices" checkbox is checked in the Universal Access control panel
-- Tested on Mac OS X 10.5.7 with Parallels Desktop 4.0.
-- John VanDyk 7/22/2009
tell application "Parallels Desktop" to activate
tell application "System Events"
tell application process "Parallels Desktop"
tell menu "Virtual Machine" of menu bar 1
click menu item "Suspend"
end tell
end tell
end tellThen the shell script waits for 35 seconds (enough time for the virtual machine to be written to disk), and executes the quitparallels.txt AppleScript:
-- Quit Parallels.
-- Assumptions:
-- - only one virtual machine is running
-- - the "Enable access for assistive devices" checkbox is checked in the Universal Access control panel
-- Tested on Mac OS X 10.5.7 with Parallels Desktop 4.0.
-- John VanDyk 7/22/2009
tell application "Parallels Desktop" to activate
tell application "System Events"
tell application process "Parallels Desktop"
tell menu "Parallels Desktop" of menu bar 1
click menu item "Quit Parallels Desktop"
end tell
end tell
end tell"But John," I can hear you asking, "why not put these together into one simple AppleScript and just use 'delay 35' to create the pause?" I'll tell you why. Because when you do it that way it doesn't work. Plus I got a scary error about "class released with no pool in place - just leaking". Seriously. So I figured, since AppleScript is always, well, flaky for me, I'd just put as much as I could in the shell script and call out to AppleScript only when necessary.
All right. So now SuperDuper! can clone the drive since the Parallels Desktop Windows XP virtual machine has been suspended and the program has been closed. But what about afterwards, when we want to bring Parallels Desktop up just like it was? Turns out, that's even easier. Here's the shell script that SuperDuper! runs after it completes the copy:
#!/bin/sh
osascript -e 'tell app "Parallels Desktop" to activate'
sleep 10
osascript /Users/john/resumeparallels.txtThat first osascript call is actually launching Parallels Desktop. We give it 10 seconds to launch, which is plenty.
Fortunately it launches with the suspended virtual machine. All we have to do is tell it to resume. Here's resumeparallels.txt:
-- Resume a Parallels virtual machine.
-- Assumptions:
-- - only one virtual machine is running
-- - the "Enable access for assistive devices" checkbox is checked in the Universal Access control panel
-- Tested on Mac OS X 10.5.7 with Parallels Desktop 4.0.
-- John VanDyk 7/22/2009
tell application "Parallels Desktop" to activate
tell application "System Events"
tell application process "Parallels Desktop"
tell menu "Virtual Machine" of menu bar 1
click menu item "Resume"
end tell
end tell
end tellPresto! It works.
Negative deletion
I'm confused...does this mean Leopard is actually creating files?

Example: How to install a package for R on Mac OS X 10.5 Leopard
Assuming that you already have the R statistics program installed on your Mac, the following can be used to install a package from the command line.
First, get the .tgz file (we'll use plotrix as the package we want to install):
$ curl http://cran.r-project.org/bin/macosx/universal/contrib/r-release/plotrix_2.6-1.tgz > plotrix_2.6-1.tgz
Check that R is properly installed:
$ which R
/usr/bin/R
Install the package:
$ sudo R CMD INSTALL plotrix_2.6-1.tgz
Password:
* Installing to library '/Library/Frameworks/R.framework/Resources/library'
* Installing *binary* package 'plotrix' ...
* DONE (plotrix)
Check that everything is happy:
$ ls -l /Library/Frameworks/R.framework/Resources/library/
total 8
drwxrwxr-x 16 root admin 544 Jun 26 09:59 KernSmooth
drwxrwxr-x 20 root admin 680 Jun 26 09:59 MASS
drwxrwxr-x 22 root admin 748 Jun 26 09:59 Matrix
-rw-rw-r-- 1 root admin 866 Jun 26 10:00 R.css
drwxrwxr-x 15 root admin 510 Jun 26 09:59 base
drwxrwxr-x 16 root admin 544 Jun 26 09:59 boot
drwxrwxr-x 18 root admin 612 Jun 26 09:59 class
drwxrwxr-x 16 root admin 544 Jun 26 09:59 cluster
drwxrwxr-x 13 root admin 442 Jun 26 09:59 codetools
drwxrwxr-x 13 root admin 442 Jun 26 09:59 datasets
drwxrwxr-x 18 root admin 612 Jun 26 09:59 foreign
drwxrwxr-x 17 root admin 578 Jun 26 09:59 grDevices
drwxrwxr-x 15 root admin 510 Jun 26 09:59 graphics
drwxrwxr-x 16 root admin 544 Jun 26 09:59 grid
drwxrwxr-x 19 root admin 646 Jun 26 09:59 lattice
drwxrwxr-x 15 root admin 510 Jun 26 10:00 methods
drwxrwxr-x 15 root admin 510 Jun 26 09:59 mgcv
drwxrwxr-x 21 root admin 714 Jun 26 09:59 nlme
drwxrwxr-x 18 root admin 612 Jun 26 09:59 nnet
drwxr-xr-x 15 root admin 510 Jul 7 14:30 plotrix
drwxrwxr-x 17 root admin 578 Jun 26 09:59 rpart
drwxrwxr-x 20 root admin 680 Jun 26 09:59 spatial
drwxrwxr-x 15 root admin 510 Jun 26 09:59 splines
drwxrwxr-x 18 root admin 612 Jun 26 09:59 stats
drwxrwxr-x 14 root admin 476 Jun 26 09:59 stats4
drwxrwxr-x 16 root admin 544 Jun 26 09:59 survival
drwxrwxr-x 17 root admin 578 Jun 26 09:59 tcltk
drwxrwxr-x 15 root admin 510 Jun 26 09:59 tools
drwxrwxr-x 17 root admin 578 Jun 26 09:59 utils
Sure enough, plotrix is there nestled among the other packages.
Waterroof is incredulous
I've been using WaterRoof, a frontend for ipfw on OS X. It's only a bit clunky and works well. What is particularly endearing, however, is its response when you have configured your rules and you tell WaterRoof that you want your computer to load them at startup:

Moving Swap on OS X 10.5 Leopard
By default, OS X 10.5 stores its swapfiles in /private/var/vm:
$ ls -lh /private/var/vm
total 131072
-rw------T 1 root wheel 64M May 28 10:32 swapfile0Recently I've been having some fun with a Mac Pro that has 32GB (sic) of RAM. The machine is being used for some bioinformatics work which involves huge chunks of memory. Naturally we ran out of memory and started swapping, but we wanted to swap faster.
I created a RAID 0 (OS X calles it a striped set) using 32GB partitions across four disks for a 128GB RAID volume. Creatively, I called this volume swapraid0. I chose that size because Leopard can have a maximum of 64 2GB swap files (at least that's what Yves wrote). The first few swap files are smaller (Leopard creates 64MB, 128MB, ... 1GB files) so 128GB should be plenty.
I made this RAID 0 volume the first volume (and put the OS on the second volume) because some people reported trouble if swap was not on the first volume.
Then I copied the existing paging directory to the new volume:
$ sudo cp -Rp /private/var/vm /Volumes/swapraid0/.vmI used a dot in the name so it wouldn't show up in the Finder. -R is recursive and -p means "preserve permissions".
If you simply edit /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist to point to your swap on the new volume, you run the risk of the volume not being mounted in time during startup. So I put the following at /sbin/dynamic_pager_init:
#!/bin/bash
#launch Apple's dynamic_pager only when the swap volume is mounted
#see http://forums.macosxhints.com/showpost.php?p=452409&postcount=14
if [ "x`df -H | grep /Volumes/swapraid0`" = "x" ]; then
echo "Waiting for swap volume to mount";
else
echo "Launching dynamic pager on volume swapraid0";
/sbin/dynamic_pager -F /Volumes/swapraid0/.vm/swapfile;
fiChanged permissions on /sbin/dynamic_pager_init to make it executable:
sudo chmod ugo+x-w /sbin/dynamic_pager_init
sudo chown root:wheel /sbin/dynamic_pager_initDouble-checked:
$ ls -l /sbin/dynamic_pager_init
-r-xr-xr-x 1 root wheel 388 Jun 1 20:41 /sbin/dynamic_pager_initNext, I made a backup of the plist that launches the dynamic pager:
$ sudo cp -p /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist /Users/jvandyk/com.apple.dynamic_pager.plistThen I edited the plist so that it would run the script at /sbin/dynamic_pager_init:
$ sudo nano -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plistThe result:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple.dynamic_pager</string>
<key>ProgramArguments</key>
<array>
<string>/sbin/dynamic_pager_init</string>
</array>
<key>OnDemand</key>
<false/>
</dict>
</plist>After rebooting, I ensured that the pager had actually launched:
$ ps aux | grep swap
root 161 0.0 0.0 610348 3504 ?? S 10:00AM 0:00.01 /sbin/dynamic_pager -F /Volumes/swapraid0/.vm/swapfileWarnings/Caveats
1. You'd have to be nuts to do this. The existing pager settings work fine.
2. I am not responsible if you blow up your machine.
3. When I made a typo while I was experimenting, I found out what happens when the pager isn't actually running and you use all the memory. Ugly.
4. Certainly there are ways to improve this.
Sources
Pretty much all of this approach was taken from the posts by E James, whom I thank.
Also, read the dynamic pager man page:
$ man dynamic_pagerOS X: To Protect and Serve
Over the weekend an importer force attacked my Mac. Fortunately, even though the box was unattended at the time, Mac OS X retaliated, eliminating all traces of this hostile force.

I couldn't find much on the web about the "Importer force killed!" message other than Simone Manganelli's helpful tweet.
ImageMagick, MacPorts and MAMP
After installing ImageMagick from MacPorts, I ran into the following error in my MAMP Apache error log when trying to run PHP code that resized images:
Symbol not found: __cg_jpeg_resync_to_restart
To solve this, edit /Applications/MAMP/Library/bin/envvars to read:
DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_FALLBACK_LIBRARY_PATH=/Applications/MAMP/Library/lib


