5

Is there a way to detect single-user mode in OSX (Lion, specifically) from the command line?

I've tried who -r, which returns 3 in either standard or single-user mode.

I've also tried nvram boot-args, which does not work either.

Google isn't helping much with this...

3 Answers 3

7
$ sysctl -n kern.singleuser
0

It's 1 when booted in single-user mode, 0 when not.

1
  • Confirmed - thanks, Ingmar, just what I needed.
    – Scot
    Commented Apr 12, 2012 at 17:34
2

Hmm. We don't have runlevel in OS X*, which would be the easy way. How about identifying something in the output of launchctl list which is not present in single user mode but is present otherwise - com.apple.Finder might be a candidate.

*man who includes: -r Print the current runlevel. This is meaningless on Mac OS X.

3
  • Thanks, Adam - thought I'd try who anyway to confirm. As for launchctl list, it returns a Socket is not connected error when in Single User Mode...I wonder if that is enough of a hook?
    – Scot
    Commented Apr 12, 2012 at 0:49
  • 1
    Finder isn't always running even in 'normal mode'. It can be quit or replaced with another launcher.
    – user588
    Commented Apr 12, 2012 at 0:51
  • If that's consistent Scot, it might be very convenient!
    – user3117
    Commented Apr 12, 2012 at 0:53
0

In single user mode open directory is not available except by jumping through hoops. You can test the return value of dscl in that case.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .