当前位置:网站首页>Busybox initrd and initialization process
Busybox initrd and initialization process
2022-04-23 06:26:00 【lingedeng】
Initrd File system loading process :
1. Boot loader , for example GRUB, Defines the kernel to load , And the kernel image and related initrd Copy to memory . We can do it in Linux In the kernel source directory ./init Many of these features are found in subdirectories .
2. In the kernel and initrd After the image is decompressed and copied into memory , The kernel will be called . It performs different initialization operations , Eventually you will find yourself in init/main.c:init()(subdir/file:function) Function .
3. This function performs a lot of subsystem initialization operations . A pair of... Will be executed here init/do_mounts.c:prepare_namespace() Call to , This function is used to prepare the namespace ( mount dev file system 、RAID or md、 Equipment and final initrd).
4. load initrd By calling init/do_mounts_initrd.c:initrd_load() Realized .
5. initrd_load() The function is called init/do_mounts_rd.c:rd_load_image(), It uses the init/do_mounts_rd.c:identify_ramdisk_image() To determine which... To load RAM disk .
6. This function will check the of the image file magic Number to make sure it's minux、etc2、romfs、cramfs or gzip Format .
7. Before returning to initrd_load_image Before , It also calls init/do_mounts_rd:crd_load(). This function is responsible for RAM Disk allocation space , And calculate the cyclic redundancy check code (CRC), Then on RAM Decompress the disk image , And load it into memory .
8. Now? , We have this in a block device suitable for mounting initrd image .
9. Now use a init/do_mounts.c:mount_root() Call to mount the block device to the root file system . It will create the root device , And call init/do_mounts.c:mount_block_root().
10. Call it here init/do_mounts.c:do_mount_root(), The latter will call fs/namespace.c:sys_mount() To actually mount the root file system , then chdir Into this file system .
11. Last , Back to init Function , And call init/main.c:run_init_process. This results in a call to execve To start up init process ( In this case, it's /linuxrc).linuxrc It can be an executable program , It can also be a script ( If it has a script interpreter available ).
Busybox init The sequence of program execution is as follows :
1. establish init Signal processing of
2. Initialize console
3. analysis inittab file ,/etc/inittab
4. Execute the system initialization script ,/etc/init.d/rcS
5. To perform all inittab The type in is wait The program
6. To perform all inittab The type in is once The program
7. After completing the above steps ,init Loop executes all inittab The type in is respawn and askfirst The program .
Busybox inittab File example :
::sysinit:/etc/init.d/rcS
# /sbin/getty respawn shell invocations for selected ttys.
tty1::respawn:/sbin/getty -nl /sbin/autologin 38400 tty1
tty2::askfirst:/sbin/getty 38400 tty2
tty3::askfirst:/sbin/getty 38400 tty3
#tty4::askfirst:/sbin/getty 38400 tty4
#tty5::askfirst:/sbin/getty 38400 tty5
#tty6::askfirst:/sbin/getty 38400 tty6
# Stuff to do when restarting the init
# process, or before rebooting.
::restart:/etc/init.d/rc.shutdown
::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/etc/init.d/rc.shutdown
Busybox inittab Document interpretation :
/etc/inittab Each entry in the file is used to define a child process , And determine its startup method , The format is as follows :
<id>:<runlevels>:<action>:<process>
for example :
ttySAC0:askfirst:-/bin/sh
(1)<id>: Indicates the console to be used by this process ( Standard input 、 standard output 、 Standard error device ). If omitted , Then use and init Process like console .
(2)<runlevels>: about Busybox init Program , This field means , It can be omitted .
(3)<action>: Express init How does the program control this subprocess ,
(4)<process>: The program to be executed , It can be an executable program , It can also be a script
If <process>: Field has "-" character , This means that this program is called “ The interaction of ”. stay /etc/inittab/ Under the control of documents ,init The behavior of the process is summarized as follows :
(1) In the early stage of system startup ,init The process starts first <action> by sysinit wait once Of 3 Class subprocess .
(2) During normal system operation ,init The program starts first ,<action> by respawn askfirst Two kinds of subprocesses , And watch them , Restart a child process when it is found to exit .
(3) When the system exits , perform <action> by shutdown restart ctrlaltdel Of 3 One or all of the class subprocesses .
Action conditions for execution explain
Sysinit After the system is started, execute first Only once ,init The process waits for it to finish before continuing with other actions
Wait The system has finished executing sysinit After the process Only once ,init The process waits for it to finish before continuing with other actions
Once The system has finished executing wait After the process Only once ,init The process does not wait for it to end
Respawn It's over once After the process Init Process monitoring found that the subprocess exited , Restart it
Askfirst It's over respawn After the process And respawn similar , however init Process first output “ Please press Enter to actvie this console ”, Wait for the user to enter the driving key before starting the sub process
Shutdown When the system is shut down That is, when restarting and shutting down the system command
Restart Busybox Configuration of the CONFIG_FEATURE_USE_INITTAB, also init Process receive SIGHUP Signal time Read again first , analysis /etc/inittab file , Re execution restart Program
Ctrlatldel Press down Ctr+Alt+del When you combine keys
版权声明
本文为[lingedeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210616199175.html
边栏推荐
- Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi
- Techniques et principes de détection
- Advanced operation of idea debug
- JDBC operation transaction
- On traversal of binary tree
- Export of data
- MySQL advanced query
- 程序設計訓練
- 線性代數第一章-行列式
- Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising
猜你喜欢
JDBC connection database
Comparative study paper - [Moco, cvpr2020] momentum contract for unsupervised visual representation learning
Installation and usage skills of idea
線性代數第一章-行列式
A sharp tool to improve work efficiency
線性代數第二章-矩陣及其運算
檢測技術與原理
In depth understanding of the relationship between dncblevel and noise denoising in the paper
Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi
Illustrate the significance of hashcode
随机推荐
Contrôle automatique (version Han min)
Rainbow (DP)
String notes
Integration and induction of knowledge points of automatic control principle (Han min version)
Unsupervised denoising - [tmi2022] ISCL: dependent self cooperative learning for unpaired image denoising
Detection technology and principle
11.a==b?
Custom exception class
Why does the subscript of the array start from 0 instead of 1?
Kalman filter and inertial integrated navigation
Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)
Sakura substring thinking
[leetcode 290] word rules
[leetcode 54] spiral matrix
The bottom implementation principle of thread - static agent mode
卡尔曼滤波与惯性组合导航
Three ways to create threads
2. Devops sonar installation
Class loading and classloader understanding
Numpy common function table sorting of data processing