Linux 黑话解释：Linux 中的 GRUB 是什么？
GRUB 黑话解释
![](/data/attachment/album/202204/03/111835u4rcmcf7qze8pawa.png)


如果你曾经使用过 Linux 桌面，你一定见过这个屏幕。这就是所谓的 GRUB 屏幕。是的，它的字母全部都是大写的。


![Remember this screen? This is GRUB](/data/attachment/album/202204/03/111939d8mdm43ll4n777nk.png)


在 “<ruby> Linux 黑话解释 <rt>  Linux Jargon Buster </rt></ruby>”系列的这一个章节中，我将告诉你 GRUB 是什么，以及它有什么用处。此外，我还会简要地介绍一下配置和定制的部分。


### GRUB 是什么？


[GRUB](https://www.gnu.org/software/grub/) 是一个用于加载和管理系统启动的完整程序。它是 Linux 发行版中最常见的<ruby> 引导程序 <rt>  bootloader </rt></ruby>。引导程序是计算机启动时运行的第一个软件。它加载 [操作系统的内核](https://itsfoss.com/what-is-linux/)，然后再由内核初始化操作系统的其他部分（包括 Shell、[显示管理器](/article-12773-1.html)、[桌面环境](/article-12579-1.html) 等等）。


### 引导程序和引导管理器


我不想现在就把你搞糊涂，但是我认为这个话题是不可避免的。<ruby> 引导程序 <rt>  boot loader </rt></ruby>和<ruby> 引导管理器 <rt>  boot manager </rt></ruby>之间有着一条模糊的界限。


你已经知道了引导程序是什么。它会首先启动，然后将内核加载到内存中并执行它。引导管理器则允许你在不同的操作系统之间进行选择（如果你的电脑上不止一个操作系统的话）。引导管理器并不会直接加载系统。


随着 Linux 内核 3.3 版本的推出，[Linux 内核包括了一个内置的 EFI 引导程序](https://www.rodsbooks.com/efi-bootloaders/efistub.html)。事实上，任何一个[支持 EFI 的系统都包括一个 EFI 引导程序](https://jdebp.eu/FGA/efi-boot-process.html)。在支持 EFI 的系统中，固件会读取 <ruby> EFI 系统分区 <rt>  EFI System Partition </rt></ruby>（ESP）中的 EFI 文件，从而获得启动信息。


这里插入一张图片，图中显示了带有 ESP 分区的分区表：


![](/data/attachment/album/202204/03/111939pzyy0coqn7a9c2yw.png)


GRUB 既是一个引导程序，也是一个引导管理器。一会儿我再来谈 GRUB。让我们先看看其他类似 GRUB 的程序。



> 
> 小知识：GRUB 是 **GR**and **U**nified **B**ootloader（大一统引导程序） 的首字母缩写。
> 
> 
> 


### GRUB 屏幕上的那些行是什么意思？


你会在 GRUB 屏幕上看到几行字。这些行对于不同的设置、不同的发行版会有所不同。


通常情况下，第一行是你的 Linux 发行版。如果你看到类似高级选项的东西，你可以进入其中，找到一些以 “linux-generic-x-y-z” 等开头的行。


当你的 Linux 发行版更新内核版本时，它至少会保留一个旧版本。你可以选择启动到旧的 Linux 内核，以防你的系统遇到新更新的 Linux 内核的任何问题。


在基于 Ubuntu 的发行版中，你也可以看到一个恢复选项。


![](/data/attachment/album/202204/03/111940ymuwn888m80or084.jpg)


*在高级选项下，通常有一个旧的内核版本和恢复选项*


在最后，你可能会看到一个条目，如系统设置或 UEFI 设置，以访问系统的 BIOS 设置。


### 还有哪些类似 GRUB 的引导管理器？


GRUB 是 Linux 中最流行的引导管理器。但它并不是唯一的一个。有一个高度可定制的引导管理器，名字叫做 [rEFInd 引导管理器](https://www.rodsbooks.com/refind/)，它同样受到了一些 Linux 用户的喜爱。


![定制化的 rEFInd 引导管理器屏幕 | 图片来源：kofler.info/pop_os](/data/attachment/album/202204/03/111940cxvqmqma6t3n2yox.png)


还有一个基于文本的引导管理器，名字叫做 [systemd-boot](https://wiki.gentoo.org/wiki/Systemd-boot)。你可以猜到这是专为基于 systemd 的 Linux 发行版准备的。有一些发行版正在使用 systemd-boot，比如 Pop OS。


![Pop OS 中的 systemd-boot | 图片来源：kofler.info/pop_os](/data/attachment/album/202204/03/111940iozaaaeqqdzay3v3.png)


### 访问或编辑 GRUB


通常你看到的 GRUB 屏幕是它的菜单界面。如果你安装了一个以上的操作系统，它会允许你在其中选择一个来启动。如果你的 Linux 发行版安装了不止一个内核，你也可以选择加载不同的内核。


根据不同的 Linux 发行版的配置，你的 GRUB 菜单上可能会有一些其他选项。


你可以在 GRUB 菜单界面按 `e` 键来编辑菜单项。这样你就可以在内核加载前修改它的参数。例如，在某些情况下，[禁用内核提供的图形驱动可以帮助你解决 Linux 系统在启动时卡住的问题](https://itsfoss.com/fix-ubuntu-freezing/)。


![](/data/attachment/album/202204/03/111941vwwiszmd2wyyvulb.jpg)


你也可以在 GRUB 菜单界面上按 `c` 键来进入 GRUB 的命令行菜单。


### GRUB 配置文件


你在菜单界面里对 GRUB 所做的任何改变都是暂时的。如果你想对 GRUB 做一些永久性的改变，比如改变默认的超时时间，你可以在 Linux 系统启动后修改 GRUB 配置文件。


默认的 GRUB 配置文件是 `/etc/default/grub`。还有一个 `/etc/default/grub.d` 目录，里面也存放一些配置。你可以直接编辑 `/etc/default/grub` 文件，但是我还是建议通过在这个目录中添加配置文件（`.cfg` 文件）进行额外的修改。


![默认的 GRUB 配置文件](/data/attachment/album/202204/03/111941mgg5hj88bs4hz5sq.png)


你必须 [更新 GRUB 才能使这些修改生效](https://itsfoss.com/update-grub/)。


### 使用 GRUB 定制器来定制 GRUB


如果你不太习惯 [在终端里使用文本编辑器编辑文件](https://itsfoss.com/command-line-text-editors-linux/)，你可以 [使用一个叫做 GRUB 定制器的图形工具](https://itsfoss.com/grub-customizer-ubuntu/)。


它允许你改变启动顺序、默认超时时间等等。你还可以用它来把 GRUB 的背景设置成一张自定义的墙纸。


![](/data/attachment/album/202204/03/111941axsxxmcdc7l2sxm7.jpg)


GRUB 定制器可以在 Ubuntu 20.04 中从 Universe 仓库安装，在 Ubuntu 18.04 中 [通过 PPA 安装](https://itsfoss.com/ppa-guide/)。它可以 [通过 AUR](https://itsfoss.com/aur-arch-linux/) 在基于 Arch Linux 的发行版中使用。


### 总结


至此，本文几乎涉及到了所有与 GRUB 相关的简单内容。至于 EFI、引导加载和 GRUB 本身，它们都是详细而复杂的话题，因此不在本文的讨论范围之内。这篇文章旨在给你一个关于 GRUB 引导程序的总体概述。


或许我以后会写一篇关于 GRUB 的详细指南，解释它底层的一些细节。目前，如果你想了解更多关于 GRUB 的信息，你可以在你的 Linux 终端里使用 `info grub` 命令访问到 GRUB 文档。


![你可以在终端中访问 GRUB 手册](/data/attachment/album/202204/03/111942c2pwkpaduw2uar79.png)


我希望你现在对什么是 GRUB 有了一点点的了解。这里有一个 GIF 动图供你一乐。


![什么是 GRUB? UEFI 再也伤害不到我了 :)](/data/attachment/album/202204/03/111945ly7nnt5atbaliyy5.gif)


或许我没有回答你关于 GRUB 的所有疑问，但请随时在评论区告诉我。我可能会根据你的问题或建议来更新这篇文章。




---


via: <https://itsfoss.com/what-is-grub/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[lkxed](https://github.com/lkxed) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

If you ever used a desktop Linux system, you must have seen this screen. This is called the GRUB screen. Yes, it is written in all capital letters.

![Grub Screen Linux](https://itsfoss.com/content/images/wordpress/2020/11/grub-screen-linux.png)

In this chapter of the Linux Jargon Buster series, I’ll tell you what Grub is and what is it used for. I’ll also briefly touch upon the configuration and customization part.

## What is GRUB?

[GRUB](https://www.gnu.org/software/grub/) is a complete program for loading and managing the boot process. It is the most common bootloader for Linux distributions. A bootloader is the first software that runs when a computer starts. It loads the [kernel of the operating system](https://itsfoss.com/what-is-linux/) and then the kernel initializes the rest of the operating system: shell, [display manager](https://itsfoss.com/display-manager/), [desktop environment](https://itsfoss.com/what-is-desktop-environment/), etc.

### Boot loader vs boot manager

I didn’t want to confuse you at this stage but this topic needs to be introduced before going on. There is a blurry line between a bootloader and a boot manager.

You already know that the bootloader starts first and then loads the kernel into memory and executes it. A boot manager program allows you to choose between operating systems, if there is more than one on your system. A boot manager doesn’t load the OS directly,

With Linux kernel version 3.3, the [Linux kernel includes a built-in EFI bootloader](https://www.rodsbooks.com/efi-bootloaders/efistub.html). In fact, any operating system that is capable of working the [EFI system includes an EFI bootloader](https://jdebp.eu/FGA/efi-boot-process.html). In EFI capable systems, the firmware reads the EFI system partition (ESP) to locate the EFI files for boot information.

![Disk Partition Gparted](https://itsfoss.com/content/images/wordpress/2020/11/disk-partition-gparted.png)

GRUB is both a bootloader and a boot manager. I’ll come back to GRUB in a moment. First, let’s see other GRUB-like programs.

**Trivia**: GRUB is acronym for

**GR**and

**U**nified

**B**ootloader.

## What are those lines in Grub screen mean?

You’ll see a few lines on the Grub screen. These lines will be different for different setups, different distributions.

Usually, the first line is your Linux distribution. If you see something like Advanced option, you can enter into it and find some lines starting with linux-generic-x-y-z etc.

When your Linux distribution updates the kernel version, it keeps at least one older version. You can choose to boot into the older Linux kernels in case your system encounters any issue with the newly updated Linux kernel.

You may also see a recovery option in Ubuntu based distribution.

![Boot into recovery mode](https://itsfoss.com/content/images/wordpress/2012/07/boot-into-recovery-mode-ubuntu-1.jpg)

At the last, you may see an entry like System setup or UEFI Settings to access the BIOS settings of your system.

## What are some other boot managing programs similar to GRUB?

GRUB is the most popular boot manager for Linux. But it is not the only one. There is the highly customizable [rEFInd boot manager](https://www.rodsbooks.com/refind/) that some Linux users love.

![Refind Boot Manager](https://itsfoss.com/content/images/wordpress/2020/11/refind-boot-manager-800x602.png)

[Image Credit](https://teejeetech.in/2020/09/05/linux-multi-boot-with-refind/)

There is also [systemd-boot](https://wiki.gentoo.org/wiki/Systemd-boot) text-based boot manager. You can guess that this is exclusively for systemd-based Linux distributions. Some distributions such as Pop OS, use the systemd-boot.

![systemd-Boot in Pop OS](https://itsfoss.com/content/images/wordpress/2020/11/systemd-boot.png)

[Image Credit](https://kofler.info/pop_os/)

## Accessing or editing GRUB

The usual GRUB screen you see is its menu interface. It allows you to choose which operating systems to boot, if there is more than one on your machine. You can also choose to load a different kernel if your Linux distribution has more than one installed.

Depending upon the configuration set by the Linux distribution, you may have some other entries on the GRUB menu.

You can edit a GRUB menu entry by pressing the “e” key. This way, you can change the kernel parameters before loading it. For example, in some cases, [disabling the graphics driver from the kernel helps you with Linux system stuck at boot](https://itsfoss.com/fix-ubuntu-freezing/).

![Editing grub to fix frozen boot issue with Ubuntu Linux](https://itsfoss.com/content/images/wordpress/2019/04/editing-grub-to-fix-nvidia-issue-800x343.jpg)

You can also enter the command line menu of GRUB using the “c” key at the GRUB menu interface.

### GRUB configuration file

Any changes you make to GRUB from the menu interface is temporary. If you want to make some permanent changes to GRUB, such as changing the default timeout, you can change the configuration file after you boot into your Linux system.

The default GRUB configuration file is located at /etc/default/grub. There is also a /etc/default/grub.d directory. You may edit the /etc/default/grub file directly, however it is advised to make additional changes by adding config files (.cfg files) in this directory.

![Default Grub Config File](https://itsfoss.com/content/images/wordpress/2020/11/default-grub-config-file.png)

You must [update GRUB for the changes to take into effect](https://itsfoss.com/update-grub/). In fact, whenever you install an additional Linux on your system, it will try to overwrite the existing GRUB config with its own.

### GRUB customizer for easily customizing GRUB

If you think [editing a file with a text editor in the terminal](https://itsfoss.com/command-line-text-editors-linux/) is not something you feel comfortable with, you can [use a graphical tool called GRUB Customizer](https://itsfoss.com/grub-customizer-ubuntu/).

It allows you to change the boot order, default timeout etc. You can also use it to change the background of GRUB with a custom wallpaper.

![Make Windows default option in Grub in dual boot mode](https://itsfoss.com/content/images/wordpress/2013/05/make-windows-default-grub-2.jpeg)

GRUB Customizer can be installed in Ubuntu 20.04 from Universe repository and via [PPA in Ubuntu](https://itsfoss.com/ppa-guide/) 18.04. It is available via [AUR in Arch Linux based distributions](https://itsfoss.com/aur-arch-linux/).

## Conclusion

I have touched everything on the surface. EFI, boot loading and GRUB itself is detailed and complicated topic and not in the scope of this article. This article intended to give you a high-level overview of the GRUB boot program.

Perhaps I’ll write a detailed guide on GRUB explaining the low-level details. For now, if you want to learn more about GRUB, you can access the GRUB documentation in your Linux terminal using the `info grub`

command.

![Grub Manual Linux Terminal](https://itsfoss.com/content/images/wordpress/2020/11/grub-manual-Linux-terminal-800x462.png)

I hope you have a tad bit better understanding of what GRUB is now. Here’s a GIF to humor you.

![What Is Grub](https://itsfoss.com/content/images/wordpress/2020/11/what_is_GRUB.gif)

I may not have answered all questions you have about GRUB. Please feel free to let me know in the comment section. I may update the article with your questions or suggestions.