Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Jun 2018 19:55:29 +0930
From:      Shane Ambler <FreeBSD@ShaneWare.Biz>
To:        Manish Jain <jude.obscure@yandex.com>, freebsd-questions@freebsd.org
Subject:   Re: How to detect single user mode in FreeBSD ?
Message-ID:  <c0718db9-8b46-2301-a770-cd334cbf0f07@ShaneWare.Biz>
In-Reply-To: <e9731c0f-1269-8919-836a-29b9a2f6b0dc@yandex.com>
References:  <e9731c0f-1269-8919-836a-29b9a2f6b0dc@yandex.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?c0718db9-8b46-2301-a770-cd334cbf0f07>