CentOS system startup process

CentOS 6 startup process:
POST --> Boot Sequence(BIOS) --> Boot Loader (MBR) --> Kernel(ramdisk) --> rootfs(readonly) –> switchroot --> /sbin/init -->(/etc/inittab, /etc/init/*.conf) --> Set the default run level --> Run the system initialization script to complete the system initialization --> Turn off the services that need to be stopped under the corresponding level, and start the services that need to be turned on under the corresponding level-- > Start the terminal and print the login prompt [–> start the graphical terminal]

1、 CentOS system startup process##

(1) POST: Power On and Self Testing
The POST program is stored in the BIOS (Basic Input and Output System) of the ROM chip, which is a CMOS (Complementary Metal Oxide) chip.
ROM+RAM is the storage space accessible by CPU, ROM and physical memory RAM
(2) Boot Sequence
Find each boot device in order, the first device with boot program is the device to be used for this startup.
(3) bootloader: boot loader, is a boot program, bootloader in Windows and Linux:
Windows:ntloader
Linux:
LILO:LInux LOader
GRUB: Grand Uniform Bootloader (Unified Bootloader)
GRUB 0.X:Grub Legacy
GRUB 1.X:Grub2
Bootloader function: Provides a menu that allows users to select the system to be started or a different kernel version, load the kernel selected by the user into a specific space in RAM, decompress and expand, and then transfer system control to the kernel.
(4) MBR: Master Boot Record, master boot record
The MBR is located in the first 512 bytes of the memory. The first 446bytes is the bootloader, the middle 64bytes is the partition table, and the second 2bytes is 55AA. 55AA means the MBR is valid, and non-55AA means the MBR is invalid.
(5)GRUB
GRUB is divided into two stages, as follows:
1 ) The first stage: loading bootloader;
2 ) Stage 1.5: Start the filesystem driver;
3 ) Phase 2: According to the /boot/grub/grub.conf configuration file, partition the disk.
(6) Kernel startup
1 ) Self-initialization
1 Detect all hardware devices that can be identified;
2 Load the hardware driver (may use ramdisk to load the driver);
3 Mount the root file system in read-only mode, and when there is no problem in booting, change to read-write mount to prevent kernel problems and data loss;
4 Run the first application in user space: /sbin/init
(7) Type of init program:
Before CentOS 5-system, it was called SysV init, and the configuration file was /etc/inittab;
The CentOS 6 system is called Upstart, which was developed by Ubuntu. The configuration files: /etc/inittab and /etc/init/ .conf;
The CentOS 7 system is called Systemd, and the configuration files are: /usr/lib/systemd/system/ and /etc/systemd/system/.
(8)ramdisk
One of the characteristics of the Linux kernel: the use of buffers and caches to accelerate access to files on the disk.
The ramdisk of CentOS 5 is called initrd, the tool program is mkinitrd, CentOS 6, CentOS 7 changes the ramdisk to ramfs, their ramdisk is called initramfs, the tool program is dracut and mkinitrd, mkinitrd is a encapsulated SHELL script, or created by dracut .
(9)/sbin/init
CentOS 5: SysV init
Operation level: a mechanism set for the operation or maintenance of the system;
0- 6 : 7 levels;
0 : Shutdown, shutdown or init 0;
1 :Single user mode (single user), root user, no authentication required; maintenance mode; safe mode;
2 :Multi-user mode (multi user), will start network function, but will not start NFS; maintenance mode, safe mode with network function;
3 : Multi-user mode (mutli user), fully functional mode; text interface; normal mode;
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), fully functional mode, graphical interface; normal mode;
6 : Restart, reboot
Default level: 3, 5;
Level switching: init #
Level view: who -r, runlevel
Configuration file: /etc/inittab
Applicable to CentOS 5 system:
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 this task, #, ###, or empty, means all levels;
action: under what conditions start this task;
process: task;
action: define when and how the task starts
wait: Execute once when waiting to switch to the level of this task;
respawn: Once this 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 mode, here is generally designated /etc/rc.d/rc.sysinit script;
For example: /etc/inittab file:
id:3:initdefault:
si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc 0 Pass parameter 0
l1:1:wait:/etc/rc.d/rc 1
…………
l6:6:wait:/etc/rc.d/rc 6
It 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##, the priority, the smaller the number, the more priority it is to close; the dependent services are closed first, and then the dependent services are closed;
S
: The service to be started; S##*, the priority, the smaller the number, the more priority it is to start; the dependent service is started first, and the dependent service is started later;
For the same service, the number of shutdowns is larger, the number of startups is smaller.
rc script: accept a run level number as a parameter;
Script framework:

for  srv  in/etc/rc.d/rc#.d/K*;do
	$srv  stop
done
										
for  srv  in/etc/rc.d/rc#.d/S*;do
	$srv  start
done

/etc/init.d/* (/etc/rc.d/init.d/*) (two directories are links) script execution mode:
# /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 of /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 runlevel Start priority Shutdown priority
# description:

Delete: chkconfig --del name
Modify the specified link type:
chkconfig [--level LEVELS] name <on|off|reset>
-Level LEVELS: Specify the level to be controlled; the default is 2345;
Note: In the normal level, the last service S99local started 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, programs that are inconvenient or do not need to be written as service scripts can be directly placed in this script file when they are expected to be automatically run on startup.

tty1:2345:respawn:/usr/sbin/mingetty tty1
......
tty6:2345:respawn:/usr/sbin/mingetty tty6	
tty7:5:respawn:/etc/X11/

mingetty will call the login program; login is a program used to log in. In addition to mingetty, there are programs such as getty that open virtual terminals.

  1. CentOS 5 system initialization script: /etc/rc.d/rc.sysinit
    (1) Set the hostname;
    (2) Set welcome message;
    (3) Activate udev and selinux;
    (4) Mount all file systems defined in the /etc/fstab file;
    (5) Detect the root file system, and remount the root file system in read-write mode;
    (6) Set the system clock;
    (7) Set the kernel parameters according to the /etc/sysctl.conf file;
    (8) Activate lvm and soft raid equipment;
    (9) Activate the swap device;
    (10) Load drivers for additional devices;
    (11) Cleanup operation.
  2. The init program of CentOS 6 is upstart, but the init command is still /sbin/init, and its configuration files are /etc/init/*.conf, /etc/inittab (only used to define the default run level).
    Note: *.conf is an upstart style configuration file.
    rcS.conf: system initialization script;
    rc.conf: start and close the service;
    start-ttys.conf: Start the virtual terminal.
  3. The init program of CentOS 7 is systemd, the configuration file is /usr/lib/systemd/system/, /etc/systemd/system/, which is fully compatible with the SysV script mechanism. Therefore, the service command is still available. However, it is recommended to use the systemctl command To control the service:
    # systemctl {start|stop|restart|status} name[.service]

Recommended Posts

CentOS system startup process
Centos system process management
Do you know the CentOS system startup process?
Do you know the CentOS system startup process?
Centos6 system boot loading process
Linux centos system boot process
Centos7 notes | operating system startup process, Linux users and permissions
centos system management
01 CentOS 7.6 switch system language
CentOS7.5-1804 system kernel upgrade
VirtualBox install CentOS system
Centos7.2 system optimization original
Centos various time [system time/hardware time]
Centos7 system commonly used commands
Graphical centos installation detailed process
Install docker on Centos system
Centos system modify time zone
centos6.5: gcc upgrade (5.2.0) process record
Centos backend system setup record
Centos7 installation tomcat process introduction
CentOS8 Linux 8.0.1905 installation process (illustration)
CentOS 6.X system initialization script
CentOS 8 (2)
CentOS 7.X system installation and optimization
CentOS 8 (1)
CentOS7.2 install lepus database monitoring system
Install Centos7 operating system in Docker
001. Installation of enterprise-level CentOS7.6 operating system
CentOS 7 system installation and configuration graphic tutorial
Graphic KVM to install CentOS7.6 operating system
CentOS7 installs IT asset management system Snipe-IT
CentOS7 system increase swap operation method example
Linux kernel compilation and CentOS system installation
Centos7.6 operating system installation and optimization record
Install mysql8.0.13 version under Linux CentOS7 system
[Centos8] The bumpy process of installing docker
CentOS7 system yum way to install MySQL5.7
IP address problem after restarting CentOS 7 system
CentOS7 build FastDFS distributed file system (below)