Home  >  Article  >  Operation and Maintenance  >  What is linux mbr grub

What is linux mbr grub

藏色散人
藏色散人Original
2023-03-14 09:48:001453browse

linux mbr grub is the process of starting the entire Linux system. The full English name of mbr is "Master Boot Record", which means the master boot record. mbr is stored in the head of the disk and has a size of 512 bytes; the full English name of grub is It is "Grand Unified Bootloader", which means multi-system bootloader.

What is linux mbr grub

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

What is linux mbr grub?

Detailed explanation of the Linux boot process: BIOS->MBR->GRUB, etc...

Overview

Linux is a A free and open source UNIX-like operating system. The operating system's kernel was first released by Linus Torvalds on October 5, 1991. After adding user space applications, it becomes the Linux operating system. Linux is the most famous example of free software and open source software development.

Let’s briefly record the entire process of the Linux system from booting to being usable, as a reminder!

LINUX startup process

Let’s first briefly understand the entire system startup process through a picture. The entire process can basically be divided into POST-->BIOS-- >MBR(GRUB)-->Kernel-->Init-->Runlevel. The role of each process is explained in detail below.

What is linux mbr grub

BIOS

BIOS (Basic Input/Output System), the basic input and output system, this system is stored in the ROM chip of the motherboard When the computer is turned on, it will first read the system, and then there will be a power-on self-test process. This process is actually to check the CPU and memory, the most basic components of the computer (controller, arithmetic unit and memory). It will also check other hardware, and if there are no abnormalities, it will start loading the BIOS program into the memory. The detailed BIOS functions will not be discussed here. One of the main functions of the BIOS is to store the startup sequence of the disk. The BIOS will search for the MBR information of the first disk header according to the startup sequence, and load and execute the Bootloader program in the MBR. , if the MBR does not exist on the first disk, it will continue to search for the second disk (PS: the startup sequence can be set in the BIOS interface). Once the BootLoader program is detected and loaded into the memory, the BIOS will transfer control to BootLoader program.

MBR

MBR (Master Boot Record), master boot record, MBR is stored at the head of the disk, with a size of 512 bytes, of which 446 bytes are used to store the BootLoader program , 64 bytes are used to store partition table information, and the last 2 bytes are used for MBR validity check.

What is linux mbr grub

GRUB

GRUB (Grand Unified Bootloader), a multi-system startup program, its execution process can be divided into three steps:

Stage1: This is actually the MBR. Its main job is to find and load the second Bootloader program (stage2). However, when the system is not started, the MBR cannot find the file system at all, so it cannot be found. The location where stage2 is stored, therefore, there is stage1_5

Stage1_5: This step is to identify the file system

Stage2: The GRUB program will search for the Kernel based on the /boot/grub/grub.conf file information, and then starts loading the Kernel program. When the Kernel program is detected and loaded into the memory, GRUB hands over control to the Kernel program.

PS: In fact, /boot has not been mounted in this step. GRUB directly recognizes the file system of the disk where grub is located, so it should actually be the /grub/grub.conf file. The information of this configuration file is as follows:

grub.conf:

#boot=/dev/sda
default=0 #设定默认启动的title的编号,从0开始
timeout=5 #等待用户选择的超时时间
splashimage=(hd0,0)/boot/grub/splash.xpm.gz #GRUB的背景图片
hiddenmenu #隐藏菜单
title CentOS (2.6.18-194.el5PAE) #内核标题
root (hd0,0) #内核文件所在的设备
kernel /vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/ #内核文件路径以及传递给内核的参数
initrd /initrd-2.6.18-194.el5PAE.img #ramdisk文件路径

Kernel

Kernel, kernel, Kernel is the most important program in the Linux system. In fact, Kernel files are very Small, only the most basic modules are retained and stored on the hard disk in the form of compressed files. When GRUB reads the Kernel into the memory, the memory begins to decompress the kernel file. When talking about kernel startup, we should first talk about the initrd file,

initrd (Initial RAM Disk), which is copied to the memory in the stage2 step. This file is generated when installing the system and is a temporary The root file system (rootfs). Because Kernel only retains the most basic modules in order to simplify it, there are no drivers for various hardware on the Kernel, so it cannot recognize the device where rootfs is located. Therefore, the initrd file is generated, which loads the necessary driver modules. , when the Kernel starts, the driver module can be loaded from the initrd file until the real rootfs is mounted, and then the initrd is removed from the memory.

Kernel will mount the root file system in read-only mode. When the root file system is mounted, it will start to load the first process (user space process), execute /sbin/init, and then control The power is transferred to the init program.

Init

init,初始化,顾名思义,该程序就是进行OS初始化操作,实际上是根据/etc/inittab(定义了系统默认运行级别)设定的动作进行脚本的执行,第一个被执行的脚本为/etc/rc.d/rc.sysinit,这个是真正的OS初始化脚本,简单讲下这个脚本的任务(可以去看看实际脚本,看看都做了什么):

  • 激活udev和selinux;

  • 根据/etc/sysctl.conf文件,来设定内核参数;

  • 设定系统时钟;

  • 装载硬盘映射;

  • 启用交换分区;

  • 设置主机名;

  • 根文件系统检测,并以读写方式重新挂载根文件系统;

  • 激活RAID和LVM设备;

  • 启用磁盘配额;

  • 根据/etc/fstab,检查并挂载其他文件系统;

  • 清理过期的锁和PID文件

执行完后,根据配置的启动级别,执行对应目录底下的脚本,最后执行/etc/rc.d/rc.local这个脚本,至此,系统启动完成。

Runlevel

runlevel,运行级别,不同的级别会启动的服务不一样,init会根据定义的级别去执行相应目录下的脚本,Linux的启动级别分为以下几种

0:关机模式

1:单一用户模式(直接以管理员身份进入)

2:多用户模式(无网络)

3:多用户模式(命令行)

4:保留

5:多用户模式(图形界面)

6:重启

在不同的运行级别下,/etc/rc.d/rc这个脚本会分别执行不同目录下的脚本

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/

这些目录下的脚本只有K*和S*开头的文件,K开头的文件为开机需要执行关闭的服务,S开头的文件为开机需要执行开启的服务。

相关推荐:《Linux视频教程

The above is the detailed content of What is linux mbr grub. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn