Detailed explanation of CentOS 6 System Startup Process

Source: Internet
Author: User
Tags network function

Detailed explanation of CentOS 6 System Startup Process

Step 1: POST power-On Self-Test)

Implement POST by integrating the BIOS program in RAM on the motherboard
ROM: CMOS on the motherboard: A read/write parallel or serial FLASH chip on the motherboard. It is used to save the BIOS hardware configuration and set certain parameters. (BIOS setup programs are generally integrated into the chip by the vendor, so BIOS settings are sometimes called CMOS settings .)
BIOS: Basic Input and Output System
You can use the BIOS to search for boot devices in sequence. The first device with a boot program is used for this start.

Step 2: load and run bootloader
Bootloader: Boot Loader (Program)
The bootloader used in Windows is ntloader.
Linux: LILO (LIinux LOader)
GRUB: Grand Uniform Bootloader
GRUB 0.X: Grub Legacy (used in CentOS 6)
GRUB 1.X: Grub2 (used in CentOS 7)


Function: provides a menu that allows you to select the system to be started or different kernel versions. It loads the selected kernel to a specific space in RAM, decompress and expand it, then, the system control is handed over to the kernel.



The bootloader of the ext series and GPT series file systems is the first 446 bytes in the MBR, And the MBR is the first sector (1st stage) of the disk, totaling 512 bytes.
MBR: Master Boot Record
First 446 bytes: bootloader
Then 64 bytes: fat (different in the GPT File System)
2 bytes: 55AA (Partition Table validity ID)
Load and run GRUB in three steps
1st stage:
Partition: filesystem driver, 1.5 stage
Partition:/boot/grub, 2nd stage

You can view my other blog for detailed GRUB running process:

Step 3: load the kernel
1. initialize the kernel after it is loaded.
2. detect all recognizable hardware devices;
3. Load the hardware driver. (The ramdisk may be used to load the driver. The ramdisk file needs to be placed in the same partition as the kernel. If you need to use it, you need to specify its location in the previous grub step, if the driver of the hardware device has been compiled into the kernel during kernel compilation, no ramdisk is required)

Note: For ramdisk information, check my other blog:


Step 4: mount the root file system in read-only mode

Step 5:Switchroot)


Step 6: run the first application of the user space:/sbin/init to initialize the system and set the system running level.

/Sbin/init/defines the running process through its configuration file
Configuration File: All files ending with. conf in the/etc/inittab and/etc/init/directory.

/Etc/inittab: used only to define the default running level (in CentOS 6)

Note: In CentOS 5, this file is not only used to define the default running level of the system. It is also used to define the system initialization and subsequent processes.

Example: id: 3: initdefault:
Si: sysinit:/etc/rc. d/rc. sysinit (set the system initialization Mode)
L0: 0: wait:/etc/rc. d/rc0
L1: 1: wait:/etc/rc. d/rc1 (start or close/etc/rc when the running level is 1. d/rc3.d/services controlled by the service scripts under the Directory)
............
L6: 6: wait:/etc/rc. d/rc6

For details, see the configuration file/etc/inittab in the CentOS 5 series.

How to set this configuration file:

Each row defines an action and the corresponding process

Format id: runlevels: action: process (four fields separated)

The first field: id: the identifier of a task;
The second field: runlevels: the level at which the task is started; #,##, it can also be blank, indicating all levels;
The third field: action: under what conditions does the task start;
Fourth field: process: task;

Action type:
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. In this case, process is omitted;
Sysinit: sets the system initialization method. Here, it is generally the specified/etc/rc. d/rc. sysinit script;

All files ending with. conf in the/etc/init/directory: define the system initialization and subsequent processes


Running process:

Read the/etc/init/rcS. conf configuration file, which defines two functions.
1. Implement system initialization

Run the system initialization script to initialize the system.
System initialization script:/etc/rc. d/rc. sysinit

Function: (1) set the host name;
(2) set the 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 the driver of the additional device;
(11) Cleanup operations;

2. Define the system running level


Note: (if this parameter is not specified in step 2 grub and is not set in the grub configuration file, the system running level is defined in the/etc/inittab configuration file)

Significance of the operation level: a mechanism set for the purpose of system operation or maintenance;
0-6: 7 levels; 0: shutdown, shutdown
1: single user mode (single user), root user, no authentication required; maintenance mode;
2. In multi-user mode, the network function is enabled, but NFS is not enabled. In maintenance mode;
3. Multi-user mode (mutli user), full functional mode; text interface;
4. Reserved level: Currently, there is no special purpose for use, but it is used to use the same three levels of functions;
5. multi-user mode, full functional mode, and graphical interface;
6. Restart and reboot

Default level: 3, 5

Level switch command: init #
Level view command:
Who-r

Runlevel

Example:

Step 7: Close the services to be stopped at the corresponding level according to the defined system running level, and start the services to be enabled at the corresponding level.


In CentOS 5 and 6, system services are designed as a separate service script. You can run these scripts to manage system services.

These service scripts are all in the/etc/rc. d/init. d/directory.



Service script running mode:


1. Add an execution parameter to the script path
#/Etc/rc. d/init. d/SRV_SCRIPT {start | stop | restart | status}
#/Etc/init. d/SRV_SCRIPT {start | stop | restart | status}
/Etc/init. d is the soft link of the/etc/rc. d/init. d directory.


2. service Command
Command Format:
# ServiceSRV_SCRIPT {start | stop | restart | status}


Under the/etc/rc. d/directory, there are 7 rc #. d subdirectories (# is an integer ranging from 0 to 6, corresponding to the seven system running levels)

These directories have many soft-link files with K # SCRIPT-NAME and S # SCRIPT-NAME,
The linked objects are all service SCRIPT files with the SCRIPT-NAME in the/etc/rc. d/init. d/directory.

In CentOS 5 and 6, the configuration of a single running-level service environment and the configuration of the service environment after the system operation-level switch are based on the above basic implementation.


Configuration process of a single running-level service environment:

1. Read the configuration file/etc/init/rc. cof.


Run/etc/rc in the configuration file. d/rc is used to configure a single running-level system service environment. A location parameter $ RUNLEVEL is passed while running, this parameter is the system running level that has been defined in the previous step. (Note: This script is also used to configure the service environment after the level switch is in progress)


/Etc/rc. d/rc: the script runs the corresponding/etc/rc according to the given position parameter ($ RUNLEVEL. d/rc #. d/The scripts starting with K and S in the directory. The running mode is to run the script starting with K in sequence. The sequence is # from small to large. An execution parameter stop is passed during the running process. Then run the scripts starting with S in sequence. The sequence is # from small to large, and an execution parameter start is passed during running. (Note: This is a brief description. For details about the execution method, see the/etc/rc. d/rc Script code)

Therefore, K indicates the service to be stopped at the system level. # indicates the priority. The smaller the number is, the higher the priority is. Therefore, if this service depends on other services, it should be set to disabled first, the services on which other services depend should be set to disabled.

S indicates the service to be started at the system level. # indicates the priority. The smaller the number, the higher the priority. Therefore, if the service is depended on by other services, it should be set to start first, this service depends on other services and should be set to post-START. (#00-99)

You can use the chkconfig command to manage system services.

Chkconfig command: control the startup or shutdown status of each service script in/etc/rc. d/init. d/rc. d /.

Format
View: chkconfig -- list [name]

Modify the specified link type: chkconfig [-- levelLEVELS] name <on | off | reset>
-- Level LEVELS: Specifies the level to be controlled. The default value is 2, 3, 4, and 5.


Add: chkconfig -- addname
Delete: chkconfig -- delname (only the soft links of the Service script are deleted)

Therefore, if you want to add a system service, you can first write a service script, put it in the/etc/rc. d/init. d/directory, and then run the chkconfig command.

One of the script definition formats of the service that can be added:
#! /Bin/bash
#
# Chkconfig: LLLNN NN
# Description:



Note: In rc2.d, rc3.d, rc4.d, and rc5.d, there is an S99local soft link, that is, this is the last system service started at several levels.

We can see that it does not link the service script under the/etc/rc. d/init. d/directory, but the/etc/rc. d/rc. local script.


It can be seen from the script comment that its function

Therefore, if you want to write a service script when some programs run automatically upon startup, you can directly write the script.


Step 8: Start the terminal
Read the/etc/init/start-ttys.conf configuration file to complete the process of starting the terminal. It is determined that, if the run level is 5, the image terminal will be started after the tty1-6 is started.

Since then, the system has been started.

Note: steps 6 to 8 are implemented by the init program through the configuration file.

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.