SysV

SysV-style init is invoked as pid 1 by the kernel. It:

  • Spawns a set of processes specified in its configuration file to bring a system to a given runlevel.
  • Reaps zombie child processes (processes that have either exited or killed by a signal, triggering a SIGCHLD signal to be sent to the parent).
  • Supervises respawn and ondemand processes.
  • Responds to signals.
  • Processes commands received via /run/initctl (/dev/initctl in later versions).

Runlevels

The runlevels standardised by SysV are:

  • 0: shutdown
  • 1 (or S or s): single user mode
  • 6: reboot

Linux distributions typically extend these:

RunlevelDebian-basedRHEL-based
0HaltHalt
1Single user modeSingle user mode
2Multi user with GUIMulti user without NFS
3Unused; behaves as 2Full multi user mode
4Unused; behaves as 2Unused
5Unused; behaves as 2Unused
6RebootReboot

init can be signalled to change the runlevel using telinit, conventionally a link to the init binary.

On-demand procedures

On-demand procedures are sets of processes (up to three; named a, b, and c) that can be launched explicitly via telinit invocations, though not during the boot sequence or from within single-user mode. Subsequent invocations restart the specified processes.

They're defined by using the characters (abc) in place of a runlevel number.

Configuration

/etc/inittab is the configuration file read by init. It contains a series of directives in the form:

id:runlevels:action:process

In the above:

  • id is a 1-4 character unique identity for the line.
  • runlevels lists the runlevels to which the action applies. If not specified, defaults to all runlevels (e.g. 0123456789).
  • action specifies what the configuration line does:
    • Assign a process to a runlevel:
      • respawn causes the specified process to be restarted on termination (e.g. for a TTY/PTY).
      • wait awaits completion of process before continuing.
      • once once upon entering the runlevel.
    • Configure the boot sequence:
      • sysinit defines processes required for early boot, regardless of runlevel.
      • boot adds a process to the boot process (after sysinit completion).
      • bootwait behaves as boot, also awaiting completion of process before continuing.
      • initdefault specifies the default runlevel.
    • ondemand specifies an on-demand procedure.
    • Responses to signals:
      • powerwait
      • powerfail
      • powerokwait
      • powerfailnow
      • ctrlaltdel specifies a process to execute in response to init receiving SIGINT.
      • kbrequest default runlevel includes S

Signal handling

init responds to signals as follows:

  • SIGHUP reloads configuration from /etc/inittab.
  • SIGINT starts the first active ctrlaltdel process.
  • SIGWINCH starts the first active kbrequest process.
  • SIGUSR1 has init close (if open) and reopen its control FIFO.
  • SUGUSR2 has init close the control FIFO and not reopen it. It can later be reopened with SIGUSR1.
  • SIGPWR causes init to read /var/run/powerstatus (formerly /etc/powerstatus) and take an action based on its content:
    • O (for OK): consider normal power status, that there's no need for a shutdown. Start all processes with a powerokwait action field.
    • L (for low): consider the batterly level to be low and the power failing; an imminent need to shutdown. Start all processes with a powerfailnow action field.
    • Anything else (conventionally F, for fail): consider the power to be failing, and a possible need for a shutdown in the near future. Start all processes with the powerfail and powerwait action fields.

Resources


Backlinks