Linux start-up process detailed

Source: Internet
Author: User

First, why to study the Linux system boot:

Perhaps someone will say, wait for it to turn on the good, why also to study its boot process, in fact, if the server runs very well and no human error operation, and so on, may not need to study, but in order to be able to fix it in the first time after the system problems, Or if you forget the root password and so on, it is necessary to study the Linux boot process, because only know how it works, to make it better service and human, nonsense not to say, the text began

Second, the system start-up process:

Different versions of Linux system boot may be different, but in general, similar, the following centos6.8 system as an example, the Linux boot process.

Post power-on self-test---> MBR boot--grub Boot---> Load kernel---> Start init---> Various initialization scripts run---> Execute/bin/login---> Start-up process ended

650) this.width=650; "alt=" 1111.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473667097485267.png "title=" 1473667097485267.png "/>

1. Power-On self-test:

Power on System test: The power-on self-test is mainly to check whether the hardware is present and functioning properly, including CPU, memory, hard disk, CPU fan, and even the peripheral detection of keyboard and mouse, This part of the program called the BIOS is stored in the CMOS hardware chip, power is to power the CMOS, because CMOS is a ROM chip, so there is a separate RAM chip to store its configuration information, this is why the motherboard to put a battery reason.

2. Select boot order to load MBR (Master boot Recoder) to enable the Bootloader program to load the kernel:

After a series of hardware detection, and successfully passed, will be loaded MBR, MBR stored in the first bootable hard disk in the first partition, the size of 512byte, the 512 bytes of the first 446byte is bootloader, and then the 64 bytes of the partition table, 2byte partition end Flag, the first part of the bootloader section is the first part of the master boot record, because the bootstrapper function is more powerful and will have a driver file, 446byte Word Energy saving storage, the following will introduce its other parts. The first part of the bootloader program calls the data in a portion of the sector after 512 bytes, which includes the drive of the/boot partition, because the software and hardware connections must be driven by the translation, at which time the/boot partition is loaded with the/boot drive, The partition contains the second part of the GRUB program, and the kernel image files, as well as the Initramfs file, if loading/partitioning at this time, because/partition is not necessarily the same file system as/boot partition, different file systems need to drive the file system is different, So grub will load the Initram file into memory decompression, and at this time to load the kernel file, decompression will be in the file system to form a similar/file system in the "/" in the Lib in this case there is a system real/various file system drivers, you can load the root file system

3. Start init and various startup scripts:

Loading the root file system will start the user's first execution program/sbin/init*, which includes/etc/inittab,/etc/init/*.conf (in Centos5 is directly a/inittab file, sequential execution, slower, By 6 o'clock many of the dependent program services are executed first, and no dependencies are executed at the same time, until the 7 o'clock config file becomes/usr/lib/systemd/* at this time the system starts up very fast, many services can be started at the same time, even if the dependencies can be started in parallel, Faster boot speed)

The init file mainly defines the following items:

(1) Boot level selection 0-6 total Seven:

0: Turn off all services shutdown

1: Single-user mode for maintenance mode

2: Multi-user mode for maintenance mode

3: Normal level, multi-user mode

4: Not defined

5: Normal level with graphical multi-user mode

6: Turn off all service reboots

Note: You can use RunLevel or the who-r command to check the current operating level of the system

(2) using/etc/rc.d/rc.sysinit for system initialization

A) set the hostname according to the configuration file

b) Print text welcome message

c) activating SELinux and Udev

d) Mount all file systems defined in the/etc/fstab file

e) Activate swap partition

f) Detecting the root file system and implementing a read-write Mount Root

g) Set the system clock

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

i) activating LVM and RAID devices

j) Load additional device drivers

k) Cleanup operation

(3) Execution selects the appropriate script under boot-up level/ETC/RC.D/RC#.D

/etc/rc.d/rc#.d/The directory is executed according to the/ETC/INIT/RC file to choose whether to start what services, in the RC file to execute a for loop first execute the k* file service to stop, The start of the service starts at the corresponding boot level below are a number of soft link files, which point to the service script below/etc/rc.d/, and these soft link files are the files beginning with S and K, which represents the service to start at that RunLevel, and K begins with a service that does not need to start at that level. , some would say that in the boot is the service will not start, why do you want to stop it? Originally the service did not start, stop it to do what? That's true, but have you ever thought that if the service has been turned on at run Level 3, but you want to switch to RunLevel 5, and the level of 5 happens to not need to start the service? Of course it should stop! Therefore, in the RC script in the For loop used to determine if the/var/lock/subsys/under the service, loop execution continue, skip the start statement to perform the next loop, know the end of the loop,/var/lock/subsys/ As soon as a service is started in the directory, a file is generated in the lock file directory. This enables all system scripts to be started by executing all of the service scripts under/etc/init/init#.d/.

What if you want to define a script that you want to start like a system service?

There are a number of service scripts under/etc/init/init.d/, which you can refer to, including the shell definition of #!/bin/bash as a system-defined script, chkconfig definition, And a description of the related description: Place the written script under the directory using the Chkconfig--{add|del} script name to add or delete the script.

Attached: Service Script Header Example:

[[email protected]_8 init.d]# head -n 12  nfs#!/bin/sh## nfs           this shell  script takes care of starting and stopping#                the nfs services.## chkconfig: -  30 60# description: nfs is a popular protocol for file  sharing across networks.#               this service provides nfs server functionality, which is  #              configured via  the /etc/exports file.# probe: true# config: /etc/sysconfig/nfs 

Of course, in the/etc/rc.local or/etc/rc.d/rc.local two files to define their own script execution path, except that the file defined in the file execution priority is the lowest, to wait until all the system service scripts to execute, to execute

(4) To configure the function of the Ctrl+alt+del key, it is recommended to turn off this feature to prevent mis-operation from restarting the server.

This configuration is directly in the/etc/inittab in Centos5, and after 6, you can see that the configuration has been transferred to the/etc/init/control-alt-delete.conf by commenting out the/etc/inittab file.

(5) configuration of the continuous electrical system PF,PR two mechanisms

These two mechanisms are to protect the system, in the system suddenly power off, to ensure that the system can normally shutdown, but it is possible because the power supply is not stable and suddenly power, and then a short time power again, it should be canceled shutdown, the default is after 2min shutdown, but after the power of 2min will cancel the shutdown

(6) Start Mingetty 6 terminals

In 6 terminals because of the previous definition of the Respawn keyword, so these 6 terminals into the undead, when you kill one of them after killing, the system will change a process number to restart it

(7) If you select Level 5, the/etc/x11/prefdm-nodaemon start graphical interface will start


At this point the system has been able to enter the boot state properly!




Linux start-up process detailed

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.