如何在 UEFI 机器上使用 grub2 从我的驱动器启动 ISO 文件?

Fab*_*bby 16 live-usb boot grub2 iso uefi

我有一堆实时 ISO 文件,例如GPartedCloneZillaBoot-RepairUbuntu 14.04 32 位...下载/opt到我的旧 BIOS 机器上,我曾经能够将它们添加到 grub 菜单并启动它们. :-)

我现在有一台 UEFI 机器,我能找到的所有信息都是关于 BIOS 机器的。

从 grub 启动这些 ISO 文件的步骤是什么?

我只是厌倦了一直将这些“刻录”到 U 盘上,因为我永远找不到我需要的 U 盘,而我的计算机本身在我周围的混乱中更难松动...... ) :-(

Fab*_*bby 16

grub 2.04 中存在一个错误,因此请确保您拥有之前或之后的版本。

好吧,将 ISO 文件添加到 grub 的基础知识对于 UEFI 和 BIOS 机器是相同的:编辑/etc/grub.d/40_custom并添加一个menuentry项目(在本示例中使用 GParted)到文件底部:

menuentry "GParted Live ISO" {
}
Run Code Online (Sandbox Code Playgroud)

现在我们要添加一个变量,其中包含我们存储 ISO 的目录(到目前为止,一切都很好:与 BIOS 机器没有区别):

menuentry "GParted Live ISO" {
  set GPartedISOFile="/opt/Live-ISOs/gparted-live-0.31.0-1-amd64.iso"
}
Run Code Online (Sandbox Code Playgroud)

/opt用来存储这些,因为我不喜欢在我的机器的根目录中创建目录,并且根据Linux 文件系统层次结构,无论如何都应该驻留可选软件。

在我们添加loopback变量之前,我们需要找出文件存储在哪个硬盘上,所以我们做了一个:df --output=source /opt/Live-ISOs/gparted-live-0.31.0-1-amd64.iso | tail -1,我机器上的输出是:/dev/sdb2

但是grub 使用 ( hdX,Y) 表示法,就是 UEFI 和 BIOS 机器之间的区别所在!所以现在重新启动你的机器,进入 grub 菜单并按下C: 这将带你进入 grub 命令提示符,其中包含与你习惯不同的命令,但你唯一需要的是:ls

在我的机器上,输出是:

(hd0) (hd1) (hd1,gpt3) (hd1,gpt2) (hd1,gpt1) (hd2) ... (hd3) ...
Run Code Online (Sandbox Code Playgroud)

嗯?4个驱动?我只有3个!它不是(hd1,4)在 BIOS 上,而是(hd1,gpt3)在 UEFI 中,(hd0)根本没有分区!

好吧,很明显,当 NVRAM 的一部分用作存储并显示为(hd0) 您需要开始将驱动器编号为 1 时!  而您在启动 ISO 文件时找到的所有信息都说您必须从 0 开始编号(在 BIOS 机器上这总是正确的,但在某些 UEFI 机器上不一定如此!)

所以我机器上的 ISO 文件的值loopback变成(hd2,gpt2)$GPartedISOFile/dev/sdb2(第二个驱动器hd2,第二个分区gpt2):

menuentry "GParted Live ISO" {
  set GPartedISOFile="/opt/Live-ISOs/gparted-live-0.31.0-1-amd64.iso"
  loopback loop (hd2,gpt2)$GPartedISOFile
}
Run Code Online (Sandbox Code Playgroud)

另一个区别是,linuxinitrd上BIOS的机器被称为linuxefiinitrdefiUEFI的机器,这为我们提供了我们最终的结果:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

menuentry "GParted Live ISO" {
  set GPartedISOFile="/opt/Live-ISOs/gparted-live-0.31.0-1-amd64.iso"
  loopback loop (hd2,gpt2)$GPartedISOFile
  linuxefi (loop)/live/vmlinuz boot=live components config findiso=$GPartedISOFile ip=frommedia toram=filesystem.squashfs union=overlay username=user
  initrdefi (loop)/live/initrd.img
}
Run Code Online (Sandbox Code Playgroud)

所以现在保存该文件,并使用以下命令更新 grub:

update-grub
Run Code Online (Sandbox Code Playgroud)

完成上述所有操作后,重新启动,进入 grub 菜单,选择GParted Live ISO,您现在可以轻松启动 ISO,而无需再次寻找 U 盘!

:-)

CloneZilla Live 示例(针对此问题

menuentry "CloneZilla ISO" {
  set ISOFile="/opt/Live-ISOs/clonezilla-live-20170905-zesty-amd64.iso"
  loopback loop (hd2,gpt2)$ISOFile
  linuxefi (loop)/live/vmlinuz boot=live components config findiso=$ISOFile ip=frommedia toram=filesystem.squashfs union=overlay
  initrdefi (loop)/live/initrd.img
}
Run Code Online (Sandbox Code Playgroud)


old*_*red 7

另一种方法是像这样向 40_custom 添加一个配置文件:

menuentry 'Live ISOs on SSD' {
configfile (hd0,3)/ISO/livecdimage.cfg
} 

menuentry 'Live ISOs on HDD (boot on SSD)' {
configfile (hd1,3)/ISO/livecdimage.cfg
} 
Run Code Online (Sandbox Code Playgroud)

我这样做是因为当我更新 ISO 时,我总是忘记运行sudo update-grub. 上述条目永远不必更改,我可以编辑 livecdimage.cfg,它与任何 40_custom 格式相同但没有标题行,并且位于我的 ISO 分区的 /ISO 文件夹中。

我确实将 toram 添加为另一个引导参数,并在 Nvidia 系统上添加 nomodeset 引导参数。但是还是经常要卸载/isodevice。

无法卸载 isodevice 卸载 ISO https://bugs.launchpad.net/ubuntu/+source/ubiquity/+bug/1155216

sudo umount -l -r -f /isodevice
Run Code Online (Sandbox Code Playgroud)

这是我的 livecdimage.cfg 文件的一部分

# livecdimage.cfg
# Add this to 40_custom to load this file:
# menuentry 'Live ISOs' {
# configfile (hd1,3)/iso/livecdimage.cfg
#} 
# Add iso names to livecdimage.cfg
#for i in `ls *.iso`;do echo "# "$i>>livecdimage.cfg; done;

menuentry "Ubuntu 16.04.4 xenial amd64" {
    set isofile="/ISO/ubuntu-16.04.4-desktop-amd64.iso"
    loopback loop (hd0,3)$isofile 
    linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile toram
    initrd (loop)/casper/initrd.lz
}

menuentry "Ubuntu 18.04 Bionic amd64" {
    set isofile="/ISO/bionic-desktop-amd64.iso"
    loopback loop (hd0,3)$isofile 
    linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile toram
    initrd (loop)/casper/initrd.lz
}

# spacer line
menuentry " " {
set root= 
}

menuentry "Reboot" {
    reboot
}

menuentry "Halt" {
    halt
}
Run Code Online (Sandbox Code Playgroud)


C.S*_*ron 5

mkusb 多引导黑客

Mkusb 为自定义启动驱动器项目奠定了良好的基础,因为它具有 BIOS 和 UEFI 的能力。

这个 hack 引导多个 ISO 文件,包括 Windows 安装程序,并有一个 grub2 菜单。

大多数操作系统的 Grub2 菜单条目都可以使用 Google 搜索获得,并且超出了本答案的范围。

mkusb 默认值

创建永久 USB 驱动器时使用 mkusb 默认值。

mkusb 再次使用默认值

如果有疑问,请使用 mkusb 持久性默认值,分区大小可以稍后调整,但需要时间。

DUS 控制台

安装后的 DUS 控制台。

GParted 之前

分区修改前的 GParted。

分手后

修改后的Gparted - 覆盖sdb4,ISO9660 OS分区和sdb5,ext2 casper-rw分区,FAT32分区用于持久化文件。

持久化分区

持久性分区 - 为每个操作系统创建一个唯一名称的文件夹,(需要持久性)

持久化文件夹

持久文件夹 - 向每个持久文件夹添加一个 casper-rw 文件和可选的 home-rw 文件。可以通过重命名 casper-rw 文件来制作 home-rw 文件。home-rw 文件就像完整安装中的一个单独的主分区,它可以在版本升级后重复使用。

ISO文件夹

在 NTFS usbdata 分区上为 ISO 文件创建一个文件夹。

ISO文件夹内容

将一些 ISO 添加到 ISO 文件夹中。

GRUB 位置

grub.cfg 位置

配置文件

编辑 grub.cfg 以循环挂载 ISO 文件。包括:persistent persistent-path=/<persistent-folder-name>/如果你想要持久性。将 rmmod tpm 添加到第一个菜单项上方的 grub.cfg。

编辑 18.04+在 grub 中指定vmlinuz不是 vmlinuz.efi 和initrd不是 initrd 不是 initid.lz

须藤分开 -ls /dev/sdb

须藤分开 -ls /dev/sdb

须藤 lsblk -f /dev/sdb

须藤 lsblk -f /dev/sdb

如果需要 Windows 安装程序,从 mkusb“提取 Windows 安装程序”功能开始可能是最简单的(我必须手动将 Windows ISO 提取到 TAR),

mkusb Windows 安装程序

安装后,为 ISO 创建一个文件夹,如果需要,为持久性创建一个文件夹(类似于上述过程)。

mkusb Windows grub

编辑 /boot/grub/grub.cfg 以循环挂载任何 ISO 并指定任何持久性文件夹。

(还没有找到一种方法来循环挂载 Windows ISO 文件)。

如果以上用作 U 盘,它可用于启动存储在仅 Windows 计算机上的 ISO。内部驱动器上不需要 Grub。