CentOS Boot Process
When we use the Linux operating system, as long as we press the power key, some messy code will appear. After a while, the login interface will appear. What did the system do during this period? Now let's talk about what the system has done during this time.
System initialization process: POST --> Bootsequence (BIOS) --> Bootloader (MBR) --> Kernel (ramdisk) --> rootfs (readonly) -->/sbin/init () /sbin/init
Step 1: power-on self-check (POST ·)
After the system is powered on, the hardware self-check is performed. under the control of the computer CPU, a program in the RAM chip is mapped to the ROM address space, and the commands are executed to check whether the hardware is healthy. For example, whether the CPU device, Nic, sound card, and other devices are in good condition. After the check is complete, start BIOS if the hardware and basic hardware are correct.
Step 2: boot Bootsequence (BIOS)
After the system power-on self-check process is completed, the control of the system is transferred to Bootloader. Bootloader is stored on the hard disk. In this case, the machine cannot obtain external storage or network information, such as date and time. Some important parameters are obtained from CMOS. So what is CMOS? The full name of CMOS is Complementary Metal-Oxide semicondu( originally referred to as the hybrid Metal Oxide Semiconductor storage, which is a raw material for large-scale application in IC chip manufacturing) it is a read/write RAM chip on the microcomputer motherboard. It is mainly used to save the hardware configuration of the current system and the setting of certain parameters by the operator. The hard disk must also be formatted as a file system to store things in the operating system, if the boot program wants to load the operating system on the hard disk, it must have a driver that supports the file system format. Unfortunately, the space in the zone 446K cannot be achieved, therefore, this driver will be found in the next sector of MBR, and the driver will be searched for in the second 64-bit bytes. The remaining two bytes are the validation bytes. If the return value is 55AA, is valid. Linux usually uses the/boot/vmlinuz-version-release model, and then the kernel is decompressed and loaded into the memory.
Step 3: load the kernel
After the kernel is imported, the system enters its own initialization process. First, it detects all the recognizable hardware devices, and then it needs to load the hardware driver (possibly using randisk ), next, the root file system will be mounted in read-only mode, and the first program (/sbin/init) of the user space will be run)
At present, the init program has different categories in different centos releases.
On centos5: Sysv init
Configuration File:/etc/initab
On centos6: Upstart
Configuration File:/etc/initab/etc/init/*. conf
On centos7: systemd
Configuration File:/usr/lib/systemd/system/,/etc/systemd/system
What is randisk?
It is one of the features of the Linux kernel: Using Cache to accelerate File Access to the disk
Centos5: initrd tool program: mkinitrd
Centos6, 7: initramfs project: dracut, mkinitrd
Step 4: Boot Loader (GRUB loading)
Grub contains the knowledge of file systems. It can load the Linux kernel from the ext2 or ext3 file system. Once bootloader completes the loader startup phase and finds the position of the boot program, the first step starts to load the boot program to the memory and the second step starts. In the GRUB boot loader stage, the bootloader of the original two sections is converted into three stages.
Stage1: BIOS loads GRUB in mbr. Because it has only 446 bytes, it cannot implement too many functions, so it is necessary to load files in 1.5 stages.
Stage1.5: loads a program that identifies the file system to identify the file system. Without loading, the file system cannot be identified. If the boot cannot be found, the boot partition cannot be set to LVM.
Stage2: start searching for and starting the kernel
Step 4: load the kernel
Geub loads the kernel into the memory and runs it. The kernel is usually compressed. First, decompress it. When the kernel is loaded into the memory, the file system cannot use it. It uses the initramfs when the Bootloader is loaded into the memory. The system places the unzipped kernel in the memory and calls a function to start a series of initialization and various devices.
Step 5: Read the initrd/etc/inittab configuration file
Configuration file/etc/inittab
Each row defines an action and a process with the object.
Id: the identifier of a task.
Runlevel: Enable this service at those levels
Action: under what conditions does the task start?
Process: Task
Action:
Wait: wait for the task to be switched to the current level.
Respawn: This task is automatically restarted once it is terminated.
Initdefault: sets the default running level. At this time, process is omitted.
Sysinit: sets the system initialization method. The/etc/rc. d/rc. sysinit script is generally specified here.
K *: the service to be stopped: K #. The smaller the priority and number, the higher the priority is. The dependent service is disabled first, and then the dependent service is disabled.
S *: the service to be started: S #. The smaller the priority, the higher the priority. The dependent service is started first, and the dependent service is started later.
Chkconfig: Control/etc/init. d/startup or shutdown status of each service script at various levels
View: chkconfig -- list name
Add: chkconfig -- add name
Delete: chkconfig -- del name
Modify the specified connection type:
Chkconfig [-- level levels] name <on | off | restat>
-- Level levels: indicates the level to be controlled. The default value is 2345.
After the kernel is loaded, the first process started is/sbin/init, And the init process reads/etc/initab. The main function of this process is to prepare the software environment, all actions are configured in/etc/initab. Execute initab to set the default running level of the system and use init # To change the default system level.
System Level: 0--7
0: shutdown, shutdown
1: single-user mode. Root User, no authentication required, maintenance mode
2: multi-user mode: network function is enabled, but NFS is not started. Maintenance Mode
3: multi-user mode: full function mode, text interface
4: Reserved level: there is no special purpose at present, but it is used to level 3
5: multi-user mode: full function mode, Gui
6: restart: reboot
Step 6: Start the System Service/etc/rc. d/rc/sysinit
Perform the initialization of/etc/rc. d/rc/sysinit and perform many settings:
1: Set the Host Name
2: Set welcome information
3: Activate udev and selinux
4: Mount all file systems defined in the/etc/fstab file
5: Check the root file system and remount the root file system in read/write mode.
6. Set the system clock.
7: Set kernel parameters according to the/etc/sysctl. conf file
8: Activate LVM and soft RAID Devices
9. Activate the swap device.
10: Load drivers for additional devices
11. cleanup operation
OST --> Boot Sequence (BIOS) --> Boot Loader (MBR) --> Kernel (ramdisk) --> rootfs --> switchroot -->/sbin/init --> (/etc/inittab,/etc/init /*. conf) --> set the default running level --> system initialization script --> close or start services at the corresponding level --> Start Terminal