From nobody Fri Sep 29 21:32:46 2023 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Ry3VG4GZyz4vgt1 for ; Fri, 29 Sep 2023 21:32:54 +0000 (UTC) (envelope-from bacon4000@gmail.com) Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Ry3VG2dgBz3V95 for ; Fri, 29 Sep 2023 21:32:54 +0000 (UTC) (envelope-from bacon4000@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-qt1-x82a.google.com with SMTP id d75a77b69052e-41811e7ac3dso60635611cf.2 for ; Fri, 29 Sep 2023 14:32:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696023168; x=1696627968; darn=freebsd.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Re76ZhQIaiotSDqbNwQSq71ctD3Oe3JjJcoXqInn3C4=; b=ZSi0aBJEW7rOlSoP5spFxx5sGfUSkcfVZHJFaCCd7EVqYXFh0EoWleVQ+jfbaFujc6 jX0Dckok1FMdQlR/uhJTx3cJq0kcq79ASqT1CUBxBOZtHMVQwd/Uv2iYIQT4EE2MOGrA gjHfoeRhEgTgaGG8f8BbNEm25rLkTjENiaQOBp5BRtJA4RaI+R7q6lMLs/HOy2QaoQcA +CM6lSiIeB3R4dNB5qXmA7tp7AqtOuXWet7gYZLYN8kqN2NUm+n5p2Tga3ffb/E+p+qz 2CkvwpqFRdHKZTz9Ruoczd+pxIndhqOBufBn1LckZedX66A2PplYPHJceE2GgYFc3SNh iFSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696023168; x=1696627968; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Re76ZhQIaiotSDqbNwQSq71ctD3Oe3JjJcoXqInn3C4=; b=tqAVbIZDvlWH0N7Nrx+AhhJLYPoXABU3wNaeaN5lGsVqVRIQ1pWyt5J6gudqNTebCB QCoA2LKDQReo/45n0iZY093+Jr41GBu2YJueJHoPrBSVdyfnnkZQUrhYXnbHOwvY0aFV utaHYppWLUr4lmGtaQOe68IF2elMJ36wgAKO+leW9BbsRfNO2kAlOkMOgTpbasrnRY8v sBgFDZiXaZ/Lc8788lR0sYuS61fZ07Vrk18OCH2JjTwyL/HCuka2vPQtTyBE8Gok8W2e foXaRhA2DWlqi40Za30OQkZUW1d0ai0X06dd4mwd7qVIwDWSajOA0fvXVo1NzQxS9zJY jxmw== X-Gm-Message-State: AOJu0YwCsr62Ih9tZS9Tz3T85lXWHX9djwamGw7SNf2ah/KGOpfAZt9s 6HLxMLQpYYt+3/c1NUUe4BH+nwXx7vY= X-Google-Smtp-Source: AGHT+IHJyGB20mjGBQnrIPK6l/R+Tbp9RuC14T34exyMEt2A/wFZnx6WvOK4o7kaXOfP6T9ve3mNCQ== X-Received: by 2002:a05:622a:40a:b0:40f:1c71:d4f7 with SMTP id n10-20020a05622a040a00b0040f1c71d4f7mr5548522qtx.40.1696023168369; Fri, 29 Sep 2023 14:32:48 -0700 (PDT) Received: from ?IPV6:2603:6000:a401:3a00:6e88:14ff:fea7:590c? (2603-6000-a401-3a00-6e88-14ff-fea7-590c.res6.spectrum.com. [2603:6000:a401:3a00:6e88:14ff:fea7:590c]) by smtp.gmail.com with ESMTPSA id iv2-20020a05622a6f0200b004109086e54bsm4763360qtb.38.2023.09.29.14.32.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 29 Sep 2023 14:32:48 -0700 (PDT) Message-ID: <22a305ca-bd0a-af58-31d1-31875ed28629@gmail.com> Date: Fri, 29 Sep 2023 16:32:46 -0500 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: Single-user actions on reboot To: Warner Losh , Chris Cc: Guido Falsi , FreeBSD Hackers References: <67d9160e-c1fc-4e60-93fb-8c18afc2ac41@madpilot.net> Content-Language: en-US From: Jason Bacon In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] X-Rspamd-Queue-Id: 4Ry3VG2dgBz3V95 On 9/29/23 11:56, Warner Losh wrote: > > > On Fri, Sep 29, 2023, 10:12 AM Chris > wrote: > > On 2023-09-29 06:49, Guido Falsi wrote: > > On 29/09/23 15:21, Jason Bacon wrote: > >> > >> I'm wondering if there's a canonical way to schedule a command > to run > >> automatically during the next boot cycle, but before going > multiuser. > >> > >> This would be useful, for example, to run certain tunefs > commands on /, > >> which can only be done in single-user mode, on remotely managed > systems. > >> > >> Running things after going multiuser is easy, of course, but not > sufficient > >> for tunefs commands that cannot be performed on a filesystem > mounted rw. > >> > >> Thanks... > >> > > > > AFAIK there is no ready made tool in base (or ports) for that. > > > > But ezjail uses this trick with rc scripts (removing itself): > > > > > https://erdgeist.org/gitweb/ezjail/tree/examples/example/etc/rc.d/ezjail.flavour.example > > > > This is effective but requires the disk mounted r/w which maybe > is not > > enough for you. > > > > Problem is, without any writable media mounted, how can any > script register > > it has > > already ran? > > > > One idea that comes to mind is adding some hook to the main rc > script, > > before > > mounting disk r/w, and a second script that removes existing > hooks once > > disks are > > r/w. > Indeed. Maybe at the same point the system tastes the disk(s) to see if > they've been dismounted > properly and then running fsck(8) if not. Using the same method to > perform > your task(s)? > > > At work we just have a custom rc script to do that for all our content > disks (only os disks are in fstab). > > As for writable media... you could set a uefi variable... or create a > small MD partition (call it /once) that an rc script in a later phase > could use to mop up and then free. The latter is easier, but in many > environments the former is more durable and reliable if there's an early > crash that happens before mopup and you can really only run something > once... > > Warner > Thanks for the brainstorming, guys. This is about what I expected to hear. What I had done to automate completion of base upgrades after the required reboot is add the following to /etc/rc.local: # Would be nice if this were added to the default rc.local rc_dir=/etc/rc.local.d for script in $rc_dir/*; do /bin/sh $script done Then drop a very simple self-removing script into /etc/rc.local.d/freebsd-update-install.sh: #!/bin/sh -e /usr/sbin/freebsd-update install /usr/sbin/pkg upgrade -y rm -f $rc_dir/freebsd-update-install.sh I just realized I could do the same thing by creating a new rc script such as /etc/rc.d/local.single, modeled on /etc/rc.d/local, but running earlier and using a different script and directory, e.g. /etc/rc.local.single and /etc/rc.local.single.d/. Cheers, J -- Life is a game. Play hard. Play fair. Have fun.