To make a small Linux, we need to understand the Linux system boot the whole process, in fact, very simple, and win almost.
Post (BIOS power on self test)--> boot the corresponding device according to the BIOS setting-->boot loader--> unpack the kernel into memory--> run the init process
The whole process is probably as described above.
The tasks that the kernel completes during loading include the following:
Hardware detection
Complete device driver initialization (INITRD get drivers, in the form of modules)
Mount the root file system (Mount read-only)
Load/sbin/init, start the system with PID 1 process
The main process of the system Init is mainly based on the definition in the/etc/inittab file. Let's look at how the Inittab file is written, and we can look at the details of the parts of the file and the components of the inittab.
NAME
Inittab-format of the Inittab file used by the Sysv-compatible
Init process
Id:runlevels:action:process
Explanation of each field
ID: is an ID number, plainly is a word, code name, you can pick.
Runlevels: Run Level
ACTION: Under what circumstances
PROCESS: what command to run
The following are common options for action
Action
Respawn reboot, when the process is finished, will be restarted immediately
Wait only after entering a certain level process will start once, and until it ends, no more action
Initdefault Set default Run level
Sysinit system initialization, this process will be executed once during system startup
Ctrlaltdel: User presses Ctrl+alt+del execution process at the same time
Take a look at the contents of the Inittab file
Id:3:initdefault:
#名字叫id, the meaning of the run level for 3,initdefault is already explained. Set default Run Level
Si::sysinit:/etc/rc.d/rc.sysinit
#名字叫si, the run level is not written, indicating all run levels, the action is called Sysinit, represents the system initialization, and then initializes the script to run as/etc/rc.d/rc.sysinit
L0:0:WAIT:/ETC/RC.D/RC 0
L1:1:WAIT:/ETC/RC.D/RC 1
L2:2:WAIT:/ETC/RC.D/RC 2
L3:3:WAIT:/ETC/RC.D/RC 3
L4:4:WAIT:/ETC/RC.D/RC 4
L5:5:WAIT:/ETC/RC.D/RC 5
L6:6:WAIT:/ETC/RC.D/RC 6
#名字叫 L1---l6, run level 0-6, respectively corresponding to the system 6 run level, each level to run the corresponding/ETC/RC.D/RC 0 in/ETC/RC.D has a script called RC, this script is mainly called/ETC/RC.D/RC. [Files in the 0-6]/directory, the files in the directory are made up of K plus numbers plus service names or s plus numbers plus service names, where k means kill, the service to be killed, that is, the system after the boot, does not run the service, S represents start, run the corresponding level, the service to run, The number that follows it is the priority of the service.
Ca::ctrlaltdel:/sbin/shutdown-t3-r now
#名字叫ca, all run level, when Press Ctrl+alt+del, run/sbin/shutdown command, that is to say: When the user presses the Ctrl+alt+del key combination, the system will reboot in 3 minutes. This is dangerous, the suggestion is changed to other.
PF::p owerfail:/sbin/shutdown-f-H +2 "power failure; System shutting down "
#名字叫pf, all levels of operation, Powerfail, after the power outage (for UPS), perform the following shutdown
Pr:12345:powerokwait:/sbin/shutdown-c "Power restored; Shutdown cancelled "
#名字叫pr, at 12345 of the run level, Powerokwait said the power outage soon, in the designated shutdown time, and then call, on the implementation of the shutdown content
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty Tty2
3:2345:respawn:/sbin/mingetty Tty3
4:2345:respawn:/sbin/mingetty Tty4
5:2345:respawn:/sbin/mingetty Tty5
6:2345:respawn:/sbin/mingetty Tty6