Understanding the linux boot order in /etc/init.d

8,611

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.

Share:
8,611

Related videos on Youtube

Nitay
Author by

Nitay

http://en.wikipedia.org/wiki/Me

Updated on September 18, 2022

Comments

  • Nitay
    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 in init.d with numbers that define the running order. These symlinks are generated from running update-rc.d.
    • insserv files - .depend.start/stop/boot files that are generated from the utility insserv. In these files you see the running scripts under TARGETS, 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 to insserv or update-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 or update-rc.d?

  • Nitay
    Nitay about 8 years
    Thanks for your answer. Does update-rc.d uses insserv when deciding the boot order?
  • Stephen Kitt
    Stephen Kitt about 8 years
    Yes, update-rc.d uses insservto determine the boot order.