Date: Sat, 30 Sep 2023 09:48:51 -0500 From: Jason Bacon <bacon4000@gmail.com> To: Guido Falsi <mad@madpilot.net>, freebsd-hackers@freebsd.org Subject: Re: Single-user actions on reboot Message-ID: <5b57713d-59d5-4fb6-3cbe-a714386f7309@gmail.com> In-Reply-To: <67d9160e-c1fc-4e60-93fb-8c18afc2ac41@madpilot.net> References: <b70d24e3-ce25-f2fb-1f0f-9526f16173b0@gmail.com> <67d9160e-c1fc-4e60-93fb-8c18afc2ac41@madpilot.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On 9/29/23 08: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. > Thanks for the brainstorming, gents. This helped narrow my direction, and I implemented what I need by creating a /etc/rc.d/local_early based on the standard /etc/rc.d/local: https://github.com/outpaddling/auto-admin/blob/master/Data/local_early https://github.com/outpaddling/auto-admin/blob/master/Data/rc.local_early The only real difference is when it runs. As an example of how to use it, to toggle the soft-updates journal using tunefs, I generate a script like the following and drop it in /etc/rc.local_early.d. It runs on the next reboot and removes itself. for fs in /dev/ada0s1a /dev/da0p1; do tunefs -j disable $fs mount -u -o rw / rm -f /etc/rc.local_early.d/auto-su+j-toggle.sh done reboot This is now integrated into auto-su+j-toggle (WIP version), part of sysutils/auto-admin. -- Life is a game. Play hard. Play fair. Have fun.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5b57713d-59d5-4fb6-3cbe-a714386f7309>
