Difference between revisions of "Reboot Mac running Linux after power failure"

From Exterior Memory
Jump to: navigation, search
(Finding the Southbridge)
(Startup Script)
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
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.
 
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 set the right bit in its device registry.
+
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.
  
 
===Sources===
 
===Sources===
Line 14: Line 14:
 
=== Finding the Southbridge ===
 
=== Finding the Southbridge ===
  
Use `lspci` to find the southbridge in your Mac.
+
Use <code>lspci</code> to find the southbridge in your Mac.
  
 
Likely, the output contains one of:
 
Likely, the output contains one of:
  
(Mac Mini early 2006 / MacMini1,1 / A1176):
+
For a Mac Mini early 2006 / MacMini1,1 / A1176:
  
 
  00:1f.0 ISA bridge: Intel Corporation 82801GBM (ICH7-M) LPC Interface Bridge (rev 02)
 
  00:1f.0 ISA bridge: Intel Corporation 82801GBM (ICH7-M) LPC Interface Bridge (rev 02)
  
(Mac Mini early 2009 / MacMini3,1 / A1283):
+
For a Mac Mini early 2009 / MacMini3,1 / A1283:
  
 
  00:03.0 ISA bridge: NVIDIA Corporation MCP79 LPC Bridge (rev b2)
 
  00:03.0 ISA bridge: NVIDIA Corporation MCP79 LPC Bridge (rev b2)
  
(Mac Mini early 2010 / MacMini4,1 / A1347):
+
For a Mac Mini early 2010 / MacMini4,1 / A1347:
  
 
  00:03.0 ISA bridge: NVIDIA Corporation MCP89 LPC Bridge (rev a2)
 
  00:03.0 ISA bridge: NVIDIA Corporation MCP89 LPC Bridge (rev a2)
  
(Mac Mini Server 2011):
+
For a Mac Mini Server 2011 (not tested myself):
  
 
  00:1f.0 ISA bridge: Intel Corporation HM65 Express Chipset Family LPC Controller (rev 05)
 
  00:1f.0 ISA bridge: Intel Corporation HM65 Express Chipset Family LPC Controller (rev 05)
Line 36: Line 36:
 
=== Setting the Registers ===
 
=== Setting the Registers ===
  
For PPC Mac Mini:
+
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.
  
echo server_mode=1 > /proc/pmu/options
+
Thankfully others have already determined the correct register for some of the south bridges.
  
For Intel Mac Mini:
+
For PPC Mac Mini (not tested myself):
  
  setpci -s 0:1f.0 0xa4.b=0
+
  echo server_mode=1 > /proc/pmu/options
  
For nVidia Mac Mini:
+
For Mac Mini with Intel ICH7 south-bridge:
  
  setpci -s 00:03.0 0x7b.b=0x19
+
  sudo setpci -s 0:1f.0 0xa4.b=0
  
For Unibody Mac Mini (THIS FAILS):
+
For Mac Mini with nVidia MCP79 south-bridge (will likely work on MCP89 too):
  
  setpci -s 0:3.0 -0x7b=20
+
  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.
  
### comment bellow
+
=== Setting bits instead of bytes ===
  
It would be more appropriate to use
+
Note that the above codes set the whole byte of the registry.
  
setpci -s 0:1f.0 0xa4.b=0:1
+
E.g. <code>setpci -s 0:1f.0 0xa4.b=0</code> 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: <code>setpci -s 0:1f.0 0xa4.b=0:1</code>. This will only set bit zero to zero (0 = value : 1 = mask).
as this will only set bit zero to zero (0 = value : 1 = masq ).
+
  
It does not matter in this case since all the other 7 bits of pci 0:1f.0 address 0xa4 are already zero, but that might not be the case for other hardware.
+
For the nVidia, I'm not 100% sure which bit is the one to set (I couldn't find documentation for the nVidia MCP79).
  
Use the sudo lspci -vvvxxx command to see what your 0:1f.0 pci device initial configuration is before making any mods.
+
If you want to check the existing value of the registries, use the <code>lspci -vvvxxx</code> argument, like so: <code>lspci -vvvxxx -s 00:03.0</code>
  
 
=== Startup Script ===
 
=== Startup Script ===
Line 76: Line 76:
 
  Type=oneshot
 
  Type=oneshot
 
  # reboot register for Mac Mini with nVidia ISA bridge
 
  # reboot register for Mac Mini with nVidia ISA bridge
  ExecStart=sudo setpci -s 00:03.0 0x7b.b=0x19
+
  ExecStart=setpci -s 00:03.0 0x7b.b=0x19
 
   
 
   
 
  [Install]
 
  [Install]
  WantedBy=multi-user.target
+
  WantedBy=sysinit.target
  
And run with `systemctl enable --now reboot_on_power_failure.service`
+
And run with <code>systemctl enable --now reboot_on_power_failure.service</code>
  
 
[[Category:Hardware]]
 
[[Category:Hardware]]

Latest revision as of 19:39, 27 July 2020

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.

Sources

  • 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

Use 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.

E.g. 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

Startup Script

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