Remote Cold Boot a Mac

Back in the good ol’ days of PowerPC Macintosh computing, and WAY before USB there was a marvelous (albeit proprietary) technology called Apple Desktop Bus or ADB for short. You might remember killer keyboards like the “Apple Adjustable Keyboard” seen here:

One of the great features of those older keyboards was the ability to power on the machine right from the keyboard itself. In 1998 Apple changed the keyboard for their brand new iMac line to utilize the increasingly popular USB format. The “Apple USB Keyboard” model number M2452 was the last keyboard (USB or otherwise) to ship with a power button.

If anyone’s ever had a Mac that they wanted to be able to cold boot remotely (for instance from another room) you’ll join me in shedding a tear for that last tidbit of information. No more power button on the keyboard?!?! I’ve been curious for the past several years if there was a way to remotely boot a machine via a USB button or some other method involving the LAN port with the “Wake on LAN” feature, but without some help from Apple it seems that no one has been able (or perhaps been allowed?) to solve this problem yet*. That is… until now!

If you keep your desktop Mac’s AC plugged into a UPS that has USB support capable of issuing a shutdown command, then what I’m going to describe might sound familiar. Imagine you’re at work and streaming some killer tunes from home from the 2TB music collection on your 27″ iMac i7 with 16GB of ram and a 400GB OWC SSD (hey, we can all dream right?) when there is a sudden and extended power failure. Luckily for you your iMac is plugged into a shiny new APC UPS. However, after 20 min or so the UPS runs out of battery and needs to safely shut down your $2500 iPod. Since there isn’t a way to power on your iMac remotely or know when power will be restored you’re a sad panda for the rest of the day while trying to code in a noisy office. That is unless you enabled the preference in Energy Saver that says “Start up automatically after a power failure”. If you have that checked then as soon as power is restored to your home, your iMac will boot again and you can return to rocking out.

For all of this to work though, the UPS has to forcibly remove power from the machine to simulate an all out power failure. This is achieved by the UPS issuing a special kind of shutdown just before yanking the virtual plug, Christina Aguilera’s favorite kind in fact… a dirty one 😉

If you look at the man page for shutdown you’ll notice a bunch of optional flags. The two that we’re concerned with are -h and -u.

      -h      The system is halted at the specified time.    -u      The system is halted up until the point of removing system power,   but waits before removing power for 5 minutes so that an external UPS   (uninterruptible power supply) can forcibly remove power.  This simulates   a dirty shutdown to permit a later automatic power on. OS X uses this mode   automatically with supported UPSs in emergency shutdowns.      

To allow me to simulate what a UPS does and be able to power on my mac from another room, I picked up a $10 Wireless Remote Control Electrical Outlet with an RF keychain remote that has an on/off switch:

When it comes time to shut down the Mac make sure to go through and close out all apps, save all documents and get the system to the point where only the Finder is running. Then issue the following terminal command:

$> shutdown -u -h now

Wait until you’re sure the machine has shut down and then click the “off” button on the RF remote (you’ll have a 5 minute window). You’ve now simulated a power failure in a totally safe way. You can come back hours/days later and “restore power” to the machine by pressing the “on” button on the RF remote and the Mac will boot! I even created an automator action to run the shell script via applescript with administrator privileges so I can just use Alfred (my new favorite launcher utility) to call the “Shutdown Dirty.app” that I made.

The AppleScript code that I used is:

do shell script "shutdown -u -h now" user name "Jon Kinney" password "noway"   with administrator privileges

Please note: this does pose some what of a security risk by embedding your system password in essentially a plain text file, but I really didn’t care. Use this solution at your own risk. Alternatively you can leave the bit about password out and it will prompt you in the OS X GUI.

The reason that I wanted to come up with this solution is that I have a recording studio in my basement and I put in conduit in the walls/ceiling so I could keep my Mac Pro and external hard drives in a server closet that I built under our basement stairs. The main reason for that is my 8-core Mac Pro puts out way too much heat to keep in the control room. It gets hot enough with the LCD monitors, studio monitors (speakers) and my high voltage track lighting. Not to mention that even though FireWire is supposed to be a hot swappable technology, every piece of FW audio gear that I’ve ever owned says to shut down the machine before plugging or unplugging it to avoid possibly frying your FW ports on your computer and/or your audio interface. Now I can shut down and boot from the comfort of my studio chair 🙂

*Note: Apple’s only modern hardware designed to be booted remotely is the Xserve server, which supports Lights Out Management (LOM).