[Linux Learning Notes] Linux system Boot process (i)

Source: Internet
Author: User

We have described the installation of Linux systems as examples of CentOS and the use of common Linux commands, and we will introduce the Linux system boot process in this section. What happens when the power is pressed and the moment we see the user interface? Hurry and find out.

To boot the process process diagram for a Linux system:

The following is a brief description of the Linux boot process process:

1. Post power-on self-test

The post on Self test first checks each device and, when completed, looks for the device that holds the boot record, finds the boot record that reads into the operating system, and gives the system control to the boot record.

2. MBR Boot

MBR (Master Boot record), MBR records are generally in the disk 0 tracks 1 sectors, a total of 512 bytes, the first 446 bytes is bootloader, the following 4*16 bytes is the storage partition information, the last two bytes is the checksum information.

3. Grub Load Kernel

GRUB (GRand Unified Bootloader) is the first 446 bytes of the MBR, one of the Booloader, and it is the function of selecting the kernel to boot.

grub for loading kernels, viewing grub profiles: <1> CentOS-7 Version Previous system:/etc/grub.conf; <2> CentOS-7 System:/boot/grub2/grub.cfg

After the kernel starts, two things are done: (1) drive hardware; (2) Start the INIT process

4. Start the INIT process

After Init starts, it reads the Inittab configuration file and executes the default RunLevel to continue the boot process. In Unix systems, Init is the first process that can exist, with a constant PID of 1, but it also has to be responsible for a more advanced function: The PID 0 Kernel scheduler (allocates CPU time).

This process contains several steps to CentOS-7 the previous system as an example:

(1) Read/etc/inittab, select the default level < commonly used RunLevel 3: for multi-user; 5:x window environment, content about RunLevel is at the end of this article and is important >

(2) Execute init system script, this script is in/etc/rc.d/rc.sysinit

(3) The script under execution/etc/rc.d/rcx.d/< The default level is 5, then all scripts under RC5.D are read to control when the system starts or shuts down those services >

The script here is broadly divided into two categories, beginning with S and starting with K.

S: Represents the boot-up

K: Indicates that the machine does not start when it is opened

File command format, for example:

S on Sysstat S: Boot start; 01: Start sequence; Sysstat: Startup pin Name

(4) Executes the/etc/rc.d/rc.local script, which is the last script launched during startup and then executes the/bin/login login user.

The following image shows a more specific picture of the process experienced during the system startup process:


Attention:

CentOS-7 version Previous system inittab configuration file storage directory:/etc/inittab

The CENTOS-7 system inittab configuration file is also stored in/etc/inittab, but is not actually configured, but instead leads to the RunLevel configuration file

--------------------------------------------------------------------------------the split line of L v S a n t o r i n i ------- ------------------------------------------------------------------------- 

To set up a boot service or program:

(1) Determine the operating level of the system

(2) Write script file and give file executable permission

(3) Create the corresponding soft connection file in the corresponding RCN.D directory (n indicates the runlevel: 1,2,3,4,5,6)

Note: The soft connection file name is named with the startup script naming specification, for example: S10sysstat

This way, the next time the device restarts, the custom startup script can be executed.

Example (prior to CentOS 7) < This segment because there is no device environment, not verified, the reader can see below with chkconfig to add the boot service example ;

[[Email protected] rc5.d]# cd /etc/rc.d/rc5.d[[email protected] rc5.d]# pwd /etc/rc.d/rc5.d[[email protected] rc5.d]# vi /etc/rc.d/init.d/start.script [[email  protected] rc5.d]# cat /etc/rc.d/init.d/start.script date >> /home/ santorini/out.logwho >> /home/santorini/out.logls -l /etc >> /home/ santorini/out.log[[email protected] rc5.d]# ll /etc/rc.d/init.d/start.script - Rw-r--r--.  1 root root 101 nov 16 21:36 /etc/rc.d/init.d/start.script[ [email protected] rc5.d]# chmod 755 /etc/rc.d/init.d/start.script [[email  Protected] rc5.d]# ll /etc/rc.d/init.d/start.script -rwxr-xr-x. 1 root root  101 nov 16 21:36 /etc/rc.d/init.d/start.script[[email protected] rc5.d]#  ln -s /etc/rc.d/init.d/start.script s20definebysantorini[[email protected] rc5.d]# lltotal  0lrwxrwxrwx. 1 root root 20 nov 14 10:24 k50netconsole -> &NBSP, .... /init.d/netconsolelrwxrwxrwx. 1 root root 17 nov 16 21:00 s10network &NBSP;-&GT;&NBSP, .... /init.d/networklrwxrwxrwx. 1 root root 29 nov 16 21:39  S20definebysantorini -> /etc/rc.d/init.d/start.script

After introducing the following Chkconfig command, we will give the CentOS-7 system how to run the installation self-start service.

Chkconfig command:

The Chkconfig command is primarily used to update (start or stop) and query run-level information for system services. Chkconfig does not immediately automatically disable or activate a service, it simply changes the symbolic connection.

Syntax: chkconfig [--add][--del][--list][system service] or Chkconfig [--level < rank code >][system service][on/off/reset] parameter usage:--add Adding the specified system service, allowing the CHKCONFIG directive to manage it, and adding relevant data to the system-initiated narrative file; --del deletes the specified system service, is no longer managed by the Chkconfig directive, and deletes the relevant data in the system-initiated narrative file; --level< Level code > Specify which execution level the read system service is to turn on or off; verbose: Chkconfig--list [name]: Displays the run state information (on or off) of all run-level system services. If name is specified, only the state of the specified service at a different run level is displayed. Chkconfig--add Name: Add a new service. Chkconfig ensure that each run level has a start (S) or Kill (K) entry. If one is missing, it is automatically created from the default init script. Chkconfig--del Name: Deletes the service and removes the associated symbolic connection from the/ETC/RC[0-6].D. Chkconfig [--level Levels] Name: Sets whether a service is started, stopped, or reset at the specified run level.

CENTOS-7 system installation Self-starting service:

[[Email protected] init.d]# pwd/etc/rc.d/init.d[[email protected] init.d]# vi  defined [[email protected] init.d]# cat defined #!/bin/bash#chkconfig:  5 10 90    (note 10 for start priority, 90 for stop priority,  5 for Run level) #description:  definedate  >> /Hello.logls -l /etc >> /Hello.log[[email protected]  Init.d]# ls -ltotal 36-rw-r--r--.  1 root root    97 nov  17 21:49 defined-rw-r--r--.  1 root root 13430 Jan 15   2015 functions-rwxr-xr-x. 1 root root  2989 jan 15  2015  netconsole-rwxr-xr-x. 1 root root  6470 Jan 15  2015  Network-rw-r--r--.  1 root root  1160 Mar  6  2015  Readme[[email protected]&nBsp;init.d]# chmod 755 defined [[email protected] init.d]# ls -ltotal  36-rwxr-xr-x. 1 root root    97 Nov 17 21:49  Defined-rw-r--r--.  1 root root 13430 Jan 15  2015  functions-rwxr-xr-x. 1 root root  2989 jan 15  2015  netconsole-rwxr-xr-x. 1 root root  6470 jan 15  2015  Network-rw-r--r--.  1 root root  1160 Mar  6  2015  readme[[email protected] init.d]# chkconfig --add defined [[email protected ] init.d]# cd /etc/rc.d/rc5.d[[email protected] rc5.d]# pwd/etc/rc.d/rc5.d[[ Email protected] rc5.d]# lltotal 0lrwxrwxrwx. 1 root root 20 nov  14 10:24 K50netconsole -> .. /init.d/netconsolelrwxrwxrwx. 1 root root 17 nov 17 21:43 s10defined &NBSP;-&GT;&NBSP, .... /init.d/definedlrwxrwxrwx. 1 root root 17 nov 16 21:00 s10network &NBSP;-&GT;&NBSP, .... /init.d/network

CentOS-7 install self-starting service steps:

(1) The script to execute when the new boot is started in the/ETC/INIT.D directory, and gives execute permission

(2) Use the Chkconfig--add command to add the startup service. (after executing this command, the corresponding soft link file is generated under the corresponding RunLevel rcn.d, and the soft link points to the execution script just created under/ETC/INIT.D)

+++++++++++++++++++++++++++++++++++++++++++ o t H E r I N T r o D U C t I o N ++++++++++++++++++++++++++++++++++++++ ++++++++++ Related concepts:

CMOS: In the computer field, CMOS often refers to the chip that holds the basic startup information of a computer (such as date, time, startup settings, etc.). Sometimes people will mix CMOS and bios, in fact, CMOS is a read-write parallel or serial flash chip on the motherboard, is used to save the BIOS hardware configuration and user settings for certain parameters.

Hardware clock (hwclock) and software clock (System time):

[Email protected] ~]# Date # #软件时钟Sat Nov 08:28:12 CST 2015[[email protected] ~]# Hwclock # #硬件时钟Sat 2015 08: 27:35 AM CST-0.192386 seconds

Hardware and software synchronization clock in time settings:

-S,--hctosys set the system time from the hardware clock # #将系统时间设置为硬件时钟-W,--SYSTOHC set the hardware Cloc K from the current system time # #将硬件时钟设置为系统时间 [[email protected] ~]# hwclock--set--date= "2011-08-14 16:45:05" # #设置硬件时钟时 room [[email protected] ~]# date [-u|--utc|--universal] [MMDDHHMM[[CC]YY][.SS]] # #设置系统时间

RunLevel (RunLevel):

RunLevel is used to represent the system state after the end of the init process , there is no fixed information in the hardware of the system to represent RunLevel, it is purely a software structure. Init and Inittab are the only reasons runlevel affect the state of the system. The following is a brief description of each runlevel RunLevel:

0-halt shutdown, let Init shut down all processes and shut down the machine;

1-single user mode, only system administrator access, no graphical interface, in this mode processing in the user can not make changes to the file;

2-multiuser,without NFS allows the system to enter multi-user mode, no graphical interface, but does not support file sharing, this mode is seldom applied;

3-full multiuser mode is the most common mode of operation, mainly used to provide real multi-user mode, but also the default mode of most servers;

4-unused is generally not used by the system;

5-X11 initializes the system to a dedicated X window terminal;

6-Close all running processes and restart the system ( the system will restart continuously ).

Run-level switching:

[[Email protected] ~]# Init 5

Inittab File Analysis:

In Inittab, all entries take the following format: id:run-levels:action:process

ID: identifier, typically two-bit letters or numbers

Run-levels: Specifies the run level, you can specify multiple

Action: Specifying the Run state

Process: Specify the script/command to run

=====

Action Common values:

Initdefault: Specifies the operating level of the system default boot;

Sysinit: System starts execution of the command specified in process

Wait: Executes the command specified in process and waits for its end to run other commands

Once: Executes the command specified in the process without waiting for it to end

Ctrlaltdel: Executes the command specified by process when Ctrl+alt+del is pressed

Powerfail: Executes the command specified by process when a power error occurs and does not wait for it to end

Powerokwait: Executes the command specified by process when power is restored

Respawn: Once the command specified by the process terminates, rerun the command


[Linux Learning Notes] Linux system Boot process (i)

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.