Linux start-up process (CentOS 6)

Source: Internet
Author: User
Tags crypt password protection

Objective

The Linux startup process plays a vital role in the actual production. Imagine what we should do if we had a problem with a service in the actual production and couldn't start it. If we understand the Linux detailed start-up process, know in which part of the problem, we can go to the corresponding link, eliminate the corresponding problems, so as to solve the actual production problems.

At the same time, we ask a question here, who knows the Windows startup process? What should we do if the startup process is out of the question? I'm afraid the answer is only to reboot the system ...

The boot process for Linux is completely transparent to the administrator, and the Linux startup process, like a perspective eye, can clearly understand everything about Linux. Know these, not only can solve the actual production problems, more able to make Linux, their own custom Linux, in short, Linux Dafa good ...

Write in front (most important)

Some of the information in this article refers to the following blog post.

    1. Linux booting Process Steps–rhel/centos 7

    2. Http://www.linuxidc.com/Linux/2014-03/97862.htm

    3. Http://www.cnblogs.com/zengkefu/p/5559058.html

Let's start with a picture.

You can right-click on the picture and choose to open it in the new tab, so you can view the larger image. This figure is the author according to the reference material re-system, reproduced please indicate the source.

650) this.width=650; "Src=" http://ot2trm1s2.bkt.clouddn.com/Linux/2017-08-30-linux-basic-command-12/Linux%E5%90% Af%e5%8a%a8%e8%bf%87%e7%a8%8b2.png "width=" "style=" Border:0px;vertical-align:middle; alt= "Linux%E5%90%AF%E5%" 8a%a8%e8%bf%87%e7%a8%8 "/>

This diagram describes the startup process of Linux in general and the corresponding annotations at different startup stages of Linux. In this paper, based on this diagram, the Linux startup process is described in detail in stages. At the same time because of their own limited capacity, the text describes the inevitable flaws, but also please note that I will promptly correct.

What's going on with the Linux boot process!!
  • Hardware boot Boot

  • Grub Boot Boot phase

  • Kernel boot phase

  • Init initialization phase

Hardware boot Boot

The hardware boot boot process is similar on Linux and Windows. Friends who are familiar with Windows systems can combine the Windows startup process to understand.

BIOS Boot

A computer-based person will know that the BIOS (basic input/output system), also known as the basic input and output system, is a set of programs that solidify onto the motherboard of a computer and are stored in ROM. Inside the computer to save the most basic input and output programs, when the computer starts first according to the information provided in the BIOS to find the corresponding hardware, and complete the most basic detection. If there is a problem in the process, the system will not start.
As a simple example, if the system is found in the BIOS stage, the memory bar does not load successfully, then the system can also start normally? This is true even for Windows systems at this point.

MBR Partition Boot

We take the MBR partition as an example to introduce the Linux boot process.
The first sector of the No. 0 track on the hard disk is called the MBR, which is the master boot record, which is the primary boot recording, and its size is 512 bytes, pre-boot information, partition table information.

After the computer completes the BIOS phase, the system will find the MBR of the hard disk specified in the BIOS, at which point the system-initiated control is transferred to the MBR stage. , the MBR consists of three parts, namely bootloader (Master boot program), DPT (hard disk partition table) and 55AA (hard disk valid flag). The detailed structure can be referenced.

Grub Boot Boot phase

The bootloader that are recorded in the MBR are read when the system boots into the MBR stage. The so-called bootloader refers to a small program that runs before the operating system kernel runs. Through this small program, we can initialize the hardware device, set up a map of the memory space, so as to bring the system's hardware and software environment to a suitable state, in order to finally call the operating system kernel ready to do everything. In Linux, it is grub.

Grub Boot in Linux is located in the/boot/grub/directory

Experiment if only keep grub.conf file, system can start normally?

650) this.width=650; "Src=" http://ot2trm1s2.bkt.clouddn.com/Linux/2017-08-30-linux-basic-command-12/%E4%BB%85%E4 %bf%9d%e7%95%99grub.conf%e6%93%8d%e4%bd%9c%e6%bc%94%e7%a4%ba.gif "alt=" only retain grub.conf "style=" border:0px; Vertical-align:middle; "/>

Just keep the grub.conf error that occurred during the startup process, as shown in the message

650) this.width=650; "Src=" http://ot2trm1s2.bkt.clouddn.com/Linux/2017-08-30-linux-basic-command-12/%E4%BB%85%E4 %bf%9d%e7%95%99grub.conf%e7%9a%84%e6%8f%90%e7%a4%ba%e9%94%99%e8%af%af.png "alt=" only retains grub.conf error message "style=" Border:0px;vertical-align:middle; "/>

Stage 1 Stages

When the system enters the MBR phase, the first 446 bytes of the disk are read directly into memory, that is, bootloader. Stage 1 refers to this paragraph.
Stage 1 is a very simple task, which is to read the 446 bytes of the hard disk into memory, parse it, and prepare for the next phase.

How do I fix the startup if the Stage1 phase is destroyed?

As we said earlier, Stage1 is mainly located in Bootloader, which is the first 446 bytes of the No. 0 track of the hard disk, so we can simulate this experiment by destroying 446 bytes. Let's take a look at the following motion diagram.

650) this.width=650; "Src=" http://ot2trm1s2.bkt.clouddn.com/Linux/2017-08-30-linux-basic-command-12/stage1%E5%90 %af%e5%8a%a8%e5%a4%b1%e8%b4%a5.gif "alt=" stage1 start Failed "style=" border:0px;vertical-align:middle; "/>

Can be seen, then the system will go directly into the rescue mode. The system could not find the hard drive boot code. So we went into rescue mode and carried out a series of rescue operations.

650) this.width=650; "Src=" http://ot2trm1s2.bkt.clouddn.com/Linux/2017-08-30-linux-basic-command-12/%E6%95%91% E6%8f%b4stage1.gif "alt=" Stage1 Rescue "style=" border:0px;vertical-align:middle; "/>

grub-installThe effect is to reinstall Grub and restore the files in the/boot/grub directory. The process we are implementing grub-install not only fixes the stage1 phase, but also fixes the stage1.5 and stage2 phases.

Stage 1.5 Stages

The Stage1 is located in the/boot basic disk partition and provides a system-aware extension to the file system where the kernel file is identified. Stage 1.5 is a bridge, stage 1 does not directly identify the file system, so you need stage 1.5来 to boot Stage 2 in a file system.

Stage 2 stages

Stage 2 is the core program of Grub, which allows the user to load the operating system, add parameters, and modify options in a menu, all of which are stage2 functions. For grub, the rest of the stage2 is done by Stage2, except that it does not start on its own. As the user sees at startup The Grub start Countdown screen, or immediately after the boot menu screen, is provided by Stage2. In the/boot/grub/directory can be seen by a stage2 file, that is, this file plays a vital role.
The grub.conf file is read during Stage 2, and the grub.conf file is a particularly important part of the Linux startup process.

grub.conf configuration file

The grub.conf file plays a big role in the startup process.

  • Ability to specify a default boot kernel or system

  • Provides an interactive interface

  • Provides password protection at startup

Below we will explain in detail grub.conf this configuration file. As shown, this is our custom grub.conf file.

650) this.width=650; "Src=" http://ot2trm1s2.bkt.clouddn.com/Linux/2017-08-30-linux-basic-command-12/ Grub.conf.png "alt=" grub.conf "style=" border:0px;vertical-align:middle; "/>

    • Default=0 which operating system is started by default

    • Timeout=5 The time required to select the operating system to start, If not selected within 5 seconds, start the default kernel or operating system

    • Splashimage The background of the boot menu, that is, select the interface to boot the kernel or operating system

    • passwd Enter the password for the startup item, meaning that after you see the system boot entry, only the password can be entered for command operations, such as entering a single user. There are several ways to configure passwords, which can be configured in clear text or in encrypted form. And there are two ways of encryption, grub-md5-crypt , grub-crypt . The configuration in the file is as follows.

passwd magedupasswd --md5  Encrypted password passwd --encrypted   encrypted password 
  • Hiddenmenu Hide Select kernel or operating system menu, only the Wait interface appears when you press ENTER. If this field is not available, the selection menu will appear each time the system starts.

  • The title defines the menu that needs to be started, (hd0,0) can be removed, but the order of kernel and INITRD cannot be reversed, or the system fails to start.

  • RHGB option can be removed, hide the animated interface (usually CentOS 6 or CentOS 7 logo), directly display the character interface, the character interface shows the various services related to launch information

  • Quiet default to hide the boot information of the kernel, if removed, start not only display the service startup information, but also display the boot information of the kernel.

If we hide the boot information of the kernel, where can we see the boot information of the kernel?

Cat/proc/cmdline will display the kernel information consistent with the grub.conf.

Kernel boot phase

Kernel, kernel, Kernel is the most important Linux system program, in fact, the Kernel file is very small, only the most basic module, and stored in compressed file form on the hard disk, when grub will Kernel read into memory, memory began to extract the kernel files. The kernel boot, you should first talk about the initrd this file,

INITRD (Initial RAM Disk), which was copied into memory at Stage2, this file was created when the system was installed, is a temporary root file system (ROOTFS). Because kernel in order to simplify, only retain the most basic module, therefore, kernel does not have a variety of hardware driver, also can not know rootfs device, therefore produced initrd this file, the file loaded the necessary driver module, when the kernel start, The driver module can be loaded from the INITRD file until the real rootfs is mounted, and the INITRD is removed from memory.

Kernel will mount the root filesystem as read-only, and when the root file system is mounted, the first process (user-space process) is loaded, the/sbin/init is executed, and control is then handed over to the INIT program.

Init initialization phase

The init process, as the name implies, is the process of initializing the operating system, when the operating system kernel is already loaded in memory. The script is actually executed according to the action set by/etc/inittab (which defines the system default RunLevel), the first executed script is/etc/rc.d/rc.sysinit, this is the actual OS initialization script related content and the configuration has a detailed description in the diagram, Not detailed here.

In summary, the system starts the process to carry on the general introduction, helpless, the time is tense, has a lot of places simply to take a stroke. In actual production, some details are also important, including the entire start-up process, if the fault should be how to repair, are worth detailed description of the knowledge points. There will be time to come back to update the supplement, in order to do better.



Personal blog Address:http://www.pojun.tech/ Welcome to visit

This article is from the "Xiaoshuaigege" blog, make sure to keep this source http://xiaoshuaigege.blog.51cto.com/6217242/1965108

Linux start-up process (CentOS 6)

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.