Try   HackMD

Init

Here we will look more closely at the init process after the Linux kernel has been loaded, and just began to start.

  1. /sbin/init
    The very first program the Linux kernel starts is the init script located at /sbin/init. This script reads in configurations from /etc/inittab which tells it what scripts to run.

    init is the root process with PID=1

    init then calls the script /etc/rc.d/rc.sysinit. (rc stands for run control)

  1. /etc/rc.d/rc.sysinit
    The rc.sysinit script does several initialization steps to the system, such as setting the clock, setting the host name, initializing controllers etc. To see the entire list of items, click here

    The next script init runs is /etc/rc.d/rc

  1. /etc/rc.d/rc
    The /etc/rc.d/rc script initiates the running of all startup scripts

    A number known as the run level is passed to this script, which is given as such

    0 = halt
    1 = single-user mode
    6 = reboot
    Runlevels 2-5 are used for various forms of multi-user mode

    The initial run level is specified in /etc/inittab.

    /etc/rc.d/rc uses the run level to enter the appropriate /etc/rc.d/rc<runlevel>.d/ directory and calls the scripts inside

  1. /etc/rc.d/rc<runlevel>.d/
    Inside the /etc/rc.d/rc<runlevel>.d/ directory contains a number of scripts. These scripts start with either an S or a K

    An example is:

    lrwxrwxrwx 1 root root 19 Aug 16 06:15 K34yppasswdd -> ../init.d/yppasswdd
    lrwxrwxrwx 1 root root 18 Aug 16 06:15 K45arpwatch -> ../init.d/arpwatch
    lrwxrwxrwx 1 root root 15 Aug 16 06:15 K50snmpd -> ../init.d/snmpd
    lrwxrwxrwx 1 root root 16 Aug 16 06:15 K55routed -> ../init.d/routed
    lrwxrwxrwx 1 root root 14 Aug 16 06:15 K80nscd -> ../init.d/nscd
    lrwxrwxrwx 1 root root 16 Aug 16 06:15 K88ypserv -> ../init.d/ypserv
    lrwxrwxrwx 1 root root 14 Aug 16 06:15 S05apmd -> ../init.d/apmd
    lrwxrwxrwx 1 root root 17 Aug 16 06:15 S10network -> ../init.d/network
    lrwxrwxrwx 1 root root 17 Aug 16 06:15 S11portmap -> ../init.d/portmap
    lrwxrwxrwx 1 root root 15 Aug 16 06:15 S15netfs -> ../init.d/netfs
    lrwxrwxrwx 1 root root 16 Aug 16 06:15 S20random -> ../init.d/random
    lrwxrwxrwx 1 root root 16 Aug 16 06:15 S30syslog -> ../init.d/syslog

    Names that start with K means to kill the process, while names that start with S means to start the process.

    The following two digit number defines the priority. S20 will run before S30

    When the system first boots, it executes all the Kill scripts K* first, before executing all the Start scripts S*.

    When the run level is switched, say for example from 3 to 1, then all the scripts in /etc/rc.d/rc1.d/ are executed (Kill scripts first, before Start scripts)

    These scripts here are symbolic links that points to scripts located in /etc/rc.d/init.d/

  1. /etc/rc.local
    The script /etc/rc.local is executed after all the normal system services are started.

    It can be used to start a custom service, for example a server that's installed in /usr/local

Upstart

Upstart: Ubuntu’s implementation of the init system. It solves the problems associated with System V. Rather than execute scripts during a runlevel, upstart manages the system state by reacting to events. An event occurs when a hot-plug device is connected/removed from the machine. Upstart initializes the required dependencies and services for this event change.