无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
楼主: hilsonma
打印 上一主题 下一主题

[分享] 使用Grub2定制UEFI启动 (bootx64.efi)

    [复制链接]
1#
发表于 2019-8-15 15:29:28 | 显示全部楼层
回复

使用道具 举报

2#
发表于 2019-8-15 17:07:06 | 显示全部楼层
大神你好,我改成这样了。改完后我希望我的grub.cfg中的配置能生效要怎么办呢。

在efi分区要目录加了你的efi目录,然后我加了自己的另外两个目录linux,pe结构是这样的。传不了图,我直接打出来
efi根目录文件:

efi,linux,pe,wepe.wim

efi目录主要是改了grub中的内容添加了几个文件grub的内容是

fonts,i386-pc,locale,themes,grub.cfg,grub32.cfg,grubenv,grubfm.cfg

grubcfg的配置改成了:
#################
## (1)特殊变量 ##
#################
#设置菜单的超时时间为5秒
set timeout=3600
#默认启动第4个菜单项众从0开始
set default=3
#
#set vt_handoff=vt.handoff=7
#
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue
#自动匹配分辨率
set gfxmode=auto
set timeout_style=menu
#将GRUB2设置为简体中文界面
set lang=zh_CN
set gfxterm_font=unicode

#################
## (2)公共模块 insmod module 载入名为"module"的GRUB2模块。 ##
#################
#两种最流行的磁盘分区格式(partmap.lst)
insmod part_gpt
insmod part_msdos
#常见文件系统驱动(fs.lst)
insmod fat
insmod exfat
insmod ntfs
insmod iso9660
insmod ext2
insmod xfs
#一次性加载所有可用的视频驱动
insmod all_video
#图形模式终端
insmod gfxterm
#背景图片支持
insmod png
insmod jpeg
#
insmod gettext
#可用于提供主题支持
insmod gfxmenu     
#将"file"文件映射为"device"回环设备   
insmod loopback        

#列出已经加载的所有模块
lsmod

#########################################
## (3)公共命令(必须放在模块和变量之后) ##
#########################################
#激活图形模式的输出终端,以允许使用中文和背景图
terminal_output  gfxterm
#加载字体文件
#loadfont (hd0,1)/efi/grub/themes/Vimix/unifont-regular-16.pf2 #设置字体
set theme=(hd0,1)/efi/grub/themes/Vimix/theme.txt #设置主题
#set theme=(hd0,1)/efi/grub/themes/breeze/theme.txt #设置主题
export theme

   
#################
## (4)菜单项   ##
# chainloader [--force] file :链式加载"file"文件。通常使用磁盘块表示法,例如用'+1'表示当前根分区的第一个扇区。
# linux file … 使用32位启动协议从"file"载入一个Linux内核映像,并将其余的字符作为内核的命令行参数逐字传入。
#--class 指定icon,在/themes/主题名/icons目录下有同名文件即可显示icon
#################

set root=(hd0,1)

menuentry "Windows 10 enterprise_x64 ISO" --class windows {
   
    chainloader +1
}

menuentry "ubuntu 18.04.2 desktop amd64 ISO " --class ubuntu --class gun-linux {
    set isofile=/linux/ubuntu_18_04/ubuntu-18.04.2-desktop-amd64.iso
    loopback loop0 $isofile
    linux (loop0)/casper/vmlinuz boot=casper iso-scan/filename=$isofile locale=zh_CN.UTF-8
    initrd (loop0)/casper/initrd
}

menuentry "Start WePE ISO " --class windows {
    set isofile=/pe/wepe/wepe_64.iso
    set g4d_dir="/efi/Grub4dos/"
    set cfgfile="find --ignore-floppies --ignore-cd --set-root $isofile; map --mem $isofile (0xff);map --hook;chainloader (0xff)"
    linux $g4d_dir/grub.exe --config-file=$cfgfile
}

#menuentry "hard disk boot" --class harddrive {
#    set root='hd1'
#    chainloader +1
#}

#menuentry "hard disk boot" --class harddrive {
#    set root='hd0,msdos5'
#    set g4d_dir="/Grub4dos/"
#    set cfgfile="map (hd0) (hd1);map (hd1) (hd0);map --hook;rootnoverify (hd0,0);makeactive;chainloader +1"
#    linux $g4d_dir/grub.exe --config-file=$cfgfile
#}

menuentry "Reboot" --class restart {
    reboot;
}

menuentry "ShutDown" --class shutdown {
    halt;
}


点评

定制efi文件的时候就定义了你的grub2路径 grub-mkimage -O x86_64-efi -p /efi/grub -o grubx64.efi part_msdos fat normal 这是最简单的定制,少了任何一项都无法进入普通模式,只会进入救援模式。 -O x86_8  详情 回复 发表于 2019-8-15 18:06
定制efi文件的时候就定义了你的grub2路径 grub-mkimage -O x86_64-efi -p /efi/grub -o grubx64.efi part_msdos fat normal 这是最简单的定制,少了任何一项都无法进入普通模式,只会进入救援模式。 -O x86_8  详情 回复 发表于 2019-8-15 18:04
回复

使用道具 举报

3#
发表于 2019-8-15 21:46:43 | 显示全部楼层
hilsonma 发表于 2019-8-15 18:06
如果你定制时使用的参数是 -p /efi/grub
那么你修改 /efi/grub/grub.cfg 你的配置就会生效。
如果你 ...

大神,的确我的菜单生效了但点了后没有实际想要的效果,而且主题也没生效,我之前在BIOS的都可以生效,但我现在想要改成uefi的方式了。哪我现在要怎么改才能和bios一样的效果呢。还是通过guub引导的方式。

点评

没有图片,我也看不出个所以然,只能假定你把需要加载的模块都加载了。 我一般是这样写的: 看起来你没有设置 color_normal 和 color_highlight 不知道这些奇怪的东西你是在哪里抄的。。  详情 回复 发表于 2019-8-16 09:42
我没有用过主题,也不懂  详情 回复 发表于 2019-8-15 22:46
回复

使用道具 举报

4#
发表于 2019-8-18 00:22:11 | 显示全部楼层
hilsonma 发表于 2019-8-15 22:46
我没有用过主题,也不懂

可以加载主题了,是我用了你定制的grub efi,但你定制的没有加载主题需要的模块所以没效果。我从新定制后可以加载了。现在遇到了新问题。我看了grubfm.cfg后有了想法。想搜索磁盘中按照一定规则的文件显示出来。但好像现本有些问题能帮我看看吗,脚本是这样的。

grub.cfg菜单中有项是这样的。

menuentry "2.wepe startup find, name [.wim .iso .efi]" --hotkey=2 --class windows {
        export op='((\.wim)|(\.iso)|(\.efi))$'
        configfile "${prefix}"/wepe_startup_find.cfg
}

解释:
export op='((\.wim)|(\.iso)|(\.efi))$'             #传入一个正则表达式过滤出定制的文件
configfile "${prefix}"/wepe_startup_find.cfg  #转到wepe_startup_find.cfg

wepe_startup_find.cfg 大概是这样的。
grubfm_init;
if  test -f "${op}"; then
        echo "grubfm grubfm_open"
        echo "op:${op}"
        grubfm_open "${op}"
        unset op;
else
        echo "grubfm grubfm_find"
        echo "op:${op}"
        #set name_regexp="${op}"
        grubfm_find "${op}"
        unset op;
fi

#name_check
function name_check {
        echo "name_check arg1:${1}";
       
        set name_file="${1}";
        if ! test -f "${name_file}"; then
                unset name_file;
                return false
        fi
       
        if ! regexp "${name_regexp}" "${name_file}"; then
                unset name_file;
                return false
        fi
       
        menuentry "${name_file}" "${name_file}" {
                #$1=title,$2=
                export op=$2;
                configfile ${grub_fm};
        }

        unset name_file;
}

#dir_earch
function dir_earch {
        echo "dir earch find arg1:${1}";
       
        set dir="${1}";
        for item in ${dir}/*; do
                if test -d "${item}"; then
                        #dir_deep_3 "${item}"
                else
                        name_check "${item}"
                fi;
        done;
        unset dir;
}

# grubfm_find DIR
function grubfm_find {
        set default=1;
        set name_regexp="${1}"

        menuentry ".." --class dir {
                configfile "${grub_fm}";
        }

        #列出grub可见的设备
        ls

        for device in (*); do
                echo "earch device:${device}"
               
                if test -d "${device}"; then
                       
                        #probe --set=fs -f "${device}";
                        #probe --set=label -l "${device}";
               
                        if regexp 'loop' "${device}"; then
                                continue;
                        elif test "${device}" = "(memdisk)" -o "${device}" = "(proc)"; then
                                continue;
                        fi;
                fi;
               

                for item in ${device}/*; do
                        #regexp --set=name '.*/(.*)$' "${item}";

                        if test -d "${item}"; then
                                dir_earch "${item}"
                        else
                                name_check "${item}
                        fi;
                done;
        done;

        unset name_regexp;
}

回复

使用道具 举报

5#
发表于 2019-8-18 00:22:53 | 显示全部楼层
wintoflash 发表于 2019-8-16 09:42
没有图片,我也看不出个所以然,只能假定你把需要加载的模块都加载了。
我一般是这样写的:
看起来你没 ...

恩,谢谢,的确是有些模块没加载,写脚本遇到了新问题帮忙看看哈。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-5-4 08:34

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表