Raspberry Pi_Eng_20.3.2 Booting Sequence

Published Book on Amazon

All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2

출판된 한글판 도서

최신 라즈베리파이(Raspberry

Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)

최신 라즈베리파이(Raspberry

Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)

Original Book Contents

20.3.2  Booting Sequence


When the system first starts up, it executes certain defined tasks in a certain order. This sequence is called "booting sequence". Next, we will explain the basic framework of booting sequence and how to use it to automatically execute the necessary tasks in booting.    Booting Framework


When the system starts for the first time, it reads system program information from disk, performs various checks and preparation tasks. Then, it performs initialization task for booting in the following order.



   Running "/sbin/init" program


When the system first starts, it runs "/sbin/init" program. This program is the first program executed by the kernel and is assigned Process ID "1". This program reads "/etc/inittab" file to check default run level, checks various configuration values for executing "init", and starts the next process.



   Running "/etc/init.d/rcS" program


The system will run "/etc/init.d/rcS" program. This is called "Sysinit" process, which is actually a script program that adjusts system settings or initializes them. Here, it check the system status and perform the task to load the kernel program.



   Running "/etc/init.d/rc" program


The system runs "/etc/init.d/rc" process in the manner specified in the "/etc/inittab" file for the specified run level, and passes the run level.


The following is registered in "/etc/inittab" and the part that specifies execution method according to run level. It specifies to run "/etc/init.d/rc" according to each run level.


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


Under "/etc/" directory, there are "rc0.d" ~ "rc6.d" directory. Under each directory, init script to start/stop at the run level is registered as link.

Figure 20‑1 init script for start/stop specified in run level


The previously run "/etc/init.d/rc" program will run all the init scripts listed under the "/etc/rc0.d" ~ "/etc/rc6.d" directory, depending on the run level. The basic scheme in which the script is executed automatically according to the run level in the booting sequence is as follows.

    /etc/init.d/rc N         à/etc/init.d/rc    à/etc/rcN.d/script-link    à/etc/init.d/script


   Running script registered in "/etc/rc.local" file


After all the init scripts specified according to the run level have been processed in the previous step, the tasks registered in the "/etc/rc.local" file are executed. This is done only at run level "2", "3", "4", and "5". In fact, this is also processed by an init script called "rc.local" created in the same way as the init script above. The basic framework is as follows.

    /etc/rcN.d/rc.local-link           à/etc/init.d/rc.local        à/etc/rc.local



   Allowing login


Once all of the above is done, the system allows a specific user account to logon.    "pstree" Command Check Booting Process Tree


As the system boots, you can see the correlation information about how the various process daemons actually running are executed by who and in what order. "pstree" command is used for this purpose.


[Command Format]

pstree  [option]


[Command Overview]

    It shows the correlation that the process daemons executed by the system during booting is executed by whom and in what order.

    User privilege           -- Normal user.


[Detail Description]



[Used Example]

The following is executing "pstree" after booting completely.

pi@raspberrypi ~ $ pstree













































In the above data, we can see that several processes have a hierarchical relationship with each other. This means that the process in the upper layer has executed the process in the lower layer. In the hierarchy, "init" is at the top, which means "init" is the first process to run when booting, and "init" has started all processes under it.