Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Jun 2018 18:26:26 -0700
From:      jungle Boogie <jungleboogie0@gmail.com>
To:        JD <jd1008@gmail.com>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: How to detect single user mode in FreeBSD ?
Message-ID:  <CAKE2PDu%2BXxXB8adQc3Kz8WuLCQKYZdFCVFZG999G8vpa=dyBQg@mail.gmail.com>
In-Reply-To: <5B21BB53.30800@gmail.com>
References:  <e9731c0f-1269-8919-836a-29b9a2f6b0dc@yandex.com> <CAKE2PDsJqX5g61wYGhKxXv6CMNbdFVLTCvfhG5FY06o6cqw10Q@mail.gmail.com> <89bc6774-aa0d-6704-71a1-6b8eea8ae3b5@yandex.com> <5B21BB53.30800@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 5:49PM, Wed, Jun 13, 2018 JD <jd1008@gmail.com> wrote:
>
>
>
> On 06/13/2018 06:29 PM, Manish Jain wrote:
> > On 06/14/18 05:09, jungle Boogie wrote:
> >> Describe the problem you want to solve, not how.
> >
> > The problem is this:
> >
> > I am writing a shell script which can run fsck on all UFS / ext2 /ext4
> > hard disk partitions listed in /etc/fstab.
> >
> > The script should be portable and be able to run no matter whether the
> > OS running is FreeBSD or Linux. The only thing that matters is that
> > the commands fsck_ufs / fsck.ext2 and fsck.ext4 are available.
> >
> > Ideally, the script should run only under single user mode, or else
> > bail out immediately.
> >
> > Linux has a clean way to find out whether the system is in single user
> > mode. I would think, no matter what others on this list have said,
> > sysctl under FreeBSD too should have a variable for indicating single
> > user mode. But there currently is not any.
> >
> > Tx and Regards
> > Manish Jain
> You need to realize that to run fsck on a filesystem, it has to be
> UNMOUNTED, unless
> you provide the -n option to fsck (which means no write - so the mounted
> fs will not be
> corrupted).
> Lynux will not allow the unmounting of / and remounting as read only.
> So,  you will not be able to fsck the device which provides the root fs,
> at least in lynux.
> It used to be that FBSD could run in single user mode with / mounted as
> ro (read only),
> but I have not booted my FBSD machine for quite some time, so I am not
> sure id
> FBSD 10.x will let me do that.
>
>

So given what JD has said, couldn't you run fsck and see what the return
message is and act on that?



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAKE2PDu%2BXxXB8adQc3Kz8WuLCQKYZdFCVFZG999G8vpa=dyBQg>