MacOS – Turned off everything in folder /LaunchDeamons with launchctl; can’t boot now—how to recover

launchdmacos

In an effort to shut down the httpd server, I was going to execute this command:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Instead this was executed:

sudo launchctl unload -w /System/Library/LaunchDaemons

The result was that my MacBook just stopped completely and can’t boot. Is it possible to revert it with the following command?

sudo launchctl load -w /System/Library/LaunchDaemons/

But I don’t know what was on and off.

So I need help. How do I restore it? I tried to alt-boot, got into Mountain Lion's recovery options and reinstalled the system, but with the same result. Is the terminal in the recovery tool to any help?

Is this setting saved in a file I can restore from Time Machine?

Best Answer

You should be able to fix this in single-user mode. Restart the Mac while holding the Command and S keys; it'll start into a full-screen command-line environment, with none of the usual daemons even trying to run. As usual, the first two things to do in single-user more are to check/repair and mount the startup volume. To check/repair it, run the command /sbin/fsck -fy and wait for it to finish. If it prints " The volume was modified ", run it again and keep running it until it finishes with "** The volume appears to be OK." Once the startup volume is OK, mount it with /sbin/mount -uw /

Once that's done, run the command:

rm /var/db/launchd.db/com.apple.launchd/overrides.plist

(Note: type this command very carefully. If you thought the damage from mistyping that launchctl command was bad, you haven't seen what a garbled version of this command could do!)

Finally, run the command reboot and the system should restart normally, with all of the system LaunchDaemons set back to their default states.