POST (Power on Self Test) power-on from the BIOS (Boot Sequence)--MBR (bootloader)-->kernel--INITRD---Rootfs (/SB In/init)
Here is a detailed explanation of each startup process:
Post (Power onself Test) power-on self-test
The computer itself does not execute any program, so the system must complete the bootstrap process, under the control of the CPU to map a program in the RAM chip to the address space of the ROM, and execute the instructions to complete the system hardware health checks, such as storage devices, network cards, The CPU sound card and other hardware devices are intact. When the check is complete, all hardware or basic, core hardware is not a problem, the next boot process-->bios
BIOS (Boot Sequence)
According to the system boot process set by BIOS, the MBR of the OS on the storage device is searched from top to bottom based on boot order (boot Sequence), then the bootloader in the MBR is read.
MBR (bootloader)
The Bootloader,bootloader in the system partition based on the active partition that the MBR directs is called a program that occupies 446 bytes. In Bootloader, the location of the kernel to boot the operating system is configured, so after the BIOS is loaded into memory, when it implements transferring control permissions to bootloader, Bootloader receives control of the entire system, Then according to the user's choice to read the kernel in the corresponding operating system, and the kernel into a space in memory, decompression, then kernel can be active in memory, and according to the function of kernel itself in memory to explore hardware and load hardware drivers and complete the kernel initialization, Bootloader will transfer control permissions to the kernel.
Kernel Kernel (Initialize)
We know that kernel is completing the exploration hardware and loading the hardware drivers and mounting the root filesystem in a read-write manner. Then there is a more bizarre question, what is the problem?
We also know that in order to access the real root file system (ROOTFS), you have to load the root file system of the device, then the root file system is not mounted, to mount the root file system and to load the root file system driver, how to do? The Initrd file is used here.
Explore hardware--load driver (INITRD)--mount root file system-->rootfs
(/sbin/init)
INITRD function Introduction
In fact, INITRD is a virtual file system, which has/, lib, bin, sbin, usr, proc, sys, VAR, dev, boot and other directories, in fact, you will find the contents of a bit like the real/, So what we call the virtual root filesystem is to connect the kernel with the real root filesystem, let kernel go to initrd to load the driver required by the root filesystem, mount the root filesystem in read-write mode, and let the first process init of the user be executed.
/sbin/init (/etc/inittab)
/sbin/init startup uses entries defined by/etc/inittab, such as the default login level Id:3:initdegault: (This is the default start Level 3)
Here's a look at what/etc/inittab is working on:
/etc/inittab
Default Run Level
0:halt
1:single user mode (single-user maintenance mode)
2:multi user mode, without NFS (NFS feature not supported)
3:multi user Mode,text mode (character interface)
4:reserved (System reserved)
5:multi user mode, graphic mode (graphical interface)
6:reboot (restart)
System Initialization (/ETC/RC.D/RC.SYSINIT)
Detect and mount the root file system in read and write mode
Set host name
Detect and mount other file systems in/etc/fstab
Start swap partition
Initializing peripheral Hardware Device drivers
Set kernel parameters according to/etc/sysctl.conf
Activating Udev and SELinux
Activating LVM and RAID devices
Purge expired lock files and PID files
Load key Mapping--the function of each key on the keyboard
Run a service script at the specified level
/etc/rc.d/init.d/
/etc/rc.d/rc#.d
Rc0-rc6
k* # #只要以K开头文件均执行stop工作
s* # #只要是以S开头的文件均执行start工作
0-99 (execution order, the smaller the number is first executed)
Init execution/etc/rc.d/rc/local
Init executes the interrupt machine emulator Mingetty to start the login process, and finally waits for the user to log in
Let's talk about the/etc/inittab format and syntax:
"Set options": "RunLevel": "Init Action Behavior": "Command Options"
Setting options:
Represents the Init main work option
Operating level:
0-6
Init operation Behavior:
Initdefault: Represents the default Run Action option
Sysinit: Represents the system initial session operation option
Ctrlaltdel: Related Settings for restart
Wait: Performs the following actions on behalf of the previous command execution result
Respawn: Represents a trailing field that can be regenerated indefinitely (reboot)
Command options:
Some commands, but they're usually scripts.
Init processing process:
Processing according to/etc/iittab settings: at default Level 3 Description: Id:3:initdefault:
Default runlevel-->/etc/rc.d/rc.sysinit-->/etc/rc.d/rc5.d--> ctrlatdel-->set "PF" and "PR"--minget Ty-->login
Init processing System initial initialization process/etc/rc.d/rc.sysinit (set file system environment)
Get network environment and host type-->/etc/sysconfig/network
Test and Mount Memory devices/proc and/sys
SELinux
Random number generator to start the system
Set the terminal font
To set the Welcome screen during system startup
Set the system time and time zone settings/etc/sysconfig/clock
Interface Device Detection
User-defined module load ——./etc/sysconfig/modules/*modules
Setting kernel parameters according to/etc/sysctl.conf
Initialize the software disk array-->/etc/mdadm.conf
Initializing LVM File system functionality
FSCK detects disk File system
Disk quotas
Detect and re-mount the root file system in read-write mode
Clear the temporary files in the purge process
Information about the launch--/VAR/LOG/DMESG
Start the service with the associated Boot profile (/ETC/RC.D/RC # &/etc/sysconfig)
At the default Level 3 description: Id:3:initdefault:
L3:3:WAIT:/ETC/RC.D/RC 3
Find/ETC/RC.D/RC3.D
file that starts with k* and runs/etc/rc.d/rc3.d/k* stop
File starting with s*, and run/etc/rc.d/rc3.d/s* start
All the files in the/etc/rc.d/rc#.d/are linked to/ETC/RC.D/INIT.D files.
User-defined boot loader (/etc/rc.d/rc.local)
You can write some execution commands or scripts into the/etc/rc.d/rc.local according to your own needs, and when you boot, you can load the
Login with User login (complete system boot) according to Mingetty program call Login
Implementation of several important configuration files during the Linux boot process
After Linux login, the configuration execution order is (Debian serials capable):/etc/environment,/etc/profile, ~/.bash_profile | ~/.bash_login | ~/ ~/.bash_logout,/ETC/BASHRC, ~/.BASHRC,. Profile)
With regard to the role of individual files, the following instructions were found on Linuxsir:
(1)/etc/environment: This configuration file sets the basic path variable, and the system current language variables, although relatively short, but in the system startup occupies a pivotal role, such as the following is the contents of my system:
Path= "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
Language= "Zh_CN:zh:en_US:en"
Lang= "ZH_CN. UTF-8 "
(2)/etc/profile: This file sets the environment information for each user of the system, and the file is executed when the user logs on for the first time. and collect the shell settings from the configuration file of the/ETC/PROFILE.D directory.
(3)/ETC/BASH.BASHRC: Executes this file for each user running the bash shell. When the bash shell is opened, the file is read.
(4) ~/.bash_profile: Each user can use this file to enter the shell information dedicated to their own use, when the user log on, the file is only executed once! By default, he sets some environment variables to execute the user's. bashrc file.
(5) ~/.BASHRC: This file contains bash information dedicated to your bash shell, which is read when you log in and every time you open a new shell.
(6) ~/.bash_logout: Executes the file each time it exits the system (exiting the bash shell). In addition, the variables set in/etc/profile (global) can be applied to any user, while the variables set in ~/.BASHRC, etc. (local) only inherit variables from/etc/profile, they are "parent-child" relationships.
(7) ~/.bash_profile is the interactive, login way into bash run ~/.BASHRC is the interactive non-login way into bash normally the two settings are roughly the same, so the former usually calls the latter.
A detailed description of the Linux startup process and the configuration files needed to use it