Reboot Mac running Linux after power failure
A Mac Mini will not automatically reboot after a power failure.
macOS has to option to toggle this option (in System Preferences > Energy Saver > "Start up automatically after a power failure" checkbox).
Behind the scenes, this options sets a register in the power management controller (typically the southbridge that acts as the host to the Advanced Configuration and Power Interface (ACPI). macOS set this registers after each boot, since the setting is not persistent across reboots.
So you need to find the type of southbridge in your Mac, and create a startup script that set the right bit in its device registry.
- Original findings by user chirhoxi on Ubuntu forums.
- Good summary by John Westlund. Parts of that page are copied here, under permission of the CC-BY-SA license.
Finding the Southbridge
lspci to find the southbridge in your Mac.
Likely, the output contains one of:
For a Mac Mini early 2006 / MacMini1,1 / A1176:
00:1f.0 ISA bridge: Intel Corporation 82801GBM (ICH7-M) LPC Interface Bridge (rev 02)
For a Mac Mini early 2009 / MacMini3,1 / A1283:
00:03.0 ISA bridge: NVIDIA Corporation MCP79 LPC Bridge (rev b2)
For a Mac Mini early 2010 / MacMini4,1 / A1347:
00:03.0 ISA bridge: NVIDIA Corporation MCP89 LPC Bridge (rev a2)
For a Mac Mini Server 2011 (not tested myself):
00:1f.0 ISA bridge: Intel Corporation HM65 Express Chipset Family LPC Controller (rev 05)
Setting the Registers
Now that we know what hardware we have, the next step is finding which register determines which mode (off, sleep, powered on) is chosen after a power failure. This is less trivial than it seems. The documentation for south bridges is hard to find, and for those available, not particularly readable.
Thankfully others have already determined the correct register for some of the south bridges.
For PPC Mac Mini (not tested myself):
echo server_mode=1 > /proc/pmu/options
For Mac Mini with Intel ICH7 south-bridge:
sudo setpci -s 0:1f.0 0xa4.b=0
For Mac Mini with nVidia MCP79 south-bridge (will likely work on MCP89 too):
sudo setpci -s 00:03.0 0x7b.b=0x19
nVidia no longer makes south bridges, and I have not tested this on a recent Mac mini, so I would love to hear your reports for other south bridges.
Setting bits instead of bytes
Note that the above codes set the whole byte of the registry.
setpci -s 0:1f.0 0xa4.b=0 sets all 8 bits of 0xa4 to 00000000. In reality, we only care to set the first bit to 0, and don't care about the last 7 bits. The proper code to do this is:
setpci -s 0:1f.0 0xa4.b=0:1. This will only set bit zero to zero (0 = value : 1 = mask).
For the nVidia, I'm not 100% sure which bit is the one to set (I couldn't find documentation for the nVidia MCP79).
If you want to check the existing value of the registries, use the
lspci -vvvxxx argument, like so:
lspci -vvvxxx -s 00:03.0
Remember that these registers need to be set after every boot!
To create a systemd startup service, create a file `/etc/systemd/system/reboot_on_power_failure.service`:
[Unit] Description=Reboot after power failure [Service] Type=oneshot # reboot register for Mac Mini with nVidia ISA bridge ExecStart=setpci -s 00:03.0 0x7b.b=0x19 [Install] WantedBy=sysinit.target
And run with
systemctl enable --now reboot_on_power_failure.service