In a Linux system, we may have multiple kernels installed. Usually, it is the latest kernel configured to be the default one the system boot loader will use during automatic boot if there is no manual kernel choosing. In many cases, such as there is no driver ready yet for some devices in newer kernels, we may choose to use an older version of kernel installed to the system. In this post, we will go through the steps to make the system boot loader grub (version 2) to boot the older kernel installed to the system on Ubuntu 20.04.
在Linux系统中,我们可能安装了多个内核。 通常,它是最新的内核,如果没有手动选择内核,它将被配置为系统引导加载程序在自动引导期间将使用的默认内核。 在许多情况下,例如尚未为较新内核中的某些设备准备好驱动程序,我们可能会选择使用安装到系统中的较旧版本的内核。 在本文中,我们将逐步完成使系统引导加载程序grub(版本2)引导在Ubuntu 20.04上引导安装到系统的旧内核的步骤。
查找已安装内核的列表和grub菜单项 (Find the list of kernels installed and the grub menu entries)
We need to first find out the grub menu entries. The tool grub-mkconfig
prints the grub configuration file content it generates to STDOUT. We can grep
relevant content from its STDOUT as follows.
我们需要首先找出grub菜单项。 工具grub-mkconfig
将生成的grub配置文件内容打印到STDOUT。 我们可以grep
从它的标准输出如下相关内容。
$ sudo grub-mkconfig | grep -E 'submenu |menuentry '
You will see output as follows.
您将看到如下输出。
...
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-84d2ae45-10d0-4cd9-a958-85e582df668b' {
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-84d2ae45-10d0-4cd9-a958-85e582df668b' {
menuentry 'Ubuntu, with Linux 5.4.0-33-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-33-generic-advanced-84d2ae45-10d0-4cd9-a958-85e582df668b' {
menuentry 'Ubuntu, with Linux 5.4.0-33-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-33-generic-recovery-84d2ae45-10d0-4cd9-a958-85e582df668b' {
Found linuximage: /boot/vmlinuz-4.15.0-101-generic
Found initrd image: /boot/initrd.img-4.15.0-101-generic
menuentry 'Ubuntu, with Linux 4.15.0-101-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-101-generic-advanced-84d2ae45-10d0-4cd9-a958-85e582df668b' {
menuentry 'Ubuntu, with Linux 4.15.0-101-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-101-generic-recovery-84d2ae45-10d0-4cd9-a958-85e582df668b' {
...
Here, we use the entry "Ubuntu, with Linux 4.15.0-101-generic" under menu "Advanced options for Ubuntu" as an example.
在这里,我们以“ Ubuntu的高级选项”菜单下的“ Ubuntu,Linux 4.15.0-101-generic”条目为例。
During booting time, grub reads the grub configuration file. grub-mkconfig
that can generate the grub configuration file. We can update the grub-mkconfig
‘s configuration file to change the grub configuration file.
在引导期间,grub会读取grub配置文件。 可以生成grub配置文件的grub-mkconfig
。 我们可以更新grub-mkconfig
的配置文件以更改grub配置文件。
设置grub-mkconfig配置文件 (Set grub-mkconfig configuration file)
Grub has a configuration file under /etc/default/grub
. The configuration file has a variable GRUB_DEFAULT
specifying the default choice in grub.
Grub在/etc/default/grub
下有一个配置文件。 配置文件具有变量GRUB_DEFAULT
用于指定grub中的默认选项。
Here, what we need to figure out is the format to select the 2 levels of the menu entries. In the configuration parameter, these 2 levels of entries should be all specified with a character >
to separate them.
在这里,我们需要弄清楚选择菜单项的2个级别的格式。 在配置参数中,这两个级别的条目都应使用字符>
指定,以将它们分开。
So for our purpose, change the config file by changing the line for setting GRUB_DEFAULT
to
因此,出于我们的目的,请更改配置文件,方法是将GRUB_DEFAULT
设置为
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 4.15.0-101-generic"
重新生成grub配置文件 (Regenerate grub configuration file)
We now can generate the configuration file. In Debian Linux distros and derivatives, there is a tool update-grub
to do this by calling grub-mkconfig
.
现在,我们可以生成配置文件。 在Debian Linux发行版和衍生版中,有一个工具update-grub
通过调用grub-mkconfig
。
$ sudo update-grub
After it finishes successfully, the default entry in the Grub2 configuration file will be the one we set when we boot the Linux system next time.
成功完成之后, Grub2配置文件中的默认条目将是我们下次引导Linux系统时设置的默认条目。
翻译自: https://www.systutorials.com/how-to-make-grub2-boot-to-older-kernel-version-in-ubuntu-20-04/