In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to understand the Linux boot process. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Overview
Linux is a free and open source UNIX-like operating system. The kernel of the operating system was first released by Linus Torvaz on October 5, 1991. After adding user space applications, it becomes the Linux operating system. Linux is the most famous example of the development of free software and open source software.
The following is a brief record of the whole process of the Linux system from boot to use as a memo!
LINUX startup process
First, through a diagram to simply understand the whole system startup process, the whole process can be divided into POST-- > BIOS-- > MBR (GRUB)-> Kernel-- > Init-- > Runlevel. The role of each process is described in detail below.
BIOS
BIOS (Basic Input/Output System), the basic input and output system, the system is stored on the ROM chip of the motherboard. When the computer is powered on, it will first read the system, and then there will be a power-on self-test process, this process is actually to check CPU and memory, the most basic components of the computer (controller, calculator and memory), but also check other hardware, if there is no exception, begin to load BIOS programs into memory. Let's not talk about the detailed BIOS function here. One of the main functions of BIOS is to store the boot order of the disk. BIOS will look up the MBR information of the first disk head according to the startup order, and load and execute the Bootloader program in MBR. If the first disk does not have MBR, it will continue to find the second disk (PS: the boot sequence can be set in the BIOS interface). Once the BootLoader program is detected and loaded into memory BIOS transfers control to the BootLoader program.
MBR
MBR (Master Boot Record), master boot record, MBR is stored in the head of the disk, the size is 512bytes, wherein, 446bytes is used to store BootLoader programs, 64bytes is used to store partition table information, and finally 2bytes is used to check the validity of MBR.
GRUB
GRUB (Grand Unified Bootloader), multi-system startup program, its execution process can be divided into three steps:
Stage1: this is actually MBR, its main job is to find and load the second Bootloader program (stage2), but when the system is not started, MBR can not find the file system, it can not find the location where stage2 is stored, so there is stage1_5
Stage1_5: this step is to identify the file system
The Stage2:GRUB program looks for Kernel information based on the / boot/grub/grub.conf file, and then starts loading the Kernel program. When the Kernel program is detected and loaded into memory, GRUB transfers control to the Kernel program.
PS: in fact, this step / boot has not been mounted yet. GRUB directly identifies the file system of the disk where grub resides, so it should actually be / grub/grub.conf file. The information of this configuration file is as follows:
Grub.conf:
# boot=/dev/sda
Default=0 # sets the number of title launched by default, starting with 0
Timeout=5 # wait for the timeout selected by the user
Background picture of splashimage= (hd0,0) / boot/grub/splash.xpm.gz # GRUB
Hiddenmenu # Hidden menu
Title CentOS (2.6.18-194.el5PAE) # Kernel title
Root (hd0,0) # device where the kernel file is located
Kernel / vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/ # kernel file path and parameters passed to the kernel
Initrd / initrd-2.6.18-194.el5PAE.img # ramdisk file path
Kernel
Kernel, kernel and Kernel are the main programs of Linux system. In fact, the files of Kernel are very small, only the most basic modules are retained, and are stored in the hard disk in the form of compressed files. When GRUB reads Kernel into memory, memory begins to decompress the kernel files. When talking about kernel startup, we should first talk about the file initrd.
Initrd (Initial RAM Disk), which is copied into memory at the stage2 step, is a temporary root file system (rootfs) that is generated when the system is installed. Because Kernel only retains the most basic modules in order to simplify, therefore, there are no drivers for all kinds of hardware on Kernel, so you can't recognize the device where rootfs is located, so the file initrd is generated, which loads the necessary driver modules. When Kernel starts, you can load the driver modules from the initrd file until the real rootfs is mounted, and then remove the initrd from memory.
Kernel mounts the root file system read-only, and when the root file system is mounted, it starts loading the first process (the process in user space), executes / sbin/init, and then transfers control to the init program.
Init
Init, initialization, as the name implies, this program is to initialize OS, which actually executes the script according to the action set by / etc/inittab (defines the default run level of the system). The first script to be executed is / etc/rc.d/rc.sysinit, which is the real OS initialization script. Briefly describe the tasks of this script (you can take a look at the actual script to see what has been done):
1. Activate udev and selinux
2. Set kernel parameters according to / etc/sysctl.conf file
3. Set the system clock
4. Load hard disk mapping
5. Enable swap partition
6. Set the host name
7. Detect the root file system and remount the root file system in read-write mode
8. Activate RAID and LVM devices
9. Enable disk quotas
10. Check and mount other file systems according to / etc/fstab
11. Clean up expired locks and PID files
After execution, according to the startup level of the configuration, execute the script under the corresponding directory, and finally execute the script / etc/rc.d/rc.local. At this point, the system boot is complete.
Runlevel
Runlevel, run level, different levels will start different services. Init will execute scripts in the corresponding directory according to the defined level. The startup levels of Linux can be divided into the following
0: shutdown mode
1: single user mode (enter directly as administrator)
2: multi-user mode (no network)
3: multi-user mode (command line)
4: reserved
5: multi-user mode (graphical interface)
6: restart
At different run levels, the script / etc/rc.d/rc executes scripts in different directories
Run level 0-/ etc/rc.d/rc0.d/
Run level 1-/ etc/rc.d/rc1.d/
Run level 2-/ etc/rc.d/rc2.d/
Run level 3-/ etc/rc.d/rc3.d/
Run level 4-/ etc/rc.d/rc4.d/
Run level 5-/ etc/rc.d/rc5.d/
Run level 6-/ etc/rc.d/rc6.d/
The scripts in these directories only start with K* and S*, the files starting with K are the services that need to be disabled for booting, and the files starting with S are the services that need to be enabled for booting.
The above is the editor for you to share how to understand the Linux boot process, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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: 255
*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.