如何在Ubuntu 20.04中将Grub2引导到较早的内核版本

本文介绍了如何在Ubuntu 20.04上引导旧内核版本。当新内核不支持某些设备时,这种方法很有用。步骤包括查找已安装内核和GRUB菜单项,设置GRUB配置文件以选择旧内核,并重新生成GRUB配置文件。
摘要由CSDN通过智能技术生成

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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要修复Ubuntu 20.04GRUB引导,可以按照以下步骤进行操作: 1. 首先,使用Ubuntu 20.04安装盘或Live CD启动计算机。 2. 进入Live CD的桌面后,打开终端。 3. 在终端输入以下命令,以查看计算机上所有的硬盘和分区: sudo fdisk -l 4. 找到包含Ubuntu 20.04安装的分区,并记下其设备名称,例如/dev/sda1。 5. 接下来,挂载Ubuntu 20.04的根分区。假设根分区的设备名称为/dev/sda1,那么可以使用以下命令挂载: sudo mount /dev/sda1 /mnt 6. 接着,挂载其他必要的分区,例如/boot分区和/efi分区(如果有的话)。假设/boot分区的设备名称为/dev/sda2,/efi分区的设备名称为/dev/sda3,那么可以使用以下命令挂载: sudo mount /dev/sda2 /mnt/boot sudo mount /dev/sda3 /mnt/boot/efi 7. 然后,切换根目录到/mnt: sudo chroot /mnt 8. 接下来,重新安装GRUB引导程序: sudo grub-install /dev/sda 9. 最后,更新GRUB配置文件: sudo update-grub 10. 完成后,退出chroot环境并重启计算机: exit sudo reboot 以上就是修复Ubuntu 20.04GRUB引导的步骤。 ### 回答2: 在修复Ubuntu 20.04GRUB引导前,首先需要了解什么是GRUB引导GRUB(GRand Unified Bootloader)是一款用于GNU / Linux引导加载程序,它可以使您选择不同的操作系统或内核以加载。 现在我们来看看如何修复Ubuntu 20.04GRUB引导: 步骤1:使用Live CD或USB启动Ubuntu 首先,您需要使用Live CD或USB启动Ubuntu,选择“试用Ubuntu”选项,进入Ubuntu桌面。 步骤2:安装Boot Repair软件 打开终端并执行以下命令: sudo add-apt-repository ppa:yannubuntu/boot-repair sudo apt-get update sudo apt-get install boot-repair 安装完成后,启动Boot Repair软件。 步骤3:修复GRUB引导 在Boot Repair软件,点击“推荐修复”按钮,然后等待软件自动修复GRUB引导。该过程可能需要一些时间,具体时间取决于您的系统和硬件。 修复完成后,Boot Repair软件会显示一个URL链接,您可以使用该链接查看修复过程的详细信息。现在,您可以将Live CD或USB从计算机取出,并重启计算机。 步骤4:验证GRUB引导是否已修复 重启计算机后,您应该能够看到GRUB引导屏幕,该屏幕将列出可以启动的操作系统和内核。如果您可以看到GRUB引导屏幕,并成功启动Ubuntu,则说明您已成功修复GRUB引导。 总结 在上述步骤,我们使用Boot Repair软件修复了Ubuntu 20.04GRUB引导。它是一个简单的工具,能够在许多情况下成功修复GRUB引导。但是,如果您的情况比较复杂,您可能需要手动修复GRUB引导,这需要更高级的技术知识。无论哪种方法,重要的是备份您的数据并小心操作,以避免不必要的数据丢失。 ### 回答3: Ubuntu 20.04是一种流行的Linux操作系统,它使用Grub作为引导程序。但有时,该Grub引导程序可能出现问题,导致无法正常启动计算机。 引导修复通常很容易,只需要使用可引导的USB闪存驱动器,我们可以步入Linux安装程序。 发现Ubuntu操作系统,进入Ubuntu命令行和使用修复工具来修复引导。 以下是修复grub引导的步骤: 1. 接通USB闪存驱动器后,启动您的计算机。 在启动按下F2,F8,F12或其他适当的键,以打开计算机的启动选项。 2. 选择从USB闪存驱动器引导,并进入Ubuntu安装程序。选择分区和安装Ubuntu的方式。 3. 安装完成后,重新启动计算机。 确保您已删除USB驱动器,并登录Ubuntu。进入Ubuntu命令行。 4. 在控制台,键入sudo update-grub ,以重新生成grub引导文件。按下Enter键,等待该操作完成。 5. 重新启动计算机,并确保计算机正常引导Ubuntu操作系统。 如果您的计算机仍然无法启动,您可能需要重新安装Ubuntu。如果您需要重新安装,请确保已备份您的数据,以免丢失。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值