I recently came across a very useful tidbit after receiving several inquires asking how to configure an Apple Mac Mini to automatically startup after a power failure. This is extremely useful for situations where power is eventually restored and you are not physically around to press the power button. Automatically starting up after a power failure is not a new feature of the Mac Mini and it actually exists on most modern day systems and can be configured using a variety of tools.
The challenge arises when you are running ESXi, how do you go about enabling this functionality in ESXi itself? Well the answer is actually quite simple, you can enable this outside of ESXi. Normally to enable this feature you can either run a setpci command on UNIX/Linux system or configure the energy saver settings in OS X. Several folks from the VMTN community such as zippytiff and twuhabro have already confirmed having success using the latter option when booting OS X off a USB or SD card to modify the energy saving settings.
I finally got a chance to look into this a bit more for myself and with a bit of research, I found several other methods which also works and may potentially be easier.
Note: I have heard that historically the auto startup flag has not persisted in older Apple hardware, but for the new Mac Mini 5,3 and 6,2, they seem to be persisting without any issue from my testing. YMMV depending on your hardware and/or firmware.
Method 1 (Configure in OS X)
If you already have OS X install on your Mac Mini, then you just need open up the System Preferences and enable auto startup under the Energy Saver section. Once that has been enabled, you can then perform your ESXi installation.
If you already have ESXi installed, then you can use either Method 2 or 3.
Method 2 (Configure using bootable Ubuntu on USB)
We can create a bootable Ubuntu image running off of a USB device (minimal footprint) and run the following setpci command to enable auto startup:
setpci -s 0:1f.0 0xa4.b=0
If you are interested in the gory details on the above command, please refer to this great article which breaks it all down for you. After you have created your Ubuntu image using the instructions in the above link, you can boot off of the USB device (Make sure to hold down ALT/OPT key so you can select to boot off of the USB device). Once Ubuntu has booted up, you will right click on the purple icon on the upper left hand corner and type in terminal.
You will then launch the terminal application and type the following to change over to root user.
sudo su -
Finally, you will enter the above setpci command which will enable the auto startup. At this point, you can type reboot and remove the USB device.
Method 3 (Configure using bootable OS X on USB)
Another method is to create a bootable OS X image running off of a USB device and change the power management settings by using the pmset utility. To enable auto startup, run the following command in the terminal:
pmset autorestart 1
You will need the original OS X installer and if you are using either Lion or Mountain Lion, you can use Lion DiskMaker to help you create the bootable USB image (Make sure to hold down ALT/OPT key so you can select to boot off of the USB device). Once the OS X installer boots up, at the top select Utilities and click on the Terminal application.
Go ahead and run the above command to enable auto start and then type reboot and remove the USB device.
The last thing to do of course is to actually test this out on your Mac Mini. Go ahead and let the system boot up and then yank the power cord and then give it a few seconds before plugging it back in. You should see the Mac Mini automatically power back on after you plug the power back in.
References:
- http://www.beasts.org/support/macminicolo_howto.html
- http://smackerelofopinion.blogspot.com/2011/09/mac-mini-rebooting-tweaks-setpci-s-01f0.html
Jon says
Will this setting stick once it's set? I have bootcamp for Windows 8. I use Windows 8 full time for Media Center cablecard DVR. When the power goes out I'd like the macmini to power back on. I went into Mac OS X and checked the box. Hopefully that's good enough. I don't want to "try" it if I can just ask first.
Jon says
EDIT: never mind, I see that Boot Camp Control Panel in windows actually has the Power option of "Restart automatically after a power failure" I should be good to go now!
Anonymous says
I'm in the same boat, running Windows 7 only on Mac Mini and need to set it to reboot after power failure. I wonder what Apple is running to do it, I would think it would be an nvram command or something.
Anonymous says
and with VMWare ESXI 5.1 installed, there is an option to Start up after power Failure?
Julfikar Rahman says
zeg op
opzeggen
uitschrijven
afmelden
tijdschriften
Cancel.my is a wonderful site for opzeggen. I was almost in trouble in that but this site preserves me from that and helped me to cover the problem, that is why I like to take their support always.
Nick James says
The problem is that this setting does not survive subsequent reboots.
The setting is written everytime OSX boots, so if you don't boot OSX each time the setting will be lost and the mini will not power on after power is restored.
In windows you can use the WPCRSET utility to set the flag each time and this achieves the same behaviour as the setting in OSX, however I am still looking for a way to run a similar utility or something every time ESXi boots so the setting sticks.
Is anyone aware of a utility that can do this, and how to set it so ESX executes it on every boot?
William Lam says
I'm currently using this method on my Mac Mini 6,2 and the settings have persisted for me on both ESXi 5.1 & 5.5. In fact, I've had a power outage a couple months back and once the power was back it started up the system as I expected
Marc says
Just tried the USB OSX boot method with the pmset command and it doesn't seem to work. Is there something that needs to be done in order to make the setting "stick"?
William Lam says
afaik, that should work. Perhaps something has changed with the latest release of OSX?
Marc says
Perhaps. I was using a Mavericks installer USB.
I subsequently tried the bootable Ubuntu (13.10) USB method which worked like a charm.
Thanks!
Marc says
Seems like the setting has reverted itself now. Is there something that needs to be done to make it stick? Or is there something that would cause it to revert?
Paul Richardson says
It seems that Mac OS oriented MOBOs and Firmware are more likely to include this capability than Windows-oriented BIOS. Is a magic packet (WOL) the only option then, for slightly older Windows PCs? Is there potentially an App/Script that might somehow help boot it back up when power returns?
Ben Peddell says
On most PCs made since about 2000, there is an option in the BIOS to set the "Restore from AC power loss" (or something similar) to "Always On".
On the Mac Mini, it looks almost as if this setting is cleared by the firmware during shutdown - the Mac Mini will only automatically power on if the OS did not gracefully shutdown and power off the system.
Claude Morin says
[Success, and a tweak]
This worked for me on a Mac Mini 6,2 using method 2: I used Ubuntu 14.04 on a DVD to run setpci.
Before making the change I checked the existing value:
# setpci -v -s 0:1f.0 0xa4.B
0000:00:1f.0:a4 = 09
#
Here we see that it was "09", which is binary 1001. I don't know what bit three does but I'd rather not find out the hard way :-).
So I made one tweak to the invocation of setpci. Instead of clearing the entire register by setting the value to zero, one can set arbitrary bits using the value:mask feature of setpci. Here, I set the least-significant bit to zero. Adding the "-v" flag produces verbose output:
# setpci -v -s 0:1f.0 0xa4.B=0:1
0000:00:1f.0 @a4 = 09->(00:01)->08
#
So we see that the value "09" was modified by the value:mask "00:01" and became the value "08". I could have just forced the value to "08" but the value:mask approach is more general.
For extra safety, do a dry run first by adding the "-D" option:
# setpci -vD -s 0:1f.0 0xa4.B=0:1
--klodefactor
MisterA says
This worked for me and seems the safer bet as it's a more subtle edit than the original proposal. Like others using macOS to do it did not persist through reboots, this did.
In my case as I was using Proxmox as my hypervisor, which is Debian based, I could simply run the setpci command via it's shell.
Cyrl says
Little tip about Method 3:
Instead of creating a full USB bootable media, you can just create a USB recovery stick by using the Recovery Disk Assistant included in Mac OS X.
It creates the "Recovery HD" on the key and you will need a 1GB usb stick. It is far away faster than creating a full USB Installer media š
paopaomj says
Hi, thanks for this article.
Just tried the 2nd and 3rd method, on Mac mini 5,2 (MC816) with ESXi 5.5 installed.
The pmset way under Mavericks installation usb disk doesn't work , it can't keep persistant, every time I reboot into installation use pmset -g to checkout that autorestart status, it always return back to 0.
The ubuntu way works!!! Just as you described, it works like a magic.
Thank you again, that helped me so much!
michalmmac says
Hi, great article
How would you deal with this -> https://communities.vmware.com/thread/500931
Basically I need to replicate halt -u behavior from OS X on ESXi hypervisor running on Mac mini.
William Lam says
I don't have any suggestions, the halt command in ESXi only provides the following options:
~ # halt --help
BusyBox v1.20.2 (2012-12-11 11:54:28 PST) multi-call binary.
Usage: halt [-d DELAY] [-n] [-f] [-w]
Halt the system
-d SEC Delay interval
-n Do not sync
-f Force (don't go through init)
-w Only write a wtmp record
I've shot a note to one of the Engineers to see if he has any ideas.
michalmmac says
Thank you for response.
My current solution would be to shuddown all running VMs and than wait for power loss to occur. Hypervisor would die. What is the worst thing that can happen? What kind of write IO operations is hypervisor doing while not running any VMs?
If engineers could come up with cleaner solution (replicating halt -u in some way), that would be great š
William Lam says
There can still be write operations happening even when there are no VMs running. Administrator could still be making changes to ESXi host, config, etc. If none of that's running, there's also auto backup script that flushes configuration files to disk every 5minutes. So, yes there can be IO operations running.
I know some other approaches that folks have done including myself, not specific to Mac Mini is to have a VM be able to talk to your UPS and once it notices it's turned on due to power outage, you can issue commands to ESXi host via SSH or using the vSphere API. I know APC/Eaton has similar solutions doing this. So, perhaps something you may want to look into.
Also remember that the Mac Mini platform is not an officially supported
michalmmac says
Just for clarity. Problem is not how to talk UPS. Problem is how to put ESXi host software to state when it is no longer running (halted) but power is still on so SMC in Mac mini can detect loss of power and restart automatically.
Would is be possible to tell init daemon to shut down every service but not itself?
michalmmac says
btw what about /bin/shutdown.sh script? It stops all running VMs and some ESXi services. Wouln't that be enough?
William Lam says
That actually initiates a shutdown of the host, once VMs are off, it shutdowns rest of services and then the host
michalmmac says
But there is no 'poweroff' or other shutdown command in /bin/shutdown.sh (ESXi 5.5U2).
Last thing it does is to shutdown syslog.
During my testing this script always stops services but host does not power off.
Perhaps I am misusing terminology (shutdown vs. poweroff)?
#!/bin/ash
log() {
echo "$1"
logger init "$1"
}
#Extract and save the random seed
dd if=/dev/urandom of=/etc/random-seed count=1 2>/dev/null
#Power off autostart configured VMs
/sbin/vmware-autostart.sh stop
/sbin/services.sh stop
#Backup the config (including the random seed)
/sbin/backup.sh 1
#Shutdown syslog daemon
/usr/lib/vmware/vmsyslog/bin/shutdown.sh
William Lam says
Sorry, meant to say for poweroff. Yes, I guess /bin/shutdown.sh should technically should work, SSH looks to still be running least with the active session.
roy says
Hi i am looking for a way to auto start / power on my mac,
i am using a switch to turn of al my side equipment of my studio computer and also the computer it self.
speaker, midi keyboard, screen. etcetera. now i am looking for a way to auto start up my mac mini the way i can do it whit my pc,
so that when i use the remote switch everything starts up. and that I don't have to start my computer manual.
So that when I am inspired to make music I would like to start as fast as possible.
Kind regards Roy
grandavebb says
Thanks for this article. I was faced with turning this feature on on a Mac Mini 1,1 (first Intel), and so far, it isn't sticking.
This was a throwaway machine that I decided to experiment with reconfiguring as a MikroTik x86 router, so that I could run the newest Dude network monitoring package on it. It boots and runs fine in MikroTik ROS, and when I hold the option key down, boots fine from an external drive containing OS X. I can set the auto-boot feature on in OS X, and if I reboot into OS X, it stays on, but once I boot into ROS, it seems to disappear. I also tried the pmset route in Terminal, with the same results. A shame, since auto-on is a key requirement for a network monitoring system. š
Dean Zook says
I have ESXi 6 on a mid 2012 mac pro and would like to know if the method outlined in this post or some other would work to enable a startup after a power failure.
manny says
The easiest way to persist this setting is to boot into a Mac OS recovery USB, go to terminal, and do a
pmset -a autostart 1 force
The 'force' writes it to nvram immediately. Normally it needs to be set by a disk file on boot up.
manny says
This has been tested on a 1,1 and a 3,1.
manny says
Oops, that should be pmset -a autorestart 1 force
Joe says
Anyone know if the setpci... command be run from the esxi 6 command line via ssh to apply this to a Mac Pro 6,1 (2013)?
Andre Garkauskas says
Thank you so much! Running pfsense on a MacMini 2014 over ProxMox and this feature is very important.
Jim says
Thank you, the setpci -s 0:1f.0 0xa4.b=0 is exactly what I needed! š