UEFI添加grub2引导

准备材料:

下载grub-2.02-for-windows.zip

第一步:

将grub-2.02-for-windows.zip解压至d盘根目录。以管理员身份运行cmd。

输入以下指令将当前路径切换至grub-2.02-for-windows文件夹下。

cd /d d:\grub-2.02-for-windows

第二步:

输入以下指令查看grub-mkimage.exe的参数

grub-mkimage.exe --help

输出以下结果:

d:\grub-2.02-for-windows>grub-mkimage.exe --help
Usage: grub-mkimage.exe [OPTION...] [OPTION]... [MODULES]
Make a bootable image of GRUB.
 
  -c, --config=FILE          embed FILE as an early config(此文件存储一些设置变量)
  -C, --compression=(xz|none|auto)
                             choose the compression to use for core image(选择内核的压缩模式)
  -d, --directory=DIR        use images and modules under DIR
                             [default=d:\grub-2.02-for-windows/<platform>](指定模块的路径,i386-efi,x86_64.efi,i386-pc等文件夹)
  -k, --pubkey=FILE          embed FILE as public key for signature checking(嵌入一个文件作为签名检查的公共密钥)
  -m, --memdisk=FILE         embed FILE as a memdisk image(嵌入文件作为一个内存镜像)。Implies `-p (memdisk)/boot/grub' and overrides
                             any prefix supplied previously, but the prefix itself can be overridden by later options(当加载内存镜像时,应用/boot/grub作为优先查找路径,并覆盖所有的以前提供的预配置文件,但是预配置文件可以被后边的选项重写)
  -n, --note                 add NOTE segment for CHRP IEEE1275(为CHRP IEEE1275添加备注)
  -o, --output=FILE          output a generated image to FILE [default=stdout](设置输出文件的名称)
  -O, --format=FORMAT        generate an image in FORMAT
                             available formats: i386-coreboot, i386-multiboot,
                             i386-pc, i386-pc-pxe, i386-pc-eltorito, i386-efi,
                             i386-ieee1275, i386-qemu, x86_64-efi, i386-xen,
                             x86_64-xen, mipsel-yeeloong-flash,
                             mipsel-fuloong2f-flash, mipsel-loongson-elf,
                             powerpc-ieee1275, sparc64-ieee1275-raw,
                             sparc64-ieee1275-cdcore, sparc64-ieee1275-aout,
                             ia64-efi, mips-arc, mipsel-arc,
                             mipsel-qemu_mips-elf, mips-qemu_mips-flash,
                             mipsel-qemu_mips-flash, mips-qemu_mips-elf,
                             arm-uboot, arm-efi, arm64-efi(设置输出文件的格式)
  -p, --prefix=DIR           set prefix directory(设置预先查找配置文件的路径)
  -v, --verbose              print verbose messages.
  -?, --help                 give this help list
      --usage                give a short usage message
  -V, --version              print program version
 
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
 
Report bugs to <[email protected]>.

第三步:

在grub-2.02-for-windows当前目录下新建一个配置文件,对应grub-mkimage.exe -c,–config=file。

32位的配置文件我们命名为i386-efi.cfg,文本内容:

search.file /EFI/grub/ia32.cfg root (查找的配置文件名称为ia32.cfg,路径在/EFI/grub路径下)
set prefix=( r o o t ) / E F I / g r u b ( 设 置 / E F I / g r u b 为 p r e f i x 目 录 ) c o n f i g f i l e ( root)/EFI/grub (设置/EFI/grub为prefix目录) configfile ( root)/EFI/grub/EFI/grubprefixconfigfile(root)/EFI/grub/ia32.cfg (设置配置文件的路径及名称)

64为的配置文件我们命名为x86_64-eif.cfg,文本内容:

search.file /EFI/grub/x64.cfg root  
set prefix=($root)/EFI/grub  
configfile ($root)/EFI/grub/x64.cfg  

后边会使用i386-efi.cfg和x86_64-eif.cfg代替file名称。

第四步:

32位的运行以下命令:

grub-mkimage.exe -d i386-efi -c i386-efi.cfg -p /EFI/grub -o bootia32.efi -O i386-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

grub-mkimage.exe

-d i386-efi (指定路径)

-c i386-efi.cfg (指定配置文件)

-p /EFI/grub (指定预配置文件路径)

-o grubia32.efi (生成文件的名称)

-O i386-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(集成的模块)

64位的运行以下命令:

grub-mkimage.exe -d x86_64-efi -c x86_64-efi.cfg -p /EFI/grub -o 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

grub-mkimage.exe

-d x86_64-efi

-c x86_64-efi.cfg

-p /EFI/grub

-o 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

运行完成后当前目录下将生成以下文件:

32位的:grubia32.efi

64位的:grubx64.efi

第五步:

从windows原生系统镜像内复制bootmgr.efi文件至/EFI所在磁盘的根目录下,并将生成的bootia32.efi、bootx64.efi复制到/EFI/boot文件夹内,其他文件夹复制到/EFI/grub文件夹内。

32位的,需新建ia32.cfg配置文件,与生成过程中i386-efi.cfg文件内定义的名称相同:

i386-efi

locale

themes

fonts

64位的,需新建x64.cfg配置文件,与生成过程中x86_64-efi.cfg文件内定义的名称相同:

i386-efi

locale

themes

fonts

其中locale、themes和fonts文件夹,32位和64位可以共用。

文件结构图:

bootmgr.efi
/EFI
├───boot
│       bootia32.efi
│       bootx64.efi
│
└───grub
    │   ia32.cfg
    │   x64.cfg
    │
    ├───i386-efi
    │       acpi.mod
    │		........  
    │
    ├───fonts
    │       unicode.pf2
    │
    ├───locale
    │   ├───ast
    │   ├───...... 	
    │   └───zh_TW
    │           grub.mo
    │
    ├───themes
    │   └───starfield
    │           blob_w.png
    │           boot_menu_c.png
    │ 			.........	
    │           theme.txt
    │
    └───x86_64-efi
            acpi.mod

第六步:

UEFI文件调用顺序:

1、启动后首先查找FAT、FAT16、FAT32分区,读取分区根目录下bootmgr.eft,将控制权限移交给/EFI/boot目录下的bootia32.efi或bootx64.efi。

2、bootia32.efi和bootx64.efi文件内部已经编译了配置文件ia32.cfg和x64.cfg的路径,会到/EFI/grub文件夹路径下调用ia32.cfg和x64.cfg。

3、ia32.cfg和x64.cfg文件内可以编辑内容,定义菜单、加载模块、设置样式、设置主题。

4、如果通过set theme=$prefix/themes/starfield/theme.txt设置过主题样式,则会调用theme.txt,输出主题。

猜你喜欢

转载自blog.csdn.net/seaship/article/details/111401398
今日推荐