【grub2】制作UEFI版本Grub2引导多系统
2017-11-20 00:00
232 查看
首先要从grub官网下在grub2,grub2中包含所有grub2相关的命令,可以用来生成grub2引导,这里着重介绍制作UEFI版本的grub2
UEFI启动是fat/fat32分区/EFI/Boot/bootia32.efi或者/EFI/Boot/bootx64.efi,然后进程由UEFI交给efi程序,我们就是制作这个efi程序,使用grub-mkimage命令即可生成。
efi程序中需要内置配置文件,类似grub的grldr文件,一旦生成后就很难修改了,所以,我们需要一个类似与menu.lst的配置文件,所以我们指定的配置文件中指向外部的cfg配置文件
以下为64位efi生成,32位参考文件夹名称,将x86_64-efi修改为i386-efi即可,一般是不需要,支持UEFI的基本都是64位的PC。
内置配置文件为:x86_64-efi.cfg,内置配置文件搜索/EFI/grub/x64.cfg 文件,并将其设定为配置文件。
将其保存在grub2解压目录下,内容如下:
search.file /EFI/grub/x64.cfg root
set prefix=($root)/EFI/grub
configfile ($root)/EFI/grub/x64.cfg
在grub2解压目录下,输入以下命令:
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
-d 表示指定查找模块目录
-c 表示指定配置文件,这个配置文件会集成到efi文件内,就是我们刚刚编写的x86_64-efi.cfg
-p 设置偏好文件夹,cfg文件中会调
-o 表示生成的目标文件
-O 表示集成的模块
以上生成完毕,在文件夹下会出现一个bootx64.efi文件,将其和x86_64-efi、locale文件夹、unicode.pf2一起拷贝到第一个fat/fat32分区,并新建一个x64.cfg。
其中,x86_64-efi为模块目录,locale为地区语言,unicode.pf2为字体,x64.cfg为配置文件
目录如下:
FAT/FAT32
#########################
/EFI/Boot/bootx64.efi
/EFI/grub/x64.cfg
/EFI/grub/unicode.pf2
/EFI/grub/x86_64-efi/
/EFI/grub/locale/
#####################
x64.cfg内容示例:
function load_video {
if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
}
insmod part_gpt
insmod fat
set root='hd0,gpt1'
#set font
font="/EFI/grub/unicode.pf2"
if loadfont $font ; then
set gfxmode=auto
load_video
insmod gfxterm
set locale_dir=$prefix/locale
set lang=zh_CN
insmod gettext
fi
#adjust the screen resolution
terminal_output gfxterm
#background
insmod jpeg
if background_image /EFI/grub/background.jpg; then
true
else
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
if background_color 255,255,155,0; then
clear
fi
fi
#default select menu index
set default=0
#timeout
set timeout_style=menu
set timeout=5
menuentry "启动 delta win7" --class windows --class os {
insmod ntfs
set root='(hd0,gpt2)'
clear
echo "Start Windows"
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
menuentry "local win7" --class windows --class os {
insmod ntfs
set root='(hd0,gpt3)'
clear
echo "Start Windows"
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
menuentry "ubuntu16.04 x86" --class ubuntu --class os {
insmod ext2
set root='(hd0,gpt5)'
linux /vmlinuz ro root=/dev/sda5
initrd /initrd.img
echo "Start Ubuntu 16.04"
}
menuentry "ubuntu16.04 x64" --class ubuntu --class os {
insmod ext2
set root='(hd0,gpt6)'
linux /vmlinuz ro root=/dev/sda6
initrd /initrd.img
echo "Start Ubuntu 16.04"
}
menuentry "-------------------" --class ubuntu --class os{
set root=(hd0,gpt1)
}
menuentry "ubuntu-efi" --class ubuntu --class os {
insmod ext2
set root='(hd0,gpt5)'
chainloader /efi/grub.efi
}
menuentry "install ubuntu" --class ubuntu --class os {
insmod ext2
insmod loopback
set root=(hd0,gpt4)
set isofile=/OS/linux/ubuntu-16.04.2-desktop-amd64.iso
loopback loop $isofile
linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile
initrd (loop)/casper/initrd.lz
}
menuentry "-------------------" --class ubuntu --class os{
set root=(hd0,gpt1)
}
menuentry "reboot" --class windows --class os{
insmod reboot
reboot
}
menuentry "halt" --class windows --class os{
insmod halt
halt
}
UEFI启动是fat/fat32分区/EFI/Boot/bootia32.efi或者/EFI/Boot/bootx64.efi,然后进程由UEFI交给efi程序,我们就是制作这个efi程序,使用grub-mkimage命令即可生成。
efi程序中需要内置配置文件,类似grub的grldr文件,一旦生成后就很难修改了,所以,我们需要一个类似与menu.lst的配置文件,所以我们指定的配置文件中指向外部的cfg配置文件
以下为64位efi生成,32位参考文件夹名称,将x86_64-efi修改为i386-efi即可,一般是不需要,支持UEFI的基本都是64位的PC。
内置配置文件为:x86_64-efi.cfg,内置配置文件搜索/EFI/grub/x64.cfg 文件,并将其设定为配置文件。
将其保存在grub2解压目录下,内容如下:
search.file /EFI/grub/x64.cfg root
set prefix=($root)/EFI/grub
configfile ($root)/EFI/grub/x64.cfg
在grub2解压目录下,输入以下命令:
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
-d 表示指定查找模块目录
-c 表示指定配置文件,这个配置文件会集成到efi文件内,就是我们刚刚编写的x86_64-efi.cfg
-p 设置偏好文件夹,cfg文件中会调
-o 表示生成的目标文件
-O 表示集成的模块
以上生成完毕,在文件夹下会出现一个bootx64.efi文件,将其和x86_64-efi、locale文件夹、unicode.pf2一起拷贝到第一个fat/fat32分区,并新建一个x64.cfg。
其中,x86_64-efi为模块目录,locale为地区语言,unicode.pf2为字体,x64.cfg为配置文件
目录如下:
FAT/FAT32
#########################
/EFI/Boot/bootx64.efi
/EFI/grub/x64.cfg
/EFI/grub/unicode.pf2
/EFI/grub/x86_64-efi/
/EFI/grub/locale/
#####################
x64.cfg内容示例:
function load_video {
if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
}
insmod part_gpt
insmod fat
set root='hd0,gpt1'
#set font
font="/EFI/grub/unicode.pf2"
if loadfont $font ; then
set gfxmode=auto
load_video
insmod gfxterm
set locale_dir=$prefix/locale
set lang=zh_CN
insmod gettext
fi
#adjust the screen resolution
terminal_output gfxterm
#background
insmod jpeg
if background_image /EFI/grub/background.jpg; then
true
else
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
if background_color 255,255,155,0; then
clear
fi
fi
#default select menu index
set default=0
#timeout
set timeout_style=menu
set timeout=5
menuentry "启动 delta win7" --class windows --class os {
insmod ntfs
set root='(hd0,gpt2)'
clear
echo "Start Windows"
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
menuentry "local win7" --class windows --class os {
insmod ntfs
set root='(hd0,gpt3)'
clear
echo "Start Windows"
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
menuentry "ubuntu16.04 x86" --class ubuntu --class os {
insmod ext2
set root='(hd0,gpt5)'
linux /vmlinuz ro root=/dev/sda5
initrd /initrd.img
echo "Start Ubuntu 16.04"
}
menuentry "ubuntu16.04 x64" --class ubuntu --class os {
insmod ext2
set root='(hd0,gpt6)'
linux /vmlinuz ro root=/dev/sda6
initrd /initrd.img
echo "Start Ubuntu 16.04"
}
menuentry "-------------------" --class ubuntu --class os{
set root=(hd0,gpt1)
}
menuentry "ubuntu-efi" --class ubuntu --class os {
insmod ext2
set root='(hd0,gpt5)'
chainloader /efi/grub.efi
}
menuentry "install ubuntu" --class ubuntu --class os {
insmod ext2
insmod loopback
set root=(hd0,gpt4)
set isofile=/OS/linux/ubuntu-16.04.2-desktop-amd64.iso
loopback loop $isofile
linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile
initrd (loop)/casper/initrd.lz
}
menuentry "-------------------" --class ubuntu --class os{
set root=(hd0,gpt1)
}
menuentry "reboot" --class windows --class os{
insmod reboot
reboot
}
menuentry "halt" --class windows --class os{
insmod halt
halt
}
相关文章推荐
- 【grub2】制作UEFI版本Grub2引导多系统
- UEFI BIOS模式下Windows系统启动过程以及引导文件修复方法
- UEFI系统安装U盘的制作方式
- UEFI下win10+ubuntu16.04双系统安装教程加高b格rEFInd可diy开机引导
- CentOS系统安装(下):kickstart文件及引导镜像的制作
- Windows 8 + centOS7双系统引导丢失 grub2解决
- UBIFS文件系统简介 与 利用mkfs.ubifs和ubinize两个工具制作UBI镜像 (完整理解版本)
- Windows平板装Android双系统及建立UEFI引导全攻略(windows8.1+android6+phoenix)
- Windows和Ubuntu双系统,修复UEFI引导的两种办法
- WinSetupFromUSB制作多系统U盘引导启动
- UEFI 引导安装 Windows 8 与 Ubuntu 12.04 双系统
- 系统安装之引导剖析,深入理解legacy与uefi
- Windows和Ubuntu双系统,修复UEFI引导的两种办法
- 把手教你源代码制作龙芯64位系统 (交叉编译版本)2.0 正式版
- Windows+Linux 双系统 grub2 引导问题
- 利用F5 VE制作F5 11.6.1系统安装引导U盘
- 系统引导UEFI 引导,Win下挂载EFI分区教程
- 如何制作系统引导光盘?
- [导入]谈论Vista版本以后关于多系统引导方面的改进
- .Net C#制作新版本安装包安装时系统提示“已经安装了该产品的另一个版本”