Rebooting a Mac Mini after power loss, but my way

tl;dr: On the incriminated A1347 Mac Mini, I found the command to be “setpci -s 0:03.0 0x7b.b=20“. Then you need a way to make it sticky (add it at startup).

For work, I’m currently experimenting setting some kind of mail alert system when one of our UPS units stops receiving power after an unexpected outage and decided to install Intelligent Power Protector from Eaton on an A1347 Mac Mini running Debian Wheezy (the UPS unit plugged to it via USB is a Protection Station 800). Why a Mac Mini? Because we have plenty at work that became useless and outdated. They’re also lightweight, easy to move and easy to set up.

Unfortunately, Intelligent Power Protector only sends emails through SMTP port 25 and you can’t change it. Intelligent Power Manager on the other hand can send through another port but can’t be installed on Linux. So the only way I found is to install Intelligent Power Manager on a Windows machine and that will trigger email alerts when the Mac Mini loses power, if Power Manager is correctly seeing the Mac on the LAN.

Now I need the Mac Mini to be able to automatically restart when power comes back. For that, I read many things on that topic and many possible solutions and indeed, none of them worked. Instead I used an approach similar to the one in that post:

https://ubuntuforums.org/showthread.php?t=1209576&p=7620648#post7620648

So what I did is grabbing another identical Mac Mini (an A1347 from 2010) still running Mac OSX. Then I installed the LSPCI port for OSX:

https://rampagedev.wordpress.com/more-guides/use-lspci-for-info/

Once it’s installed and after rebooting, I get this when typing “lspci” on a freshly opened Terminal:

lspci

Hmm, that tells me we have nVidia devices but I can’t see where is my LPC device or ISA bridge (responsible for the function I want in my case). So going back to the Debian Mac Mini, let’s run lspci from there by typing “lspci | grep LPC”. I’m now getting this:

 

root@debmacmini:~# lspci | grep LPC
00:03.0 ISA bridge: NVIDIA Corporation MCP89 LPC Bridge (rev a2)
root@debmacmini:~#

Okay, that looks more like what I wanted. This confirms that on NVidia-equipped Mac Minis, the ISA bridge is located at 00:03.0 and not 00:1f.0 (like it is for Intel chipsets). So I know now where to look at.

Now going back to the Mac OSX Mac Mini again, let’s open Energy saver settings from the “System Preferences” window (Click on the apple, then “System Preferences”) and check that the value for “Start up automatically after power failure” isn’t ticked. Now on the Terminal window still opened, let’s type “lspci -s 00:03.0 -vvvxxxx > before-setpci.txt”. That will write the result of the lspci command into the before-setpci.txt file:

untick

Now, let’s tick the “Start up automatically after power failure” option and then type “lspci -s 00:03.0 -vvvxxxx > after-setpci.txt” afterwards:

tick

Now we need to compare the files. Before doing so let’s clean them up. When you open both of them, there’s a lot of info going on:

before-setpci after-setpci

Remove all the bits before “00: de 10 80 0d 0f 00 a0 00 a2 00 01 06 00 00 80 00” (that means removing “Region 0: I/O ports at 2100” and all lines above) and after “f0: 00 78 00 fe fd 00 00 00 10 00 80 80 00 00 00 00” for both files and save them. This is what we should have:

before-setpci-edited after-setpci-edited

Now we can compare them by typing “diff before-setpci.txt after-setpci.txt”:

diff

As you can see, only one byte have changed at location 0x7b and went from “60” to “20”. So we now know that you must change that byte to “20” in order to get that auto-reboot after power loss on an A1347 Mac Mini not running Mac OSX.

So, going back to the Debian one, I simply type “setpci -s 0:03.0 0x7b.b=20” to set the value. Then check that the value is correctly set by typing “setpci -vD -s 0:03.0 0x7b.b”:

 

root@debmacmini:~# setpci -s 0:03.0 0x7b.b=20
root@debmacmini:~# setpci -vD -s 0:03.0 0x7b.b
0000:00:03.0 @7b = 20
root@debmacmini:~#

Now let’s yank out the cord out of the Debian Mac Mini. Wait a bit and put the cord back in. Bingo! It restarts! Yay!… Yay? Okay, let’s find out if our setting remained by typing “setpci -vD -s 0:03.0 0x7b.b” after the Mac has restarted. Uh-oh… It turned back to “60”. It looks like we need to have the command executing itself each time the Mac boots up to make the change permanent. So let’s edit /etc/rc.local (for a Debian system) and add that “setpci -s 0:03.0 0x7b.b=20” to it, like this:

 

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will “exit 0” on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

setpci -s 0:03.0 0x7b.b=20
exit 0

 

On that Mac Mini, I installed vim. So to edit it, I simply typed “vim /etc/rc.local”, pressed the [Inser] key to be in edit mode, typed my command above “exit 0” and then exited vim by typing [Esc] then [W] then [Q]. Just to be sure, I ran my command once again and yanked out the cord. Put it back and Bingo! And this time for real.

For those using a Mac Mini as a server running Debian or Ubuntu Server or whatever and wants to restart automatically after a power outage, I hope this has been helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *