refind 配合 VentoyLiveCD 来启动iso(系统,pe等)

# 下载
# https://sourceforge.net/projects/refind/files/
refind-bin-0.14.0.2.zip

# 配置文档
https://www.rodsbooks.com/refind/configfile.html
# 解压zip之后, 使用第一个分区为fat32的U盘进行文件存置
refind/refind_x64.efi 放到 /EFI/boot/bootx64.efi
refind 包括目录 放到 /EFI/boot 下
refind/refind.conf-sample 复制到 /EFI/boot/refind.conf
# 为什么要指定存放目录为/EFI/boot/,因为默认的加载的efi配置是 EFI/boot/bootx64.efi 其他配置文件需要相对位置

# 编辑 refind.conf
# 不喜欢图形界面的打开
textonly
# 工具,取消注释
showtools shell, bootorder, gdisk, memtest, mok_tool, apple_recovery, windows_recovery, about, hidden_tags, reboot, exit, firmware, fwupdate



# 如果是在硬盘上, 如果无法启动, 再使用 BOOTICE 工具修改 UEFI 启动序列, 添加并选择 refind_x64.eif, 既可以不用覆盖之前的bootx64.efi文件,实现双启动项
# U盘上不需要

# 用 bootice 修复 MBR 引导问题, 貌似只有[分区引导记录]才能作为启动分区
#     bootice主界面->主引导记录->windows NT5.x/6.x MBR
#     bootice主界面->分区引导记录->选择对应的分区->bootmgr引导程序/NTLDR引导程序


# 参考
https://www.altairwei.top/2018/10/31/win-linux-dual-system/
  • winpe 添加到分区实现新增pe启动项

# 下载pe的iso镜像
# 新增一个U盘的fat32分区
# 然后解压iso镜像到分区里面,解压之后会看到很多文件以及启动的EFI文件: /EFI/BOOT/BOOTX64.EFI
# 给分区的磁盘重命名,比如 PEVOL

# 新增配置启动项到配置,主要是指定volume名称和loader的.EFI文件位置,如果不知指定volume,默认就是refind的volume

menuentry "win10PE" {
    volume   "PEVOL"
    loader   /EFI/BOOT/BOOTX64.EFI
}
  • 配置启动项实例


menuentry Linux {
    icon EFI/refind/icons/os_linux.png
    volume 904404F8-B481-440C-A1E3-11A5A954E601
    loader bzImage-3.3.0-rc7
    initrd initrd-3.3.0.img
    options "ro root=UUID=5f96cafa-e0a7-4057-b18f-fa709db5b837"
    disabled
}

# Below is a more complex Linux example, specifically for Arch Linux.
# This example MUST be modified for your specific installation; if nothing
# else, the PARTUUID code must be changed for your disk. Because Arch Linux
# does not include version numbers in its kernel and initrd filenames, you
# may need to use manual boot stanzas when using fallback initrds or
# multiple kernels with Arch. This example is modified from one in the Arch
# wiki page on rEFInd (https://wiki.archlinux.org/index.php/rEFInd).
menuentry "Arch Linux" {
    icon     /EFI/refind/icons/os_arch.png
    volume   "Arch Linux"
    loader   /boot/vmlinuz-linux
    initrd   /boot/initramfs-linux.img
    options  "root=PARTUUID=5028fa50-0079-4c40-b240-abfaf28693ea rw add_efi_memmap"
    submenuentry "Boot using fallback initramfs" {
        initrd /boot/initramfs-linux-fallback.img
    }
    submenuentry "Boot to terminal" {
        add_options "systemd.unit=multi-user.target"
    }
    disabled
}

# A sample entry for loading Ubuntu using its standard name for
# its GRUB 2 boot loader. Note uses of Linux-style forward slashes
menuentry Ubuntu {
    loader /EFI/ubuntu/grubx64.efi
    icon /EFI/refind/icons/os_linux.png
    disabled
}

# A minimal ELILO entry, which probably offers nothing that
# auto-detection can't accomplish.
menuentry "ELILO" {
    loader \EFI\elilo\elilo.efi
    disabled
}

# Like the ELILO entry, this one offers nothing that auto-detection
# can't do; but you might use it if you want to disable auto-detection
# but still boot Windows....
menuentry "Windows 7" {
    loader \EFI\Microsoft\Boot\bootmgfw.efi
    disabled
}

# EFI shells are programs just like boot loaders, and can be
# launched in the same way. You can pass a shell the name of a
# script that it's to run on the "options" line. The script
# could initialize hardware and then launch an OS, or it could
# do something entirely different.
menuentry "Windows via shell script" {
    icon \EFI\refind\icons\os_win.png
    loader \EFI\tools\shell.efi
    options "fs0:\EFI\tools\launch_windows.nsh"
    disabled
}

# MacOS is normally detected and run automatically; however,
# if you want to do something unusual, a manual boot stanza may
# be the way to do it. This one does nothing very unusual, but
# it may serve as a starting point. Note that you'll almost
# certainly need to change the "volume" line for this example
# to work.
menuentry "My macOS" {
    icon \EFI\refind\icons\os_mac.png
    volume "macOS boot"
    loader \System\Library\CoreServices\boot.efi
    disabled
}

# The firmware_bootnum token takes a HEXADECIMAL value as an option
# and sets that value using the EFI's BootNext variable and then
# reboots the computer. This then causes a one-time boot of the
# computer using this EFI boot option. It can be used for various
# purposes, but one that's likely to interest some rEFInd users is
# that some Macs with HiDPI displays produce lower-resolution
# desktops when booted through rEFInd than when booted via Apple's
# own boot manager. Booting using the firmware_bootnum option
# produces the better resolution. Note that no loader option is
# used in this type of configuration.
menuentry "macOS via BootNext" {
    icon /EFI/refind/icons/os_mac.png
    firmware_bootnum 80
    disabled
}

引导grub2

# 自己编译grubx64.efi的文件
# 电脑默认支持grubx64.efi、bootx64.efi,如果文件不支持会只显示一个下划线,最好修改一个文件名称

# 或者从常用的linux镜像中提取
nixos-plasma5-23:\boot\efi.img 里面的 EFI\boot\bootx64.efi

# https://ftp.gnu.org/gnu/grub/
# grub-2.06-for-windows.zip

grub-mkimage.exe -d x86_64-efi -c x86_64-efi.cfg -p /EFI/grub -o z_bootx64.efi -O x86_64-efi part_gpt part_msdos disk fat exfat ext2 ntfs xfs appleldr hfs iso9660 normal search_fs_file configfile linux linux16 chain loopback echo efi_gop efi_uga video_bochs video_cirrus file gfxmenu gfxterm gfxterm_background gfxterm_menu halt reboot help jpeg ls png true

# 重命名grubx64.efi生成z_bootx64.efi文件,并复制模块文件夹x86_64-efi/
grub-mkimage.exe -p /EFI/boot -o z_bootx64.efi -O x86_64-efi -d x86_64-efi part_gpt part_msdos disk fat exfat ext2 ntfs xfs appleldr hfs iso9660 normal search_fs_file configfile linux linux16 chain loopback echo efi_gop efi_uga video_bochs video_cirrus file gfxmenu gfxterm gfxterm_background gfxterm_menu halt reboot help jpeg ls png true terminal


-d 表示指定查找模块目录, 最后的参数就是模块名称
-c 表示指定配置文件,这个配置文件会集成到efi文件内,就是我们刚刚编写的 grub.cfg
-p 设置偏好文件夹,会查找grub.cfg文件的目录, 通常是/EFI/grub,这里我用同一个目录/EFI/boot
-o 表示生成的目标文件
-O 表示生成二进制文件的格式,x86电脑用的x86_64-efi
 
# 启动grub,配合 当前目录的grub.cfg进行菜单管理,需要font也可以下载fonts/目录的文件
menuentry "grub2" {
    volume   "UP"
    loader   EFI/boot/z_bootx64.efi
}

grub.cfg 文件,配置参考grub2-bios-uefi-usb 如果配置异常,不会显示菜单

set default="0"

function load_video {
  insmod efi_gop
  insmod efi_uga
  insmod video_bochs
  insmod video_cirrus
  insmod all_video
}

load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod ext2

set timeout=5
### END /etc/grub.d/00_header ###

# 设置根目录,设置之后以后引用文件的路径就以当前目录为根目录
search --no-floppy --set=root -l 'Fedora 18 x86_64'
# 或者以指定文件的形式进行指定根目录
# search --set=root --file /EFI/nixos-installer-image

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Fedora 18' --class fedora --class gnu-linux --class gnu --class os {
	linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=Fedora\x2018\x20x86_64
	initrdefi /images/pxeboot/initrd.img
}
menuentry 'Test this media & start Fedora' --class fedora --class gnu-linux --class gnu --class os {
	linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=Fedora\x2018\x20x86_64 quiet rd.live.check
	initrdefi /images/pxeboot/initrd.img
}


# 添加Windows
# 需要查看分区的uuid
# 或者 search --no-floppy --set=root -l 'Fedora 18 x86_64' 使用 -l 指定分区的标识符名称
menuentry 'Windows' {
    insmod part_gpt
    insmod fat
    search --no-floppy --set=root --fs-uuid <ESP分区的UUID>
    chainloader /EFI/Microsoft/Boot/bootx64.efi
}
  • 引导基于grub2的文件管理器,可以浏览并启动iso文件

# 基于grub2的文件管理器
# https://github.com/a1ive/grub2-filemanager/releases
# 下载 grubfm-zh_CN.7z 提取 grubfmx64.efi
menuentry "fimemanger" {
    volume   "UP"
    loader   EFI/boot/grubfmx64.efi
}
  • 查看分区的uuid

# linux
lsblk -f

# windows

diskpart
# 磁盘
list disk
select disk 0
# 分区
list partition
select partition 1
detail partition
  • 引导.vhdx的系统

# 实际需要refind加载win的efi引导至BCD,由bcd引导至vhdx文件启动
# efi文件路径以及同目录的BCD文件,复制到当前位置即可,使用BOOTICEx64.exe软件可以进行编辑
\EFI\Microsoft\Boot\bootmgfw.efi
\EFI\Microsoft\Boot\BCD

# 也可以把整个\EFI\Microsoft 复制过来只作引导wind的备份


# winBCD
menuentry "winBCD" {
    volume   "UP"
    loader   EFI/boot/bootmgfw.efi
}


# 似乎只能引导win的\Windows\system32\winload.efi, 不支持linux