Boot command

Hello there, been thinking about this for quite some time now, is there any way to make FreeBSD run a command before entering multimode while booting unattended.

Thanks.

Bern
 
Hello SirDice, thank you for your reply,
but I think rc.d scripts will run in multimode only,
I need the scrip to run in "Preen" mode before finishing the boot sequence.
 
Rc scripts don't "run in multiuser mode", they are part of the transition from single to multiuser mode. Why can't you just insert something that runs before any of the regular scripts?
 
jalla said:
Rc scripts don't "run in multiuser mode", they are part of the transition from single to multiuser mode. Why can't you just insert something that runs before any of the regular scripts?

I did not know that, thanks.
How can I check if I or a script is currently multi or single mode ?
 
jalla said:
Rc scripts don't "run in multiuser mode", they are part of the transition from single to multiuser mode. Why can't you just insert something that runs before any of the regular scripts?

I don't think so: the init(8) process is the first process created on the system and it is responsible to start all over processes in multi-user mode, so rc scripts are run in multi-user mode (they are normal processes).
The only way I believe can be used to run something in single mode is to modify the init process, even if I don't see the point in running such a process. If you want to preserve users to connect to your machine while running a maintenance procedure, I'm sure there could be another way (configuring a dependency on ssh, etc.).
 
cgigeek said:
How can I check if I or a script is currently multi or single mode ?
There is no difference.

Single user mode and multi-user mode aren't that different. The only difference is what's running.
 
One way to check if the system is running multiuser is to test against the getty process, but I don't think this is a sure and reliable way. Maybe there is some syscall that emphasizes the status of the boot? (I was unable to find it)
 
Single mode means - disabled logins, no daemons, no logs, it is a stage of [CMD=""]init 1[/CMD]

To answering your primary question: run rcorder(8)() as [CMD=""]rcorder /etc/rc.d/*[/CMD](you will find first task that would be done by OS when it is out of the single mode, usually sysctl is the first one ) and place in the first found task (to the /etc/rc.d/sysctl)

[CMD=""]# REQUIRE: abcd[/CMD]
where abcd is your task that you want to run before system going to multi-user

In this case your script(/etc/rc.d/abcd) will be the first one that will be executed by the system when it is going to multi-user
 
AlexJ said:
In this case your script(/etc/rc.d/abcd) will be the first one that will be executed by the system when it is going to multi-user

But this is run also in multimode, and the question was about running something before multimode begins....
 
fluca1978 said:
But this is run also in multimode, and the question was about running something before multimode begins....

Yes, it is. Single mode doesn't have the same meaning as it is in DOS/Windows world, ALL processes, include processes running by/as the superuser runs in user mode, only kernel routines can run in supervisor mode (ring0 of CPU), so in a term of FreeBSD there no real/protected mode that one can distinguish programmatically by making assumed syscalls.
Either you are a kernel module(ring 0) or running process(user mode).

As about hooking, - FreeBSD isn't a Linux (System V to be more correct) and it has only two runlevels - either single or multiuser. Boot process finished by loading either to single or multiuser mode. There's no such stage as boot->single-mode->multiuser.
If one need to hook up a system on a particular stage, it need to be done either on the end of booting or on beginning of multiuser mode.
Since we are talking about legal(not malicious purpose) bootstrapping then FreeBSD has a legal way to hook initialization process by
placing
[CMD=""]init_script="/path/to/first/script/that/will/be/executed/by/init"[/CMD] in the /boot/loader.conf.local
This script will be responsible to call /etc/rc later... if needed, but since thread author wants to load system to "multimode" then IMHO it would be more convenient
to hook up legally a system on a first multimode command because of some housekeeping(rc(8)()) need to be done correctly before starting multimode commands, so instead of executing hook before rc(8)() it better/safety to execute it after rc(8)() IMHO.
 
Back
Top