|
如题,grub4dosuefi(以下简称g4e)的默认工作目录是/efi/grub,如果是用其他efi程序调用g4e,如果不是放在工作目录,会调用失败,有时候会进入一个grub的命令行界面。
我目前采用的方法是,内置menu.lst,定制一个g4e。
mkimage -p /8888 -o BOOTX64.EFI -O x86_64-efi -c menu.lst
通过这样,就能把g4e放在8888目录。
然后现在有了新的需求,要求8888目录可以动态改名,然后通过g4e引导目录内的menu.lst。这时候就遇到问题了,上面的p参数是写死的,没法通用。
使用deepseek,要求设置工作目录,以及动态加载目录内menu.lst,代码如下。
timeout 0
default 0
# 设置根设备为当前设备
root (bd)
# 获取当前路径
set /a current_path=%@root%
set /a current_path=%current_path:~1%
# 设置当前路径为工作路径
prefix %current_path%
# 检查当前目录下是否存在menu.lst文件
if exist %current_path%/menu.lst goto boot_menu
if exist menu.lst goto boot_menu
# 如果当前目录没有menu.lst,尝试在上级目录查找
set /a current_path=%current_path%/
set /a parent_path=%current_path:~0,-1%
if exist %parent_path%/menu.lst goto boot_parent
# 如果都找不到,显示错误信息
echo Error: menu.lst not found in current or parent directory!
pause
fallback 1
:boot_menu
configfile %current_path%/menu.lst
goto end
:boot_parent
configfile %parent_path%/menu.lst
goto end
:end
但是这些代码失败了,请问各位大神,大概需要怎么写代码,或者说,是不是无法实现这个功能。
|
|