Getting ready

sysvinit is the default initialization manager in Yocto and it has been used in Linux since the operating system's origin. The kernel is passed an init command-line argument, typically /sbin/init, which is then launched to a default runlevel, a machine state that defines which processes to run. This init process has PID 1 and is the parent of all processes.

The init process will read an inittab file and look for a default runlevel. The default inittab file is installed with the sysvinit-inittab package and is as follows:

# /etc/inittab: init(8) configuration. 
# $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $ 
 
# The default runlevel. 
id:5:initdefault: 
 
# Boot-time system configuration/initialization script. 
# This is run first except when booting in emergency (-b) mode. 
si::sysinit:/etc/init.d/rcS 
 
# What to do in single-user mode. 
~~:S:wait:/sbin/sulogin 
 
# /etc/init.d executes the S and K scripts upon change 
# of runlevel. 
# 
# Runlevel 0 is halt. 
# Runlevel 1 is single-user. 
# Runlevels 2-5 are multi-user. 
# Runlevel 6 is reboot. 
 
l0:0:wait:/etc/init.d/rc 0 
l1:1:wait:/etc/init.d/rc 1 
l2:2:wait:/etc/init.d/rc 2 
l3:3:wait:/etc/init.d/rc 3 
l4:4:wait:/etc/init.d/rc 4 
l5:5:wait:/etc/init.d/rc 5 
l6:6:wait:/etc/init.d/rc 6 
# Normally not reached, but fallthrough in case of emergency. 
z6:6:respawn:/sbin/sulogin 

Then, init runs all scripts starting with S (start scripts) in the /etc/rcS.d directory, followed by all the scripts starting with S in the /etc/rcN.d directory, where N is the runlevel value. When the system is shutting down, scripts starting with K (kill) are executed.

So the init process just performs the initialization and forgets about the processes. If something goes wrong and the processes are killed, no one will care. The system watchdog will reboot the system if it becomes unresponsive; applications built with more than one process usually need some type of process monitor that can react to the health of the system, but sysvinit does not offer these types of mechanism.

However, sysvinit is a well-understood and reliable initialization manager, and the recommendation is to keep it unless you need some extra feature.

We will now see how to make init launch new processes. These can be one-shot processes, daemons, that is, processes that run in the background, or applications.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset