可以直接下载以下操作的所有文件:https://download.csdn.net/download/u010875635/10655981
本来不想设置积分,无奈最低只能设置1分,大家见谅。没有积分的还是从grub2官网下载按照下面的修改吧
首先要从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
}