|
5#
楼主 |
发表于 2019-7-12 00:10:47
|
只看该作者
#GRUB2转换GRUBDOS4路径结贴,这里是gamelife大的 ,但 wintoflash大的代码更简单些,感谢谢两位大神的开源
set grub_file="(hd0,msdos2)/ISO/WIN10PE.ISO";
set grub_exe="/Boot/grub/grub.exe";
function funcDec {
#初始化变量
set str="$1";
set fag="1";
set str_final="";
set str_end="";
#循环处理,直到借位标志$fag不为1
while test "${fag}" = "1" ; do
#生成序列
setparams "9" "8" "7" "6" "5" "4" "3" "2" "1" "0";
#提取最后一位
regexp --set=str_end '^.*(.$)' "${str}";
if test "$?" != "0"; then
#字符串为空
set fag="-1";
break;
fi
#去掉$str最后一位
regexp --set=str '(^.*).$' "${str}";
#查找所在序列位置
until test "${str_end}" = "$1" -o "$#" -le "0"; do
shift;
done;
#检查非法字符
if test "$#" -le "0"; then
set fag="-1";
break;
fi
#检查是否借位并保持当前位
if test "$1" = "0"; then
#需要借位
set str_final="9${str_final}";
else
#不需借位
set fag="0";
shift;
set str_final="$1${str_final}";
fi
done;
#合拼字符串到$str
set str="${str}${str_final}";
#去除首位到“0”
regexp --set=str '^0*([^0].*$)' "${str}";
#清理环境变量
unset str_final;
unset str_end;
#检查错误并输出结果
if test "${fag}" = "-1"; then
unset str;
unset fag;
return 1;
else
unset fag;
return 0;
fi
}
function funcToG4dPath {
#分区号
regexp --set=1:str_1 --set=2:str_2 --set=3:str_3 '(^\([[:alpha:]]+[[:digit:]]+,)[mM]?[sS]?[dD]?[oO]?[sS]?([[:digit:]]+)(\).*$)' "$1";
if test "$?" = "0"; then
if funcDec "${str_2}"; then
set str="${str_1}${str}${str_3}";
else
set str="";
fi
else
set str="$1";
fi
#空格
set str_3="";
while regexp --set=1:str_1 --set=2:str '(^[^ ]*)[ ](.*$)' "${str}"; do
set str_3="${str_3}${str_1}"'\\ ';
done;
set str="${str_3}${str}"
#清理
unset str_1;
unset str_2;
unset str_3;
if test -z "${str}"; then
unset str;
return 1;
else
return 0;
fi
}
function GetHotkey {
if [ "$k" != "." ]; then
set hotkeys="_0123456789adfghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`=,."
regexp -s k "${k}(.)" "$hotkeys"
fi
}
function grubfm_init {
insmod loopback;
insmod probe;
insmod progress;
insmod regexp;
set debug= ;
set enable_progress_indicator=0;
set grub_exe="/Boot/grub/grub.exe";
set grub_fm="/Boot/grub/grubfm.cfg";
set grub_ipxe="/Boot/grub/ipxe.lkrn";
set grub_memdisk="/Boot/grub/memdisk";
set grub_wimboot="/Boot/grub/wimboot";
set pager=0;
}
funcToG4dPath ${grub_file};
set g4dfile="${str}";
#regexp --set=1:g4d_path (/.*) "${grub_file}"
menuentry "仿真启动光盘镜像 (grub.exe)不载入内存运行" --class iso{
set enable_progress_indicator=1;
set cfgfile="find --set-root ${g4dfile};map ${g4dfile} (0xff);map --hook;chainloader (0xff);boot"
linux ${grub_exe} --config-file=$cfgfile
}
menuentry "仿真启动光盘镜像 (grub.exe)载入内存运行" --class iso{
set enable_progress_indicator=1;
set g4d_cmd="map --mem (rd)+1 (0xff);map --hook;chainloader (0xff)"
linux16 ${grub_exe} --config-file=$g4d_cmd;
initrd16 ${grub_file};
} |
|