From owner-freebsd-questions@freebsd.org Thu Jun 14 07:47:56 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 6313A100C62E for ; Thu, 14 Jun 2018 07:47:56 +0000 (UTC) (envelope-from 4250.10.freebsd-questions=freebsd.org@email-od.com) Received: from s1-b0c6.socketlabs.email-od.com (s1-b0c6.socketlabs.email-od.com [142.0.176.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F0D4A7AEE9 for ; Thu, 14 Jun 2018 07:47:55 +0000 (UTC) (envelope-from 4250.10.freebsd-questions=freebsd.org@email-od.com) DKIM-Signature: v=1; a=rsa-sha256; d=email-od.com;i=@email-od.com;s=dkim; c=relaxed/relaxed; q=dns/txt; t=1528962476; x=1531554476; h=content-transfer-encoding:content-type:mime-version:references:in-reply-to:message-id:subject:cc:to:from:date:x-thread-info; bh=jFXSUHAiYZOyNlZnDtaC6PC6Tjxx+zXJuPC8Us22iZk=; b=aEPLwjrSYCD4HImgppvzeXhRpRMBAio6HZbJw0cu2UQ0FkmRJczE1fvIDep158ilTXjewDVedlr8v65ZcBOPU0OpSHiF41XPrB6PyKuZRyWxgSYAjSZenyEgKH+G14CG3QTQf1ck0437fk+4t6hSNkHxRhQFh5bjW8ugvp7S6Fs= X-Thread-Info: NDI1MC4xMi4xOGYwMDAwMDAxMzdkMGIuZnJlZWJzZC1xdWVzdGlvbnM9ZnJlZWJzZC5vcmc= Received: from r5.us-east.aws.in.socketlabs.com (r5.us-east.aws.in.socketlabs.com [52.204.195.176]) by mxsg2.email-od.com with ESMTP(version=Tls12 cipher=Aes256 bits=256); Thu, 14 Jun 2018 03:47:54 -0400 Received: from smtp.lan.sohara.org (EMTPY [89.127.62.20]) by r5.us-east.aws.in.socketlabs.com with ESMTP(version=Tls12 cipher=Aes256 bits=256); Thu, 14 Jun 2018 03:47:54 -0400 Received: from [192.168.63.1] (helo=steve.lan.sohara.org) by smtp.lan.sohara.org with smtp (Exim 4.90_1 (FreeBSD)) (envelope-from ) id 1fTMz2-000K8i-D0; Thu, 14 Jun 2018 07:47:52 +0000 Date: Thu, 14 Jun 2018 08:47:52 +0100 From: Steve O'Hara-Smith To: Manish Jain Cc: jungle Boogie , FreeBSD Questions Subject: Re: How to detect single user mode in FreeBSD ? Message-Id: <20180614084752.bd90d2277cdcaf099c501bdc@sohara.org> In-Reply-To: <89bc6774-aa0d-6704-71a1-6b8eea8ae3b5@yandex.com> References: <89bc6774-aa0d-6704-71a1-6b8eea8ae3b5@yandex.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; amd64-portbld-freebsd11.1) X-Clacks-Overhead: "GNU Terry Pratchett" Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 07:47:56 -0000 On Thu, 14 Jun 2018 05:59:16 +0530 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 one mounted on / is going to be a problem in Linux. I'm not sure I see the point in such a script though, the boot time checks have always been adequate in my experience but hey you want it so fine. > 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. Fine. > Ideally, the script should run only under single user mode, or else bail > out immediately. Why ? It would be far more sensible for the script to check each filesystem to see if it is mounted and run fsck if it is not. That way it will run correctly at any time, including in single user with filesystems mounted which is a perfectly feasible condition. > 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. I can't think of any time when single user mode is the correct thing to be checking for before doing something. -- Steve O'Hara-Smith