I want to run one sysvinit script before another and figured out how to do that.

To make sure, this actually happens in the the order I like, I would like to see a list, in which order that happens.

I found sudo insserv --showall already, but can't make head or tail of it, since it lists init scripts multiple times.

How to find out in which order /etc/init.d scripts are load on Debian?


2 Answers 2


There's some files in /etc/init.d/ directory:

$ ls -al /etc/init.d/ | grep -i depend
-rw-r--r--   1 root root  2739 Feb 17 05:20 .depend.boot
-rw-r--r--   1 root root  2221 Feb 17 05:20 .depend.start
-rw-r--r--   1 root root  1855 Feb 17 05:20 .depend.stop

Whenever you run update-rc.d the files will change. .depend.boot file is for S level, .depend.start is for 2 3 4 5 levels and .depend.stop for 0 1 6.

In my case, I have the following order in .depend.start:

TARGETS = killprocs motd nvidia-kernel nfs-common rsyslog privoxy virtualbox
linuxlogo acpi-fakekey binfmt-support fancontrol openvpn hddtemp cgconfig 
dropbox-container dbus dnscrypt-proxy pulseaudio atd cryptmount exim4 
qbittorrent-nox ddclient acpi-support smartmontools ssh ntp loadcpufreq acpid 
cron rsync cgrulesengd cpufrequtils bootlogs bootchart-done single rmnologin 
rc.local stop-bootlogd

You can also see why the order presents in the way you see above. Each next line looks like this:

cgrulesengd: rsyslog cgconfig

which means that cgrulesengd needs rsyslog cgconfig to be started prior.


For every runlevel (0 6) there is an folder /etc/rc[N].d

In every directory there are symbolic link either starts with an "S" or with a “K”. "S" to start e "K" to stop. The scripts are executed in a lexical sort manner of the filename, in other words S10script will be executed first than S20myscript. For example :

we have two simple scripts, the second.sh script must be execute after the fist.sh script in the current runlevel.

    root@localhost init.d]# cat /etc/init.d/first.sh 
    echo 'I am the first'  >> /var/log/messages

    root@localhost init.d]# cat /etc/init.d/second.sh   
    echo 'I am the second'  >> /var/log/messages

What is my current level?

    [root@localhost init.d]# runlevel 
    N 5

Now we need a symbolic link starting namely S(N)myScript for the first and S(N+1)mysecondScript:

    root@localhost rc5.d]# ln -s /etc/init.d/first.sh /etc/rc5.d/S1first
    root@localhost rc5.d]# ln -s /etc/init.d/second.sh /etc/rc5.d/S2second

We can reboot and check the messages log:

    [root@localhost ~]# cat /var/log/messages | grep "I am" -A 1 -B 1
    Dec 13 13:53:36 localhost rpc.statd[3468]: Version 1.0.9 Starting
    I am the first
    Dec 13 13:53:37 localhost hcid[3532]: Bluetooth HCI daemon
    Dec 13 13:53:40 localhost automount[3689]: lookup_read_master:       lookup(nisplus): couldn't locate nis+ table auto.master
    I am the second
    Dec 13 13:53:41 localhost gpm[3785]: *** info [startup.c(95)]: 

Tested on old Centos5

  • I recommend using /usr/bin/logger to append to the system log instead of redirection, so you don't accidentally write ">" by accident one day and wipe out your logs.
    – DanB
    Jul 4, 2018 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.