In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
This article is to share with you the Centos7 system startup process, I believe that most people have not yet learned this skill, in order to let you learn, to give you a summary of the following content, say no more, let's read on.
Familiar with the system startup process is very helpful for us to learn the Linux system, although the basic, but can help us to better understand the working mechanism of the Linux system. The following will take the CentOS release as an example to introduce the startup process of the Linux system, because the initialization program init used in CentOS 5, CentOS 6 and CentOS 7 is different. Although CentOS 6 and CentOS 7 are backward compatible, there are still some differences in the working mechanism, so the following mainly introduces the CentOS 5 6 system startup process.
The overall order of the startup process for CentOS is as follows (take CentOS 6 as an example):
POST-- > Boot Sequence-- > bootloader (MBR)-- > Kernel-- > load rootfs-- > switchroot-- > / sbin/init-- > (configuration file: / etc/inittab, / etc/init/*.conf)-- > set the default run level according to the init configuration file-- > run the system initialization script / etc/rc.d/rc.sysinit Complete system initialization-> turn on or off the corresponding service under the corresponding run level selected by the user-> start the terminal and print the login prompt.
Note: the red part represents the system startup process in kernel space, and the purple part represents the system startup process in user space.
Next, we will explain in detail one by one:
Step 1: POST power-on self-test
The main function is to detect whether each peripheral hardware device exists and can run normally. This self-test function is realized by the BIOS (Basic Input/Output System) program solidified on the ROM (mainly represented as CMOS) chip on the motherboard; for example, BIOS will test whether the CPU, Memory and Igamot devices can function properly, and if it is a personal computer, it may also check the monitor. As soon as it is powered on, CPU will automatically load the BIOS program on the ROM chip, which is realized in this way. After the detection is completed, the hardware device is initialized.
Step 2: Boot Sequence (select boot device to load MBR)
The main function is to select the hardware device to start, and then you can read the bootloader in the MBR on this device. This step is implemented as follows: according to the boot sequence set in BIOS, BIOS scans each boot device in turn, and then the first device that is scanned to have a boot program (bootloader) is treated as the boot device to boot.
Step 3: load bootloader (MBR)
There are many steps to implement this step. The previous BIOS reads and executes the bootloader in the MBR of the boot device, and the function of bootloader is to provide a menu for the user to select the system or different kernel version to boot, and then load the kernel version selected by the user into a specific space in the RAM, then decompress and expand it in RAM, and then hand over the control of the system to the kernel.
Grub is a kind of bootloader, as far as grub is concerned, in order to break the restriction that only 446Bytes is used to store bootloader in MBR, so the implementation of this step is like this: grub is divided into three stages to load the kernel, which are: stage1, stage1.5 and stage2. Where:
Stage1: a pre-446Bytes stored in MBR to load the stage1.5 phase in order to identify and drive the file system of the partition where stage2 (or / boot) resides
Stage1.5: the sector stored behind the MBR, which loads the file system driver of the partition where the stage2 resides, so that the bootloader in the stage1 can recognize the file system of the partition where the stage2 resides.
Stage2: stored on top of the disk partition, specifically under the / boot/grub directory, mainly used to load kernel files (vmlinuz-VERSION-RELEASE) and ramdisk as a temporary root file system (initrd-VERSION-RELEASE.img or initramfs-VERSION-RELEASE.img).
Summary: if you want to start a hard disk device, first of all, our hardware platform motherboard BIOS must be able to identify the hard disk, and then BIOS can load the bootloader in the hard disk, and bootloader itself can directly identify the hard disk device on the current host. However, being able to identify a hard disk device does not mean that it can identify the file system in the hard disk device, because the file system is an additional layer of software-organized file structure, so to dock a file system, there must be a corresponding driver that can identify and understand this file system, which is called a file system driver. Stage1.5 provides the file system driver to grub so that stage1 can access stage2 and the partition where the kernel is located (/ boot).
Note: the file paths of kernel and initramfs both start with the "root" of grub and are stored on the partition where stage2 is located.
It should be noted that stage2, kernel, and ramdisk files are usually placed on a basic disk partition, because grub cannot drive complex logic devices such as lvm, advanced soft raid, etc., unless a complex driver interface is provided, otherwise, if stage2 and kernel files are stored on complex logic devices such as lvm, they will not be recognized by stage1, let alone loaded!
Step 4: initialize Kernel itself
After gaining control of the system, Kerenl first initializes itself, and the main functions of initialization are:
(1) detect all recognizable hardware devices
Bootloader handing over control of the system to the kernel is like the post-dynasty overthrowing the previous dynasty. After the ruler (kernel) is in power, first check what is left by the previous dynasty, such as what territory, manpower, financial resources, troops are available, and so on.
(2) load the hardware driver, that is, load the driver of the device where the real root file system is located (possibly with the help of ramdisk)
This is like the ruler (core), after knowing the human and financial resources at the bottom, begins to include the manpower that can be "for my use" under his command, at his own command, rather than killing him.
(3) Mount the root file system read-only
If there is a temporary file system with the help of ramdisk (virtual root), a root switch is performed after this step; otherwise, no root switch is performed.
(4) run the first application in user space: / sbin/init.
At this point, the startup process of the kernel space is over, and then the user space completes the subsequent system startup process.
Note:
Ramdisk and the kernel are loaded into memory together by bootloader. Ramdisk is used to implement system initialization, memory-based disk devices, that is, after loading into memory (a certain section of space), the memory is used as a disk and provided to the kernel as a temporary root file system in memory to help the kernel mount the real root file system. The reason why it can help the kernel mount the root file system is that under the / lib/modules directory of the temporary file system ramdisk, there is a driver for the device where the root file system resides; in addition, the temporary file system also follows FHS, for example, it has these fixed directory structures: / bin, / sbin, / lib, / lib64, / etc, / mnt, / media,...
Because a feature of the Linux kernel is to accelerate access to files on disk by using buffering / caching, and ramdisk is loaded into memory and simulated as a disk for use, so Linux will use another layer of buffering / cache for the "disk" in memory, but our ramdisk is already memory, it is only used as a hard disk, which results in double buffering / caching. And it will not increase the speed, and even affect the access performance. The problem mentioned above occurs when the CentOS 5 series and previous versions of the ramdisk file are initrd-VERSION-RELEASE.img; in order to solve the problem, the CentOS 6x7 series version changed it to initramfs-VERSION-RELEASE.img, using the file system to avoid double buffering / caching, which can be said to be a speed-up mechanism.
It should be noted that in order to adapt to different hardware interfaces, the system publisher assembles the drivers of different hardware interfaces, for example, after the user installs the system with the CD for the first time, it will dynamically detect the hardware devices on the current host and call the corresponding device drivers to make ramdisk files. Therefore, the ramdisk file is not necessary, if only to install Linux on a specific hardware platform, you can directly compile the corresponding driver into the kernel, without the need to use the ramdisk file.
Step 5: init manages the user space service process
Init can be understood as an emissary sent by the kernel to manage user space, just as angels visit the world on behalf of God. The initialization program init performs a series of actions based on its configuration file. Although the init configuration files for CentOS 5, CentOS 6, and CentOS 7 are different, the overall startup process remains the same.
The process of this step is: / sbin/init-- > set the default run level according to the init configuration file-- > run the system initialization script / etc/rc.d/rc.sysinit, complete the system initialization-- > shut down or start the service corresponding to the default run level selected by the user-- > start the terminal and print the login prompt.
(1) set the default run level according to the init configuration file
For CentOS 5, the initializer init is SysV init and its configuration file is: / etc/inittab
For CentOS 6, the initializer init is upstart, and its configuration file is: / etc/inittab, / etc/init/*.conf, that is, upstart splits the configuration file into multiple, upstart-style configuration files that end with conf in the / etc/init/ directory, while / etc/inittab is only used to set the default run level
For CentOS 7, the initializer init is systemd and its configuration file is: / usr/lib/system/systemd/*, / etc/systemd/system/*
After reading the above, have you mastered the method of starting the Centos7 system? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.