CentOS system startup process
-
Parts of Linux system
Parts of Linux system: kernel + root file system
Kernel: process management, Memory management, network protocol stack, file system, driver, security function
Kernel design genre:
Single core design: integrate all functions into the same program
Microkernel design: use a separate for each function Subsystem implementation
Linux kernel features: support modularity: .ko(kernel object)
support dynamic loading and unloading during module runtime
Component:
Core file: /boot/vmlinuz-VERSION- release
ramdisk: CentOS 5: /boot/initrd-VERSION-release.img
CentOS 6,7: /boot/initramfs-VERSION-release.img
Module file: /lib/modules/VERSION- release
The running system environment can be divided into two layers: kernel space and user space
User space: application (process or thread)
Kernel space: kernel code (system call)< /li>
- Startup process of CentOS system
1. Load the hardware information of BIOS, get the first boot device
2. Read the boot of the first boot device MBR The boot information of the loader (grub)
3. Load the core information of the core operating system, the core starts to decompress, and try to drive all hardware devices
4. The core executes the init program and obtains the default operating information
br>5.Init program executes the /etc/rc.d/rc.sysinit file
6. Starts the core plug-in module
7.Init executes each batch file (scripts) that runs
8.init Execute /etc/rc.d/rc.local
9. Execute the /bin/login program and wait for the user to log in.
10. After logging in, start to control the host with a shell - Detailed description Boot process
1. Load the hardware information of the BIOS and get the first boot device:
POST, power-on self-test is a main part of the BIOS function, responsible for Complete the detection of CPU, motherboard, memory, hard disk subsystem, display subsystem, serial and parallel interface, keyboard and other hardware conditions.
ROM:BIOS, save The most important basic input and output programs for computer systems, system information settings, power-on self-check programs and system startup bootstrapping, etc.
RAM: CMOS complementary metal oxide semiconductor, save the settings of various parameters
Press Search the boot device in order, the first device with boot program is the boot device
bootloader: boot loader, program;
Windows: ntloader
Linux:
LILO: LIinux LOader
GRUB: Grand Uniform Bootloader
GRUB 0.X: Grub Legacy
GRUB 1.X: Grub2
Function: Provide a menu that allows users to select the system to boot or a different kernel version; select the user The kernel is loaded into a specific space in RAM, decompressed, expanded, and then the system control is transferred to the kernel
2. Read the boot load of the first boot device MBR Program (grub) startup information
MBR: first sector
first 446 bytes: bootloader
middle 64 bytes: partition table
The last 2 bytes: 55AA
GRUB:
bootloader: 1st stage
Partition: filesystem driver, 1.5 stage
Partition: /boot/grub, 2nd stage pre>3. Load the core information of the core operating system, the core begins to decompress, and try to drive all hardware devices
Kernel:
Self-initialization:
Detect all identifiable hardware devices
Load hardware drivers
Mount the root file system in read-only mode
Run the first application in user space: /sbin/ initType of init program:
Centos5-:SysV int
Configuration file:/etc/inittab
Centos6:Upstart
Configuration file:/e tc/inittab
/etc/init/*.conf
CentOS 7: Systemd
Configuration file: /usr/lib/systemd/system/, /etc/systemd/system/
ramdisk:< br>One of the characteristics of the Linux kernel: use buffering and caching to accelerate file access on the disk;
ramdisk --> ramfs
CentOS 5: initrd
Tools: mkinitrd
CentOS 6, 7: initramfs
Tools: dracut, mkinitrd
4. The core executes the init program and obtains the default operating information
Type of the init program:1. SysV: init, the reason why the boot speed in CentOS 5 is the slowest is the SysV init method, which is characterized by starting the service program in the user space, usually through a script, and the dependent services will be started serially.
(1) Operation level: a mechanism set for the operation or maintenance of the system;
0-6: 7 levels;
0: shutdown, shutdown< br /> 1: Single user mode (single user), root user, no authentication; maintenance mode;
2: multi-user mode (multi user), will start network functions, but will not start NFS; maintenance mode;
3: Multi-user mode (mutli user), fully functional mode; text interface;
4: Reserved level: There is no special purpose for use at present, but it is used to use the same 3 level functions;
5: Multi user mode (multi user), full function mode, graphical interface;
6: Restart, reboot
Default level: 3, 5
Level switch: init #
Level View:
who -r
runlevel
(2) Configuration file: /etc/inittab
Each line defines an action and its corresponding process
id: runlevels:action:process
id: the identifier of a task;
runlevels: at which level to start the task; #, ###, can also be empty, indicating all levels;
action : Under what conditions start this task;
process: task;
action:
wait: execute once when waiting to switch to the level of this task;
respawn: Once the task is terminated, it will be restarted automatically;
initdefault: set the default run level; at this time, process is omitted;
sysinit: set the system initialization method, here is generally designated /etc /rc.d/rc.sysinit script;
2.Upstart: init,CentOS 6 #CentOS 6 will boot faster than 5 because it uses the Upstart method although the name you see is also called init However, many mechanisms use the Upstart mechanism developed by ubuntu. The characteristic is that the communication between the daemons depends on D-Bus, so similar parallel startup can be basically achieved. The init program: upstart, but still /sbin/ init, its configuration files:
/etc/init/*.conf, /etc/inittab (only used to define the default run level)
*.conf is an upstart-style configuration file;
3. Systemd: systemd, CentOS 7 #The reason for the fastest startup speed in 7 is the systemd method, which is characterized by the fact that the service will only start up when it is accessed for the first time
Core concept: unit , unit is identified, identified and configured by its related configuration files; the files mainly include system services, monitored sockets, saved snapshots and other init-related information;
These configuration files are mainly stored in:
/usr/lib/systemd/system
/run/systemd/system
/etc/systemd/system
Common types of unit:
Service unit: The file extension is .service, which is used to define system services;
Target unit: The file extension is .target, which is used to simulate the "run level";
Device unit: .device, used to define the device recognized by the kernel;
Mount unit: .mount, define the file system mount point;
Socket unit: .socket, used to identify inter-process communication Socket file;
Snapshot unit: .snapshot, manage system snapshots;
Swap unit: .swap, used to identify swap devices;
Automount unit: .automount, file system automatic point device;
Path unit: .path, used to define a file or directory in the file system;
Key features:
Socket-based activation mechanism: Socket and program separation;
Based on bus Activation mechanism;
device-based activation mechanism;
Path-based activation mechanism;
system snapshot: save the current state information of each unit in a persistent storage device;
Backward compatible with sysv init script; /etc/init.d/
incompatible:
systemctl commands are fixed;
services that are not started by systemd, systemctl cannot communicate with it ;5. The init program executes the /etc/rc.d/rc.sysinit file
System initialization script: /etc/rc.d/rc .sysinit
(1) Set the host name;
(2) Set the welcome message;
(3) Activate udev and selinux;
(4) Mount the /etc/fstab file All file systems defined in;
(5) Detect the root file system, and remount the root file system in read-write mode;
(6) Set the system clock;
(7) According to /etc/sysctl.conf file to set kernel parameters;
(8) activate lvm and soft raid devices;
(9) activate swap devices;
(10) load additional device drivers ;
(11) Cleanup operation;6. Start the core plug-in module
7init executes various batch files (scripts)< /strong>After the system /etc/rc.d/rc.sysinit is initialized, the system can work normally at this time, but it still lacks the various services required at startup, so The host can provide some of the functions we need, such as network services, dhcp services and other functions. This is configured through l3:3:wait:/etc/rc.d/rc 3 mentioned in inittab, and here is actually through /etc/ All the link files under rc.d/rc3.d/ decide how to start or shut down the service; the ones that start with S are all started by passing the start parameter, and all those starting with K are all stopped by passing the stop parameter.
And all link files under /etc/rc.d/rc3.d/ are all scripts under /etc/init, and these scripts must accept at least four basic parameters, {start| stop|status|restart}
means to start or close the service controlled by the service script in the /etc/rc.d/rc3.d/ directory;
K*: the service to be stopped; K# #*, priority, the smaller the number, the more priority it is to shut down; the dependent service is closed first, and then the dependent service is closed;
S*: the service to be started; S##*, the priority, the smaller the number , The more priority it is to start; the dependent services are started first, and the dependent services are started later;
rc script: accepts a run level number as a parameter;
/etc/init.d/* (/etc /rc.d/init.d/*) Script execution method:
/etc/init.d/SRV_SCRIPT {start|stop|restart|status}
service SRV_SCRIPT {start|stop|restart|status }
chkconfig command: Control the startup or shutdown status of each service script at each level in /etc/init.d/;
View: chkconfig --list [name]
Add: chkconfig --add name
One of the script definition formats of services that can be added:
#!/bin/bash
#
# chkconfig: LLL NN NN
# description:
Delete: chkconfig --del name
Modify the specified link type:
chkconfig [--level LEVELS] name
--level LEVELS: Specify the level to be controlled; the default is 2345;8. init executes /etc/rc.d/rc.local
Note: At the normal level, the last A service started, S99local, is not linked to a script under /etc/init.d, but is linked to the /etc/rc.d/rc.local (/etc/rc.local) script; therefore, it is inconvenient or unnecessary When the program written as a service script is expected to run automatically when booting up, it can be directly placed in this script file.
? /etc/rc.d/rc.local is run after specifying the run level script.
? You can customize and modify according to the situation.
9Execute the /bin/login program and wait for the user to log in
After logging in, start to control the host with ShellCentOS 6 boot process:POST --> Boot Sequence(BIOS) --> Boot Loader -->Kernel(ramdisk) --> rootfs --> switchroot --> /sbin/init -->(/etc/inittab, /etc/init/*.conf) --> Don't set Set the default run level --> system initialization script rc.sysinit --> shut down or start the service of the corresponding level --> start the terminal