Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted
$ sysctl -n kern.singleuser
0

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

share|improve this answer
    
Confirmed - thanks, Ingmar, just what I needed. –  Scot Apr 12 '12 at 17:34
add comment

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.

share|improve this answer
    
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 Apr 12 '12 at 0:49
    
Finder isn't always running even in 'normal mode'. It can be quit or replaced with another launcher. –  user588 Apr 12 '12 at 0:51
    
If that's consistent Scot, it might be very convenient! –  Adam Eberbach Apr 12 '12 at 0:53
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.