两个 linux 发行版,grub 没有检测到其他发行版

omi*_*nns 7 dual-boot debian grub2 linux-mint

我的 PC 上安装了两个 linux 发行版,linux Mint 和 Debian,它们都有单独的引导分区,并且都安装在luks加密卷上。先安装了 Debian,然后我安装了 Mint。在 Mint 安装时 grub 没有检测到 Debian。update-grub在 Mint 上运行也检测不到 Debian。我应该怎么做才能让 grub 检测到两个发行版?

我的分区结构如下:

sda
|---- sda1 (windows boot [ntfs])
|---- sda2 (windows [ntfs])
|---- sda3 (extended)
      |---- sda5 (debian boot [ext4]) mounted at /media/...
      |---- sda6 (debian root [crypt-luks]) mounted at /media/...
      |---- sda7 (mint boot [ext4]) mounted at /boot
      |---- sda8 (mint root [crypt-luks]) mounted at /
Run Code Online (Sandbox Code Playgroud)

我的 mint 安装正在运行,并且分区已按上述方式安装。

sudo os-prober
Run Code Online (Sandbox Code Playgroud)

输出:

/dev/sda1:Windows 10 (loader):Windows:chain
Run Code Online (Sandbox Code Playgroud)

和,

sudo update-grub
Run Code Online (Sandbox Code Playgroud)

输出:

Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-57-generic
Found initrd image: /boot/initrd.img-4.4.0-57-generic
Found linux image: /boot/vmlinuz-4.4.0-53-generic
Found initrd image: /boot/initrd.img-4.4.0-53-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
Found Windows 10 (loader) on /dev/sda1
done
Run Code Online (Sandbox Code Playgroud)

两个找到的 linux 映像都是 mint 映像。

Emm*_*osa 4

即使os-prober检测到您的两个 Linux 安装,它也没有多大用处,因为它不会生成 GRUB2 配置。它只是以机器可读的格式报告它发现的内容。

与无需任何工具、需要手动配置的 GRUB 旧版不同,GRUB2 使用生成配置和手动配置的组合。

update-grub是grub-mkconfig的包装器,该实用程序用于检测/boot中的内核。因为grub-mkconfig使用已挂载的 /boot(也许它也可以基于 /etc/fstab 挂载 /boot)并且您的 Linux 安装使用单独的 /boot 分区,所以grub-mkconfig只会为您当前运行的 Linux 发行版生成配置。这就是为什么在 Debian 中未检测到 Mint,反之亦然。

幸运的是, /etc/grub.d/ 中应该有一些 GRUB2 配置脚本,您可以使用它们手动将条目添加到 GRUB2 菜单。

修复

要将两个 Linux 安装放入同一个 GRUB2 菜单中,您可以执行以下操作。

选择一个 Linux 安装作为 GRUB 的维护者

您需要选择要从中更新 GRUB 的 Linux 系统。例如,如果您选择 Debian,那么就向自己保证永远不会运行update-grubMint。

为其他 Linux 安装添加自定义菜单条目

这可能因 Linux 发行版而异,但基本上您需要编辑正确的配置文件来添加其他Linux安装的菜单条目。例如,如果您选择 Debian 来管理 GRUB2,那么您需要手动添加 Mint 的菜单项。

运行 update-grub/grub-mkconfig

当您运行时update-grub,它现在将使用在 /boot 中检测到的任何内容以及您为其他 Linux 安装手动配置的组合来生成可以引导两个操作系统的 GRUB 菜单。

其他资源

查看Gentoo Linux 的 GRUB2 文档。这不是一个插件,只是它比 Debian 的等效文档更详细,并且可以帮助您指明正确的方向。