From owner-freebsd-questions@freebsd.org Thu Jun 14 01:27:15 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 B9BBF100CD56 for ; Thu, 14 Jun 2018 01:27:15 +0000 (UTC) (envelope-from jungleboogie0@gmail.com) Received: from mail-io0-x233.google.com (mail-io0-x233.google.com [IPv6:2607:f8b0:4001:c06::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5F6FA6852A for ; Thu, 14 Jun 2018 01:27:15 +0000 (UTC) (envelope-from jungleboogie0@gmail.com) Received: by mail-io0-x233.google.com with SMTP id s26-v6so5488514ioj.4 for ; Wed, 13 Jun 2018 18:27:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=z1QVswpPqv37iUVBttJZv3WBnadsAxFAehacVFr5kSc=; b=J1tEwpL0svncHX2BBwtobknuNK8nm8cRfCyt7HgdaaQTzgn9XwUZ+PNaXKpPoX0Gdi ZTcaL8MAIrKF3U32iNjIwHqxtJ9ctgSim6sUexSCOdqUyPNda3AkbY739tVBaPSuOaWV A01Ns3yzVU2GIZzKcJo/+SSfTLERt+iIWV0l9C4Z2Ap3ShxW7gTxOLyw/JiLehh9X/0O +DlxbR0Rj81nAa7YdmmT67eayerH/JopLRGsmOCTeWCwaI2czx7GW4Wp3OgtSiDfqepI ASHNlDlWcwXZLBvb7sHkasGUnh1klknw7YDi4NGlRbQSPdljxGZtHU1NvTl/Ow1Ve0h1 VlfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=z1QVswpPqv37iUVBttJZv3WBnadsAxFAehacVFr5kSc=; b=ZG0inBt+Y0ZGc9Cvf668h8qFcjcLUIcz1Hxmtlf+7oKqevlwoVPOZbeZDTIm/ueThP 8Eclufy6hnhivw6h+WJH+vfRvD3D5Vp0jwXiQr7Dl8dao/PWlAsBs7sspWdU8xJDVYqu TMUjCOBkQtB2qJooVJnW7JKhrTJLCmjmb+kfKs2uOa9oG5r/9xiP4NW6ntsGsFutjVfl sy0kB11JS3NTVL+xxcP7hEMfJ8FHj7XF0b7U2MJKFAYip7WWNkta9tQn6nClqEnic6Ne kVTfxkl5absJn8x271c87rwEVLJAUGkK1smFoJyyclTn1B5+zvm46urcTcuTDFmYxYBe HM1g== X-Gm-Message-State: APt69E3l2y7gMAQJJxi/XK5E8FfwMbnH70koiyURv8yIyGH21u4unm31 6SByAtTdDE6yf+9ztPYygT/z+6kVl0HRO5N6TZkVZg== X-Google-Smtp-Source: ADUXVKKQ41YclrX2acgMWPp/54fA3/REs0KoeNXg+dxRrN7058DiXEvHH5SiWFCgmaoECedi43vZoV86+Dvd1EgaM8A= X-Received: by 2002:a6b:dd1:: with SMTP id 200-v6mr545157ion.122.1528939634847; Wed, 13 Jun 2018 18:27:14 -0700 (PDT) MIME-Version: 1.0 References: <89bc6774-aa0d-6704-71a1-6b8eea8ae3b5@yandex.com> <5B21BB53.30800@gmail.com> In-Reply-To: <5B21BB53.30800@gmail.com> From: jungle Boogie Date: Wed, 13 Jun 2018 18:26:26 -0700 Message-ID: Subject: Re: How to detect single user mode in FreeBSD ? To: JD Cc: FreeBSD Questions Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.26 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: Thu, 14 Jun 2018 01:27:16 -0000 On 5:49PM, Wed, Jun 13, 2018 JD 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?