Linux system startup process

Source: Internet
Author: User

Kernel level startup process :

Post-->bootsequence (BIOS)->bootloader (MBR)-->kernel

650) this.width=650; "Style=" Float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto; Border-left-width:0px;margin-right:auto; "title=" program Start process "border=" 0 "alt=" program Start process "src=" http://s3.51cto.com/wyfs02/ M01/78/f0/wkiom1aexnfguj-vaae_femu_e8851.jpg "width=" 707 "height=" 358 "/>

Post: Power-on self-test to check for the presence of various hardware devices.

Boot Sequence: When the hardware self-test is complete, the BIOS will look up the boot devices in sequence, and the first MBR-enabled device is the one that will be used for this boot. Once a device with MBR is found, control is handed over to the MBR in the first 446 bytes of bootloader for the next step.

The first 446 bytes in the bootloader:mbr are stored in Bootloader, and in the early Linux distributions, Bootloader has been using Lilo,lilo as the mainstream Bootloader in the Linux distribution, However, it does not lead to the 1024 cylinder after the partition, greatly restricting the operating space, so today's Linux distribution bootloader use GRUB, it has a better interface and interface, but also to provide users with interactive interface, use configuration more flexible and convenient. The bootloader then loads the kernel that the user chooses to boot into memory to decompress the expansion, and then the control is handed over to the kernel for the next step.

Kernel: The kernel receives control after it completes its own initialization--all the hardware devices that are recognized--load the hardware driver (possibly with the help of the RAMDisk load driver)--read-only mount the root file system-- First program to run user space:/sbin/init

User level:

Set the default run level-run the system initialization script, complete the system initialization--close the service that needs to be stopped at the corresponding level, start the service that needs to be turned on at the corresponding level, and set the login terminal [--> to start the graphics terminal]

(CentOS5 init program: SysV init)





650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "title=" User-level startup process "border=" 0 "alt=" User level Start Process "src=" http://s3.51cto.com/wyfs02/M00/78/EE/wKioL1aExp-gfqOTAAFOUVoFRaE142.jpg "width=" 789 "height=" 439 "/>

init program start Task :

/sbin/init The configuration file is read when the program starts:/etc/inittab

Various tasks are defined in the configuration file, and each row defines an action and the corresponding process

id:runlevels:actions:process

ID: The identifier of a task;

Runlevels: The level at which this task is started; #,### can also be empty, representing all levels.

Action: Under what conditions 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 will be restarted automatically;

Initdefault: Sets the default RunLevel, at which time the process is omitted

Sysinit: Set the system initialization mode, here is generally designated/etc/rc.d/rc.sysinit script;

First step: Set the default run level

Set the default run level in the/etc/inittab file in CentOS6:

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "title=" 1 "border = "0" alt= "1" src= "Http://s3.51cto.com/wyfs02/M01/78/EE/wKioL1aExp_iQjCjAAAMK6LuOVU233.png" width= "$" height= "69" />

Step three: Run the system initialization script to complete the system initialization

System initialization script file:/etc/rc.d/rc.sysinit

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "title=" 1 "border = "0" alt= "1" src= "Http://s3.51cto.com/wyfs02/M02/78/F0/wKiom1aExoKySXKaAAAPg-x7FMU672.png" width= "616" height= "44" />

(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) Detect the root file system, and re-mount the root file system in read-write mode;

(6) Set 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 the drivers for additional devices;

(11) Cleaning operation;


Step three: Close the service that needs to be stopped at the corresponding level, start the service that needs to be opened at the corresponding level

1 Some services we need to shut down or turn on automatically when booting up, these service scripts are stored in/etc/init.d/* (/etc/rc.d/init.d/*).

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "title=" 1 "border = "0" alt= "1" src= "Http://s3.51cto.com/wyfs02/M00/78/EE/wKioL1aExqXRU7UnAABB7EsVXkQ238.png" width= "731" height= "170 "/>

How to start or close these scripts: #/etc/init.d/srv_script{start|stop|restart|status}

#/service Srv_script {start|stop|restart|status}

However, it is too cumbersome to start or shut down these scripts one after the other at all levels, in order to facilitate the management of the startup of these services, we need a unified interface, which is the service script. We can achieve the purpose of starting various services by controlling these service scripts.

2) The RC scripts running at all levels are stored in the/ETC/RC.D directory

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "title=" 1 "border = "0" alt= "1" src= "Http://s3.51cto.com/wyfs02/M00/78/F0/wKiom1aExofT1dqfAAAPThYo5wE736.png" width= "617" height= "46" />



RC Script: Accept a run-level number as parameter

L0:0:WAIT:/ETC/RC.D/RC 0 means to start or close services controlled by service scripts under the/etc/rc.d/rc0.d/directory

L0:1:WAIT:/ETC/RC.D/RC 1

L0:2:WAIT:/ETC/RC.D/RC 2

.......

L0:6:WAIT:/ETC/RC.D/RC 6

K*: The service to be stopped, k##*, priority, the smaller the number, the more priority to shut down, the dependency of the service is closed first, and then shut down the dependent services.

S*: The service to start, s##*, priority, the smaller the number, the higher the priority to start, the dependent service starts first, and then the dependent service is started.

And we need to start or shut down these services at all levels of the system, we need to pass parameters to these scripts at boot time, in order to pass parameters to these scripts, we need to/etc/rc.d/rc#. D These levels are running in the RC script to create a soft connection to the INIT.D, starting with the start of the starting, the beginning of K indicates power-on shutdown.

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "title=" 1 "border = "0" alt= "1" src= "Http://s3.51cto.com/wyfs02/M01/78/F0/wKiom1aExouimPfrAABurMxjnBo624.png" width= "621" height= "249 "/>

650) this.width=650; "Style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0 px; "title=" 1 "border=" 0 "alt=" 1 "src=" Http://s3.51cto.com/wyfs02/M01/78/EE/wKioL1aExq_g_uooAABW4VxPgOc952.png " Width= "676" height= "199"/>

Now we need to work out how to create these connections for these scripts that can be started or closed automatically.

3) We can use the Chkconfig command to control the opening or closing of each service script under/etc/init.d/* at/etc/rc.d/rc#.d levels .

① View script: Chkconfig--list[name]

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "title=" 1 "border = "0" alt= "1" src= "Http://s3.51cto.com/wyfs02/M02/78/EE/wKioL1aExrOjiW-iAABzgwssJ3w982.png" width= "545" height= "426 "/>



② Add service script: Chkconfig--add name

The service script that can be added defines the format:

#! /bin/bash

#

#chkconfig: ll nn nn (ll indicates that at those levels are started, the first NN is the start level number, the second NN is the off-level number)

#description

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "title=" 1 "border = "0" alt= "1" src= "Http://s3.51cto.com/wyfs02/M02/78/F0/wKiom1aExpezX3ARAAAy1vb9jE0570.png" width= "545" height= "179 "/>

, which indicates that the service script is automatically run in level 345 after it is added. Automatic shutdown in level 0126 .

③ Modify the specified link type: (only valid on current system, invalid after reboot)

Chkconfig [--level levels] name <on|off|restart>

--level levels: Specifies the level to be controlled; default is 2345;

Note: In the/etc/rc.d/directory there will be a rc.local file, in order to run the last step in the boot, when we are not able to write script or do not need to write service script but also expect to change the program boot, directly placed in this script file.

Fourth Step: Define the virtual terminal at all levels

Tty1:2345:respawn:/usr/sbin/mingetty tty1
... ...
Tty6:2345:respawn:/usr/sbin/mingetty Tty6
(1) Mingetty will invoke the login program;
(2) Open the virtual terminal program in addition to Mingetty, there are such as Getty, etc.







CentOS6:

Init program: Upstart style, but still/sbin/init, with config file:/etc/init/*.conf,/etc/inittab (set default RunLevel only)

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; " title= "1" border= "0" alt= "1" src= "Http://s3.51cto.com/wyfs02/M00/78/EE/wKioL1aExrij8EszAAAmFKA5vTU236.png" width= " 690 "height=" 111 "/>

As shown, in CentOS6 only the configuration file is cut into a different configuration file fragment ending in. conf, each file controls one configuration content.

rcs.conf: System initialization script. RC.D: Start or close various services. START-TTYS.D: Which terminals are started.

CentOS7:

Init program: systemd, config file:/usr/lib/systemd/system/*,/etc/systemd/system/*
Fully compatible with the SYSV scripting mechanism; Therefore, service commands are still available;

However, it is recommended to use the SYSTEMCTL command to control the service;
# systemctl {start|stop|restart|status} Name[.service]

(When Init starts in CentOS7, all services are not started by default and are started when the first access is started)

Linux system startup process

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.