CentOS system Start-up process

Source: Internet
Author: User
Tags network function

Not just click on the power button, and turn off the power button just turn off it? That's true, but since Linux is a multi-tasking operating system, you don't have to be online when you're shutting down, and if you happen to have a large group of people working online when you turn it off, you're going to get disconnected from the people who were working online! That's not killing people! Some of the data is priceless.

In addition, Linux in the implementation of the time, although you on the screen just will see a dense, completely no picture, but in fact, he has a lot of programs in the background, such as login file control program, routine work scheduling, of course, there are a lot of network services, such as mail server, WWW server and so on. If you shut down casually, it is very easy to hurt the hard drive and data transmission operation! So in Linux under the opening of the machine is a door brainiac.


The composition of Linux is: Kernel + rootfs

kernel: process management, memory management, network management, drivers, file systems, security features

rootfs: programs and GLIBC

Libraries: function sets, functions, calling interfaces (header file is responsible for description)

Procedure call: Procedure, no return value

Functions Call: function

Program: Binary Execution file

Kernel design Genre:

Single core (monolithic kernel): Linux

Integrate all functions into the same program

Microkernel (micro kernel): Windows, Solaris

Each feature is implemented using a separate subsystem



Linux kernel Features:

Support modularity:. KO (Kernel object)

Such as: File system, hardware driver, network protocol, etc.

Supports dynamic loading and unloading of kernel modules

Part:

Core file:/boot/vmlinuz-version-release

RAMDisk: Auxiliary pseudo-root system

CentOS 5:/boot/initrd-version-release.img

centos6,7:/boot/initramfs-version-release.img

Module file:/lib/modules/version-release



Since start-up is a serious matter, let's take a look at the startup process:


Introduction to the system startup process:

1, load the BIOS hardware information and self-detection, and according to the settings to obtain the first bootable device;

2. Read and execute the boot loader (both Grub,spfdisk and so on) of the MBR within the first boot device;

3, according to boot loader settings load kernel, kernel will start to detect hardware and load drivers;

4, after the hardware driver succeeds, kernel will take the initiative to mobilize the INIT process, and Init will obtain run-level information;

5. Init executes the/etc/rc.d/rc.sysinit file to prepare the operating environment for software execution (e.g. network, time zone, etc.);

6, init execution run-level the start of each service (script mode);

7, init execution/etc/rc.d/rc.local file;

8, init execution Terminal simulator Mingetty to start the login program, and finally wait for the user to log in.


Detailed Description:


1, load the BIOS hardware information and self-detection, and according to the settings to obtain the first bootable device;

The boot system first loads the BIOS and loads the CMOS information through the BIOS and then obtains the host's hardware configuration information through the CMOS settings.

Then post the post (power-on Self test). Begins the initialization of hardware detection. The next step is to start the data read of the device.



POST: Power-on-self-test, power-on self-test, is a major part of the BIOS function. Responsible for the CPU, motherboard, memory, hard disk subsystem, display subsystem, serial parallel interface, keyboard, CD-ROM drive and other hardware conditions detection.

ROM: The BIOS (basic input and output system) holds the most important basic input and output programs for computer systems, System Information settings, power-on and self-test programs, and system startup bootstrap programs.

RAM: CMOS complementary metal oxide Semiconductor, save the parameters of the setting, in order to find the boot device, the first device with a boot program for this boot device





2. Read and execute the boot loader of the MBR within the first boot device

Because the system software is stored in the hard disk, so the BIOS will specify the boot device, so that we can read to the system's kernel files, due to different operating system file system format, it is necessary to use a boot loader to handle the kernel file loading problem. This program is then turned into boot loader. The boot loader program is installed in the first sector of the boot setup, which is inside the MBR.


think: Here's an interesting question:

Since the kernel files need loader to read, each operating system loader are different, then how does the BIOS find the loader inside the MBR?

In fact, the BIOS is through the hardware of the INT 13 interrupt function to read the MBR, as long as the BIOS can detect your disk, then he can read the first sector of the disk through the 13来 of the MBR information, so that the boot loader can be executed.


bootloader: bootloader, boot loader

① provides a menu, the user can choose different startup items, which is also an important function of multi-boot;

② load Kernel file: Direct point to the bootable program section to start the operating system;

③ Transfer to other loader: to transfer the bootloader to the other loader for execution;

Because of the function of the menu, we can now start the system with different kernels, and because it has the function of handing over to the other loader, it can be realized, one machine multi system.

But:

Windows:ntloader, only the OS is started, Windows does not have control over the default function,

Linux: Feature rich, provide menus that allow users to choose which system to boot or different kernel versions, load the user-selected kernel into a specific space in memory, unzip, expand, and transfer control of the system to the kernel

Therefore, to implement multi-system, can only install Windows, and then install Linux, because Linux can take control of the bootloader to the windows to manage. At this point, the Windows loader will take over the startup process so that the kernel files can be loaded.



3, according to boot loader settings load kernel, kernel will start to detect hardware and load drivers;

Linux will unzip the kernel into memory and take advantage of the kernel's capabilities to start testing and driving various peripherals, including CPUs, storage devices, network cards, and so on. The kernel will also re-examine the hardware for its own functionality. Instead of using the hardware information that the BIOS detects, that is, the kernel begins to fully take over after the BIOS is started.

So where does the kernel file reside?

In general, the kernel file is stored in/boot, and named Vmlinuz 650) this.width=650; "Src=" http://s2.51cto.com/wyfs02/M01/87/20/ Wkiol1fvmwwqwra1aaam7ff6ua4660.png "style=" Float:none; "title=" 12.png "alt=" wkiol1fvmwwqwra1aaam7ff6ua4660.png "/ >

    • CONFIG-2.6.32-642.EL6.X86_64: This version of the kernel is compiled with the selected feature and module configuration file;

    • Grub: Boot loader grub Related Data directory

    • SYSTEM.MAP-2.6.32-642.EL6.X86_64: The corresponding table where kernel functions are placed into memory addresses

    • INITRAMFS-2.6.32-642.EL6.X86_64.IMG: Virtual file System files

    • VMLINUZ-2.6.32-642.EL6.X86_64: Kernel file!



According to the names of these files, we can also know that this version of the Linux kernel is 2.6.32-642.el6.x86_64 this version, because the Linux kernel can be dynamically loaded kernel modules (that is, drivers), these modules are stored in the/lib/modules/directory. Because the module is placed in the root directory of the disk, the kernel must mount the root directory during startup so that it can read the functionality of the load driver provided by the kernel module.

To prevent impact to the on-disk file system, the root directory is mounted in read-only form during startup.



Bootloader is the boot loader for the system. Typically, the bootstrapper is installed in bootloader. As an example of our common Grup, grub is divided into stage1,stage1.5,stage2. Where the Stage1 code is stored directly in the MBR. When the BIOS passes control to the MBR, the STAGE1 code begins to run, and it is primarily responsible for loading the contents of stage1.5 or Stage2 in memory. After the stage2 is loaded into memory, the grub configuration file is read grub.conf

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/87/22/wKioL1fVSBCTMY3nAAAfPP-buX8570.png "title=" 14.png "alt=" Wkiol1fvsbctmy3naaafpp-bux8570.png "/>


think: now encountered a problem, the kernel does not know the device, so need to load the driver, but the driver is in the/lib/modules/directory, and the root directory is now no way to mount, that is how to read to/lib/modules/ The driver in the directory?

In this case, the Linux system relies on the virtual file system to solve this problem,


Virtual file system (Initialram disk):

The general file name is: "/boot/initramfs-version number. img" This file can be loaded into memory via boot loader, then emulated into a root directory, and an executable program within the simulation file system that can load the kernel modules that are most needed during the startup process. Typically these modules are drivers for file system and disk interfaces such as RAID,LVM. Once loaded, it will help the kernel recall/sbin/init/to begin the subsequent process ...


System Initialization Process:

POST--Bootsequence (BIOS)--Bootloader (MBR)--Kernel (ramdisk)--ROOTFS (read-only)--init (SYSTEMD)



4, after the hardware driver succeeds, kernel will take the initiative to mobilize the INIT process, and Init will obtain run-level information;


Once loaded, the kernel actively invokes the first process, "/sbin/init", and its function is to prepare the environment for software execution. All operations are planned through the init configuration file,/etc/inittab, and the Inittab has an important setting option, which is the default run level.



operating level: set for the purpose of operation or maintenance of the system; 0-6:7 Levels

0: Turn off the machine

1: Single user mode (root automatic login), one, maintenance mode

2: Multi-user mode, start the network function, but do not start NFS; Maintenance mode

3: Multi-user mode, normal mode, text interface

4: Reserved level, can be same as 3 level

5: Multi-user mode, Normal mode, graphical interface

6: Restart


Default Level: 3, 5

Toggle Level: Init #

viewing level: RunLevel; Who-r




Init reads its initialization file:/etc/inittab

Initial runlevel (Run level)

System initialization Scripts

Script directory corresponding to run level

Capturing a keyword order

Define UPS Power terminal/recovery scripts

Generate Getty in Virtual Console

Initialize x at run Level 5






5. Init executes the/etc/rc.d/rc.sysinit file to prepare the operating environment for software execution (e.g. network, time zone, etc.);

In the/etc/inittab file, the phrase "si::sysinit:/etc/rc.d/rc.sysinit" means: Before starting to load various system services, the entire system environment should be done, mainly using/etc/rc.d/rc.sysinit This foot is set up the system environment, so, want to know exactly what the process of CentOS boot, you have to carefully analyze/etc/rc.d/rc.sysinit this file


/etc/rc.d/rc.sysinit: System Initialization script

(1) Set host name

(2) Setting welcome information

(3) Activate Udev and SELinux

(4) Mount the file system 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) Activate swap device

(8) Set kernel parameters according to/etc/sysctl.conf file

(9) Activating LVM and software RAID devices

(10) Loading drivers for additional devices

(11) Cleaning operation


6, init execution run-level the start of each service (script mode);

Loading the kernel lets the entire system prepare to accept instructions to work, and after the initialization of the/etc/rc.d/rc.sysinit system module and related hardware information, your CentOS system should be working smoothly.

But we also need to start the services required by the system so that the host can provide the relevant network or host functions. At this point, based on the run level setting mentioned in/etc/inittab, you can decide which service item to start.

For example, using Run Level 3 is of course not necessary to start the X Window related services.

Each script address launched by different run level services is stored in "/etc/inittab";

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/24/wKiom1fVVtOzMRy2AAAogFQktSs997.png "title=" 16.png "alt=" Wkiom1fvvtozmry2aaaogfqktss997.png "/>

Description:RcN----means reading/etc/rc.d/rcn.d/

k*: k##*:# #运行次序; The smaller the number, the more it runs; the smaller the number of services, usually dependent on other services

s*: s##*:# #运行次序; The smaller the number, the more first it runs; the smaller the number of services, usually the services that are dependent on

For srvin/etc/rc.d/rcn.d/k*; Do $srv Stopdone
For srvin/etc/rc.d/rcn.d/s*; Do $srv Startdone

7, init execution/etc/rc.d/rc.local file;

Once the default runlevel is complete, the file executes the system commands that it wants to execute if there are other actions that you want to complete. That is, any work that you want to do at boot time will be directly written to/etc/rc.d/rc.local, and the work will be loaded automatically when it is powered on. Instead of having to wait for the login system to start.



Note: At normal level, the last service s99local is not linked to/etc/rc.d/init.d a service script, but instead points to the/etc/rc.d/rc.local script


Commands that are inconvenient or do not need to be written as service scripts to be placed in the/etc/rc.d/init.d/directory and run automatically when you want to power on, can be placed directly in the/etc/rc.d/rc.local file

/etc/rc.d/rc.local run After you specify a run-level script

Custom modifications can be made according to the situation



8, init execution Terminal simulator Mingetty to start the login program, and finally wait for the user to log in.

After the boot of all the system services is completed, Linux will then start the terminal or X Window to wait for the user to log in! The actual reference item is in this paragraph in/etc/inittab:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/87/24/wKiom1fVWfvBL0d9AABMPeMHyOQ334.png "title=" 17.png "alt=" Wkiom1fvwfvbl0d9aabmpemhyoq334.png "/>


This section represents, at run Level 2, 3, 4, 5 o'clock, executes/sbin/mingetty, and executes six, which is why Linux provides "six plain text terminal" settings. Because Mingetty is the command to start the terminal.

Note that the Respawn init program, which represents the active restart of the project when the subsequent instruction is terminated (terminal). This is why after we log in to the Tty1 terminal interface, the system will re-display the screen waiting for the user to enter after exiting.

If we are using Run Level 5 then in addition to these six terminals, Init will also execute/etc/x11/prefdm-nodaemon that command, his main function is to start the X Window.



CentOS 6 startup process:

POST--Boot Sequence (BIOS)--Boot Loader--Kernel (RAMDisk)--rootfs--> switchroot-->/sbin/init- (/etc/inittab,/etc/init/*.conf)--Set default run level--system initialization script rc.sysinit--> shut down or start the corresponding level of service--start terminal


The simple diagram is:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/87/26/wKiom1fVdQvTQCFdAAI_VLiTVzI196.png "title=" 6.png " alt= "Wkiom1fvdqvtqcfdaai_vlitvzi196.png"/>



This article is from the "I ' m Groot" blog, so be sure to keep this source http://groot.blog.51cto.com/11448219/1852091

CentOS system Start-up process

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.