From nobody Fri Sep 29 14:34:10 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 4RxtCG45YZz4v0WW for ; Fri, 29 Sep 2023 14:34:18 +0000 (UTC) (envelope-from jamie@catflap.org) Received: from donotpassgo.dyslexicfish.net (donotpassgo.dyslexicfish.net [IPv6:2001:19f0:7400:8808:123::1]) by mx1.freebsd.org (Postfix) with ESMTP id 4RxtCG1PZkz4CYr for ; Fri, 29 Sep 2023 14:34:17 +0000 (UTC) (envelope-from jamie@catflap.org) Authentication-Results: mx1.freebsd.org; none X-Catflap-Envelope-From: X-Catflap-Envelope-To: freebsd-hackers@FreeBSD.org Received: from donotpassgo.dyslexicfish.net (donotpassgo.dyslexicfish.net [209.250.224.51]) by donotpassgo.dyslexicfish.net (8.14.5/8.14.5) with ESMTP id 38TEYAUe088286; Fri, 29 Sep 2023 15:34:10 +0100 (BST) (envelope-from jamie@donotpassgo.dyslexicfish.net) Received: (from jamie@localhost) by donotpassgo.dyslexicfish.net (8.14.5/8.14.5/Submit) id 38TEYARc088285; Fri, 29 Sep 2023 15:34:10 +0100 (BST) (envelope-from jamie) From: Jamie Landeg-Jones Message-Id: <202309291434.38TEYARc088285@donotpassgo.dyslexicfish.net> Date: Fri, 29 Sep 2023 15:34:10 +0100 Organization: Dyslexic Fish To: mad@madpilot.net, freebsd-hackers@FreeBSD.org, bacon4000@gmail.com Subject: Re: Single-user actions on reboot References: <67d9160e-c1fc-4e60-93fb-8c18afc2ac41@madpilot.net> In-Reply-To: <67d9160e-c1fc-4e60-93fb-8c18afc2ac41@madpilot.net> User-Agent: Heirloom mailx 12.4 7/29/08 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 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.2.7 (donotpassgo.dyslexicfish.net [209.250.224.51]); Fri, 29 Sep 2023 15:34:10 +0100 (BST) 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:20473, ipnet:2001:19f0:7400::/38, country:US] X-Rspamd-Queue-Id: 4RxtCG1PZkz4CYr Guido Falsi wrote: > 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? To get around that (and I know it's not the same thing, but it does the job for me), I have a script that checks for a marker file in /etc and if it exists, only runs if the file timestamp is newer than the current time. I then have various helper scripts to set the date on that file to (e.g.) 15 minutes in the future. This shuld really be made more generic (having the commands to be run within the so called flag file), but as it stands, I just use this as an added file to /etc/rc.d/ This particular example is based on /etc/rc.d/fsck but is added (don't replace it!), and just forces a full fsck on all filesystems on boot. It's not clean, and really should be merged into /etc/rc.d/fsck , to avoid the double-fsck for one thing, but it was a quick and dirty hack that does the job. I have a script "force-fsck" that simply does this: #!/bin/sh /usr/bin/touch -t "$(/bin/date -v +15M '+%Y%m%d%H%M.%S')" /etc/.force-fsck-expire which i run prior to doing the reboot. The drop-in script, /etc/rc.d/fsck_force_full is here if anyone is interested: https://www.dyslexicfish.com/jamie/freebsd/etc_rc.d_fsck__force__full Though the meat of it is this: | flagfile="/etc/.force-fsck-expire" | | # We have to make sure we only use commands here that exist on the root partition, | # as "/usr" and other partitions won't be mounted at this point. Also, we can't use | # a marker file that gets removed as the mount at this stage is read-only! | | if [ -f "$flagfile" ] && # If the flagfile exists, | expire_time_1="$(/bin/ls -lD '%s' "$flagfile")" && # read it's "mtime", in seconds since epoch | [ "$expire_time_1" ] && # If we get a result, | expire_time_2="${expire_time_1% $flagfile}" && # strip the filename off the end of the string. | [ "x$expire_time_2" != "x$expire_time_1" ] && # If this operation is successful, | expire_time_1="${expire_time_2##* }" && # strip the rest of the cruft from beginning of the string. | [ "x$expire_time_2" != "x$expire_time_1" ] && # If this operation is successful, | [ "${expire_time_1%%*[!0-9]*}" ] && # and if the result is a valid integer, | [ "$expire_time_1" -gt "$(/bin/date +%s)" ] # and if the result is older than the current date, then..... | then | ........ | fi Jason, the script could easily be modified by replacing the fsck command with whatever you want to run.. Cheers, Jamie