From owner-freebsd-questions@freebsd.org Wed Jun 13 10:30:44 2018 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4A6C7101D96F for ; Wed, 13 Jun 2018 10:30:44 +0000 (UTC) (envelope-from FreeBSD@shaneware.biz) Received: from ipmail06.adl6.internode.on.net (ipmail06.adl6.internode.on.net [150.101.137.145]) by mx1.freebsd.org (Postfix) with ESMTP id 76E5279AAC for ; Wed, 13 Jun 2018 10:30:42 +0000 (UTC) (envelope-from FreeBSD@shaneware.biz) Received: from 124-169-216-215.dyn.iinet.net.au (HELO leader.local) ([124.169.216.215]) by ipmail06.adl6.internode.on.net with ESMTP; 13 Jun 2018 19:55:31 +0930 Subject: Re: How to detect single user mode in FreeBSD ? To: Manish Jain , freebsd-questions@freebsd.org References: From: Shane Ambler Message-ID: Date: Wed, 13 Jun 2018 19:55:29 +0930 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-AU Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jun 2018 10:30:44 -0000 On 13/06/2018 00:38, Manish Jain wrote: > Hi, > > > I am writing an fsck wrapper which first needs to check if the system is > in single user mode. > > Under Linux, there appears to be a sysctl that shows whether the system > is in single user > > mode:  sysctl -n kern.singleuser. Is there some similar facility under > FreeBSD too ? I don't think there is a definite way to know. Single user mode is only meant to be for interactive recovery. When in single user mode PID 1 should be "/sbin/init -s" which becomes "/sbin/init --" in multi user mode. The next closet to knowing would be looking at mount, in single user mode you will only have / mounted read only and /dev. It is rare for any system to be past single user mode with only that mount setup but the user can mount the filesystems before starting your script and still be in single user mode. You could maybe take a hint from the firstboot option. By default a file called /firstboot is created and if it exists it means the system has not been started since it was installed, then a series of setup steps can be carried out. You should note that you do not have to be in single user mode to run fsck, it is in fact designed to run in the background even after a user has logged in and started various tasks. >From man fsck - If background checking is available, fsck is invoked twice. It is first invoked at the traditional time, before the file systems are mounted, with the -F flag to do checking on all the file systems that cannot do background checking. It is then invoked a second time, after the system has completed going multi-user, with the -B flag to do checking on all the file systems that can do background checking. -- FreeBSD - the place to B...Software Developing Shane Ambler