To understand the startup process of a Linux system, first understand the composition of the system
about the composition of the system:
Kernel + root File system composition
Kernel: consists of kernel core files and module files
1. Kernel core files: generally located in the/boot/directory, named Vmlinuz-version (version number)
2. module files: In the/lib/modules/version/directory, a number of functional components (such as drivers) that hold the kernel
3.INITRD: under/boot, generally named Initramfs-version, this file is equivalent to a lite version of the root file system, the kernel cannot mount the file system is loaded, the auxiliary kernel to complete the real root file system mount
Add some basic concepts: (easy to understand in the process explained)
(1) CMOS: A read-write RAM chip on the motherboard to save the system's hardware configuration information
(2) BIOS: Basic input/output system, micro-system written to motherboard ROM chip
(3) Mbr:master boot Record, total 512 bytes, 446 byte boot loader,64 byte partition table
(4) Boot loader: Boot manager, Linux boot Manager for GRUB or Lilo
system-initiated brief process:
BIOS post-load boot loader--boot load load kernel file to memory--kernel initialization, INIT process initiated, init initialization, start login terminal
The simple start-up process of the system as shown above, to understand the details, it is likely to be divided into two layers, the kernel level and the user level, the following startup process based on GRUB expansion
Kernel level:
1. Post: After powering on, the BIOS reads the hardware information from the CMOS and reads the boot loader program grub from the first sector of the first boot device after self-test
There are three stages of 2.grub booting: Stage1, Stage1_5, Stage2
Stage1: This phase is not a direct boot to the kernel, but a stage1_5 to the second sector
Stage1_5: Identify file system and load Stage2
Stage2: Locate the kernel and unzip it into memory, retire
3. Kernel initialization, and try to mount the root file system read-only, the root file system mounts, the kernel loads the driver, and finally the kernel starts the first process init
If the kernel cannot complete the root file system mount, you need to load the Initramfs file to assist the root mount
User space level
4. Init program initializes the system environment, obtains the RunLevel by reading Inittab, loads the init script/etc/rc.d/rc.sysinit, completes the service stop and starts according to the corresponding RunLevel, and finally starts the terminal
Note: Initramfs is not required, depending on whether the kernel can mount the root file system
Init initialization: (the CentOS 5 initialization process)
Init is the system first process that the kernel finishes initializing the last step, its PID sets the run level for 1,init read Inittab profile, and then reads the/etc/rc.d/ Rc.sysinit initializes the script, completes the system environment initialization, loads and shuts down the related service according to the RunLevel (related run level service information, through traversing the symbolic connection in the directory corresponding to the RunLevel under/etc/rc.d/, the symbolic connection points to/etc/rc.d/ Script files in the INI.D directory)
Final Launch terminal
configuration file:/etc/inittab
Configuring the system Run level
[Email protected]_linux ~]# cat/etc/inittab # Default RunLevel. The runlevels used are:# 0-halt (do not set Initdefault to this) # 1-single user mode# 2-multiuser, without NFS (The same as 3, if you don't have networking) # 3-full multiuser mode# 4-unused# 5-x11# 6-reboot Set Initdefault to this) # Id:3:initdefault:
0-halt (System direct shutdown)
1-single user mode (single, no login, maintenance)
2-multi-user, without NFS (multi-user system without NFS service)
3-full Multi-User mode (command-line mode with network capability)
4-unused (System hold function)
5-X11 (load x Window, similar to 3)
6-reboot (restart)
Note: The default runlevel do not set to 0 or 6, or the system will shut down and restart
configuration file-related syntax:
Id:runlevel:action:process
ID: Task Flag
RunLevel: The level at which this task is run
Action: The condition to start this task
Process: Task
Action
Wait: Executes once while waiting to switch to the level at which the task is located:
Respawn: Once this task is terminated, it is automatically restarted:
Initdefault: Set default runlevel: At this point, process is omitted:
Sysinit: Sets the system initialization method, where the/etc/rc.d/rc.sysinit script is typically specified:
Example: 2:2:WAIT:/ETC/RC.D/RC6.D
Represents switching to level 2 to perform a rc.6 configuration file once
when the service is initialized, the service with high priority will be stopped or started, and the dependent service should have higher priority than the dependent service, and the stop priority should be lower than the dependent service
/etc/rc.d/rc.sysinit
Initialize the script file, init initializes the system environment by loading this script file
Initializing information
(1) Set host name
(2) Setting welcome information
(3) Activate Udev and SELinux
(4) Mount all file systems defined in the/etc/fstab file
(5) Detecting the root file system and re-mounting the root filesystem in read and write mode
(6) Setting the system clock
(7) Set kernel parameters according to/etc/sysctl.conf file
(8) activating LVM and soft raid devices
(9) Activate swap device
(10) Loading drivers for additional devices
(11) Cleaning operation
/ETC/RC.D/*.D
RC.D directory under the $runevelrc.d named file, the content is corresponding to RunLevel
Symbolic links for services that should be stopped and started, with symbolic connections pointing to script files in the/ETC/RC.D/INIT.D directory
/etc/rc.local: The initialization process finally specifies the execution of the script file, which can be set by this file boot program
chkconfig: Viewing service information at run level
View
Chkconfig [--list] [name]
Add to
Chkconfig--add Name
Delete
Chkconfig--del Name
Modify
Chkconfig [--level level] name {No|off|reset}
Do not specify level defaults to 2345
This article is from "Rock blog" blog, please be sure to keep this source http://johnsonxu.blog.51cto.com/11214707/1757354
Linux boot Process Explained