Understanding the linux boot order in /etc/init.d
With sysvinit
(systemd is different, but you'd use units there, not initscripts), the boot order is determined during boot by the ordering of files in /etc/rc?.d
. The symlinks there are generated by update-rc.d
with the help of insserv
, which is really an implementation detail (as are the .depend.boot
etc. files). All you need to care about are the dependencies between initscripts, declared in their LSB headers; e.g.:
### BEGIN INIT INFO
# Provides: unbound
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
If you want to change the boot order, you need to add dependencies to the relevant initscripts. The safest way to do that is to add overrides to /etc/insserv/overrides
: create a new file there with the same name as the script you wish to override, and write the new header to that file. Then run update-rc.d yourscript defaults
to re-calculate the symlinks.
You'll find more information in the manpages for insserv
and update-rc.d
.
Related videos on Youtube
Comments
-
Nitay over 1 year
This question is about Debian, but I guess it's the same in many linux environments.
The
/etc/init.d
directory defines the services that run at boot-time. As I see it, there are two mechanisms that define who runs and when:- runlevel directories - The
/etc/rcN.d/
directories, in which there are symlinks to scripts ininit.d
with numbers that define the running order. These symlinks are generated from runningupdate-rc.d
. - insserv files -
.depend.start/stop/boot
files that are generated from the utilityinsserv
. In these files you see the running scripts underTARGETS
, and the order in which they appear is the running order (See this post)
So first question - Which of these decides the boot order?
In order to change the boot order I guess you can either edit the symlinks name in the
rc.N
directories, or change the order of appearence in.depend.start
. But both of these changes will be overwritten by a call toinsserv
orupdate-rc.d
.So second question - How do you control the boot order init.d scripts in a way that will last after a call to
insserv
orupdate-rc.d
? - runlevel directories - The
-
Nitay about 8 yearsThanks for your answer. Does update-rc.d uses insserv when deciding the boot order?
-
Stephen Kitt about 8 yearsYes,
update-rc.d
usesinsserv
to determine the boot order.