How to Enable Safe Mode from the Command Line on a Mac
Troubleshooting complex issues on a Mac can be challenging as is, and if you’re ever confronted with some complex situations you may find the command line to lend a major hand. In this case, advanced users can boot a Mac into safe mode through the usage of the nvram utility, a tool which allows users to directly manipulate firmware variables. We’ll use nvram to enable safe booting entirely through the command line, preventing a user from needing to use the standard Mac method to boot into safe mode by holding down a Shift key upon system start of OS X, this opens the door for remotely enabling safe mode and improved remote troubleshooting, and for a variety of scripting applications.
This is a trick with fairly advanced application, so most users will never need to use this. Nonetheless, nvram command allows for truly remote troubleshooting, or for situations where there is an issue with a Mac keyboard and USB interfaces that are preventing the Shift key to be used for safe booting as is usual.
The command sequence to enable safe mode through the terminal with nvram is as follows:
sudo nvram boot-args="-x"
Note this is applying a boot argument so that safe mode is set to always be enabled, meaning until it has been specifically disabled again, every boot will be ‘safe’ with all the accompanying limitations.
After your troubleshooting is complete, you will want to remove the boot-arg from firmware so that the Mac can boot as normal and behave as normal again, that can be done by clearing boot-args with the following command string:
sudo nvram boot-args=""
You can also check the current nvram boot arguments with the following command:
If it’s cleared, you’ll see an error message indicating no variable was found.
This can obviously be used directly from the local terminal of OS X, but to be able to use this nvram command for remote management purposes on a different machine, the target Mac would need to have enable the SSH server to allow for a remote login to administer the Mac.
The -x boot-arg can also be used in conjunction with the -v argument to combine booting safe mode with always booting verbose mode, though how useful verbose booting is on a remotely administered Mac is questionable.
I’ve had to use this trick when troubleshooting a Mac with mysterious erroneous behavior that had nonfunctioning keyboards and USB interfaces, eventually it was discovered the Mac had water contact, and the machine eventually recovered after drying out. In that case the troubleshooting tricks weren’t necessary, but there are plenty of situations where they would be.