CentOS system Start-up process
POST--Boot Sequence (BIOS)--Boot Loader (MBR)--Kernel (ramdisk)--Rootfs (readonly)--Switchro OT--/sbin/init (CentOS 5,6,7 different)--set the default run level--run the system initialization script, complete the system initialization--shut down services that need to be stopped at the corresponding level, start services that need to be turned on at the corresponding levels--& Gt Set up login terminal ( start terminal Graphics Terminal )--Operating system boot complete
CentOS system boot process (kernel level)
1. Post: Power-on self-test
after power on, the system self-test hardware device includes CPU, memory, hard disk, display equipment, etc., this process is called power-on self-check post; Once the power is automatically read ROM there is a live-chip CMOS program and run to find the bootable device in order, The first device with a boot program is the device to be used for this boot, and the bootloader is called the bootloader boot loader.
2.BIOS: Device starting in the first order (basic input and output systems basic inputs and cutput system)
Once the information in the ROM is written, it cannot be modified, and its information is still retained after the power outage. And CMOS is a computer motherboard on a read-write RAM chip after the power is saved in the above data will automatically disappear, need the motherboard battery power, the parameters of the CMOS set to pass a special program, now manufacturers will CMOS Setup program to achieve the BIOS chip, So CMOS settings are also commonly referred to as BIOS settings. BIOS (Basic input and output system) is also cured in the current host ROM chip code, the implementation of the order to find the boot device, the first device with a boot program is the device to use this boot.
3.Boot squence: Boot loader boot kernel
in order to find the boot device, the first device with a boot program is the device to be used for this boot;
bootloader boot loader, program:
Windows: Boot loader by Ntlader
Linux:
(1) Ltlo:linux Loder (cannot support large disk, cannot load after 1024)
(2) Grub:grand Uniform bootloder (Unified boot loader)
GRUB 0.x:grub Legacy (Legacy version)
GRUB 1.X:GRUB2 (second version)
Function: Provide a menu that allows the user to select the system to be launched or a different kernel version, the user selected multi-core loaded into RAM (memory) in the feature space, decompression, deployment, and then transfer the entire system control to the kernel, that is done to load the kernel into memory space.
The bootloader boot loader is a program installed on a hard disk or even a USB flash drive, and the first software code that runs after the system is power-up.
The bootloader boot loader is located in the MBR on disk, and each disk or partition in each disk has mbrmbr that is the first sector on the disk and the master boot sector, which is the first sector that must be read when the computer is powered on to access the hard disk, divided into three parts:
Mbr:master Boot Record (Master boot recording)
512bytes:
446bytes:bootloader (boot program Ltlo or GRUB)
64bytes:fat (partition table, file system Allocation table)
2bytes:55AA(Mark MBR valid)
MBR is produced by a partitioner (such as fdisk,parted), which does not depend on any operating system, and the hard drive boot program can also be changed to enable multi-system booting. Contains only a 64-byte hard disk partition table. Because each partition information requires 16 bytes, it is possible to identify up to 4 primary partitions for a hard disk with MBR-type partition structure (the Disk volume label type is MS-DOS). Therefore, it is not possible to get more than 4 primary partitions for a hard disk with this partition structure. This requires the extension partition, which is also a primary partition (Primary partition), but it differs from the primary partition in that it can theoretically be divided into countless logical partitions, each with an extended boot record (EBR) similar to the MBR structure.
Linux has a variety of boot loader, common with the earliest lilo, disadvantage: Lilo can not support the large hard disk, if the kernel or the loaded system is located on the 1024 cylinder after the partition, Lilo is not loaded, but on the Android phone more widely used, and later by Grub replaced, Grub has two versions of Grub 0.x (grub Legacy) and Grub 1.x (GRUB2) that are completely different from the design concept.
There are several implementations of boot loader bootloader in Linux:
Lilo:liinux LOader
Grub:grand Uniform Bootloader
GRUB 0.x:grub Legacy
GRUB 1.X:GRUB2
GRUB (Boot lloader):
bootloader:1st stage (for MBR bootloader is loading its second stage, not loading the kernel)
Partiton:filesystem driver,1.5 Stage
partition:/boot/grub,2nd Stage
After loading, you can provide an operating system (i.e. an interface) before the operating system, and then load the kernel;
Grub Legacy: Divided into three stages
Stage1: Stored on MBR
Stage1_5: The sector that is stored in the MBR, allowing the bootloader in the Stage1 to identify the filesystem on the partition where the stage2 resides;
Stage2: Disk partition (/boot/grub/)
The bootloader first reads the first stage of the gurb on the MBR, because the MBR is small and only 512 bytes boot the program with GRUB, Then read the stage1.5 stage in the sector, read the 1.5 phase and then can drive the second stage of the disk partition Stage2, stage2 is stored on the partition of the disk and the kernel files and RAMDisk, etc. are stored on this partition, this is why through the bootloader grub can Enough to load the kernel files.
Note: The current hardware platform, the motherboard BIOS must be able to recognize the hard disk, and then the BIOS to load the hard disk bootloader, the disk after the bootloader itself loaded, will be able to identify the current host on the hard disk device.
But the hard disk device can be recognized, does not mean that the hard disk file system can be recognized, because the file system is an additional layer of software organization of the file structure, so to be able to docking a file system, must use the file system driver, the corresponding application must be able to recognize and understand such a file system can, This program is called File system driver Grub's 1.5 phase is to provide GURB with filesystem-driven access to the corresponding second stage and the partition where the kernel resides, which is usually a basic disk partition, so the second phase of grub and the kernel and RAMDisk files are usually placed on a basic disk partition, because grub cannot drive logical volumes. Advanced interface.
Stage2 is generally mounted to the/boot/grub/directory; Grub also has its own configuration file:/boot/grub/grub.conf and usually has a symbolic link file:/etc/grub.conf;
The function of Stage2:
(1) Provide menu or interactive interface;
(2) Can load the user selected kernel or operating system;
(3) The protection mechanism is passed for the menu.
4. Load kernel
(1) After Grub is loaded into the kernel, it is decompressed and expanded in memory to complete the subsequent operation, i.e. the kernel itself is initialized; it is divided into four steps:
First: Detect all hardware devices that can be identified
Second: Load the hardware driver; (it is possible to load the driver with Randisk)
Third: Mount the root file system in read-only mode
IV: The first application running user space:/sbin/init
(It is possible to use the Randisk load driver, RAMDisk: is a memory-based disk device; Mount the root file read-only reason is to prevent bugs in the kernel, to ensure that there is no problem and then change to read-write mode;)
(2) If the kernel compiles the disk device driver that is known as the root file system into the kernel (usually with this driver in its own compiled kernel), this ramdisk is not needed at this time, so the installation system files provided by the Publisher cannot contain all the drivers in the kernel.
In this way, to load the root filesystem, it is necessary to load the disk device driver on which the root filesystem resides, and the drive is at the root so that it cannot rely on the driver on the root to load the root filesystem; load the root file system with the RAMDisk temporary root filesystem to load the drive of the disk device on which the root file system resides ;
RAMDisk temporary root file system is not the operating system publisher directly on the CD-ROM, but after the installation of the operating system temporarily generated, after installing the operating system, it can scan the current host hard drive device model, and find the relevant driver to create a temporary root ; So this temporary root is created dynamically for each user installation process that is generated later.
RAMDisk temporary root is the memory of a certain space as a disk use, and the Linux kernel feature is to use buffering and caching to speed up the file access on the disk, which is why the use of centos5 on the RAMDisk (INITRD), in the later CENTOS6, 7 uses the RAMFS reason to avoid double buffering and double caching in memory.
Spacer.gif
5. Mount the root file system
Once the kernel is loaded with the temporary root provided by RAMDisk to load the device on which the real root filesystem resides, the next step is to mount the root filesystem, which automatically mounts the root filesystem to the root, so that root is the reason in the kernel.
6. Root switch
When mounting the root file system in order to avoid bugs in the kernel or bug in the process of the root file system is damaged, read-only mount the root file system, load is completed before reading and writing mount, complete the entire Mount root file system, directly to find the/sbin/init program, that is, the first program to start running user space.
User space Initiation Process
7./sbin/init Program
The INIT program relies primarily on configuration files:/etc/inittab, which is broadly divided into: Set the default boot level--Set the system initialization script--start the corresponding level of service and print each terminal login interface (if Level 3 processing provides a text login interface, If Level 5 also provides graphical login interface)
8. Set the default run level
(1) Operation level: a mechanism set up for the purpose of running or maintaining the system;
0-6: A total of 7 levels;
0: Shutdown, shutdown
1: Single user mode, root user, no authentication, maintenance mode;
2: Multi-user mode (multi user), will start the network function, but will not start NFS, maintenance mode;
3: Multi-user mode (multi user), full function mode, text interface;
4: Reserved level: Currently no special use purposes, but the habit of using the same 3-level function;
5: Multi-user mode (multi user), full function mode, graphical interface;
6: Restart, reboot
(2) Profile:/etc/inittab defines a number of functions, each defining an action (action) and the corresponding process (only for CentOS 5), one row defines the task that Init will perform, or even a bunch of tasks, with the syntax of each line being: Id:runlevels:action:process
ID is the identifier of a task;
Runlevels: At which runlevel to start this task; example: 3,2345, or null to indicate all levels;
Action: Under what conditions to start this task;
Wait: Executes once while waiting to switch to the level at which the task is located (just when you switch in);
Respawn: Once this task is terminated, it will be restarted automatically, (for example: Login terminal execution logout log out will start again)
Initdefault: Sets the default allowable level, at which time the process is omitted to be empty;
Sysinit: Set the system initialization mode, here is generally designated/etc/rc.d/rc.sysinit script, (CentOS 5,6 Use this script, CentOS 7 is done by Systemd), in the CentOS Only the ability to set the startup RunLevel in this profile is maintained in 6.
Process: a specific task; typically an application, or script, or binary program, depending on the customization.
9. System initialization Scripts
System Initialization script:/etc/rc.d/rc.sysinit
(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) Detecting the root file system and re-mounting the root filesystem in read/write mode; (re-mount refers to the root file after detection)
(6) Set the system clock;
(7) Set kernel parameters according to/etc/sysctl.conf file;
(8) Activating LVM is a soft raid device;
(9) Activate swap device;
(10) Load Drivers for additional devices (kernel load driver only loads root file system)
(11) Cleaning operation;
Note: In the init configuration file:/etc/inittab, there is one line that defines/etc/rc.d/rc.sysinit, which is the script file that is responsible for completing the system initialization.
10. Close/Start the service at the corresponding level
The script file/ETC/RC.D/RC functions to start or stop the service when the level switches, and this script accepts arguments passed to the $runlevel variable in the script, and then reads/etc/rc$runlevel.d/k* and/etc/rc$runlevel.d/s* All files, these files are why the boot started, some services will start automatically, some services do not start the reason.
K*: To stop the service, k##*, priority, the smaller the number, the higher the priority to shut down, the dependent service is first closed, and then closed by the dependent.
S*: To start the service, s##*, priority, the smaller the number, the more priority starts, the dependent service starts first, and the dependent service starts.
The/ETC/RC.D/INIT.D directory also has a link directory for the/ETC/INIT.D directory, and the files are the same in both directories.
11. Start the terminal (graphics terminal)
Operating system startup complete
Related concepts:
Components of the Linux system: Kernel + Root file system
Kernel: Process management, memory management, network protocol stack, file system, driver.
IPC (inter-process communication interprocess communication): refers to the way that multiple processes communicate with each other and exchange information. Linux IPC is basically inherited from the Unix platform. Primarily includes the original UNIX Ipc,system V IPC and socket-based IPC. In addition, the POSIX IPC is supported by Linux.
The system environment in operation can be divided into two layers: kernel space and user space;
Kernel Space: Kernel code (System call)
User space: Application (process or thread)
Kernel design Genre:
Single Core design: Integrate all functions into the same program; (Linux)
Microkernel Design: Each function is implemented using a separate subsystem; (Windows solarls)
Linux kernel Features:
(1) Support modularity:. KO (Kernel object)
(2) Dynamic loading or unloading when module motion is supported
Part:
Core file:/boot/vmliuz-version-release
Ramdirk:
Centos5:/boot/initrd-version-release.img
Centos6,7:/boot/initramfs-version-release.img
CentOS system Start-up process