无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
查看: 3163|回复: 6

求一段路径转换代码

[复制链接]
发表于 2019-7-11 20:52:44 | 显示全部楼层 |阅读模式
本帖最后由 lhb9900 于 2019-7-11 20:54 编辑

不能启动
grub_file=(hd0,msdos2)/ISO/WIN10PE.ISO
menuentry "仿真启动光盘镜像 (grub.exe)不载入内存运行" --class iso{
set enable_progress_indicator=1;
set cfgfile="find --set-root ${grub_file};map --mem ${grub_file} (0xff);map --hook;chainloader (0xff);boot"
linux ${grub_exe} --config-file=$cfgfile
}

能启动
grub_file=(hd0,msdos2)/ISO/WIN10PE.ISO
menuentry "仿真启动光盘镜像 (grub.exe)不载入内存运行" --class iso{
set enable_progress_indicator=1;
set cfgfile="find --set-root /ISO/WIN10PE.ISO;map --mem /ISO/WIN10PE.ISO (0xff);map --hook;chainloader (0xff);boot"
linux ${grub_exe} --config-file=$cfgfile
}
 楼主| 发表于 2019-7-11 21:17:20 | 显示全部楼层
wintoflash 发表于 2019-7-11 21:13
对于grub4dos,
(1)find --set-root /ISO/WIN10PE.ISO 语法正确
(2)find --set-root (hd0,msdos2)/IS ...

谢谢
回复

使用道具 举报

 楼主| 发表于 2019-7-11 21:21:49 | 显示全部楼层
wintoflash 发表于 2019-7-11 21:13
对于grub4dos,
(1)find --set-root /ISO/WIN10PE.ISO 语法正确
(2)find --set-root (hd0,msdos2)/IS ...

如果能转换GRUB2的路径到grub4dos就更好了,就不需要find了
回复

使用道具 举报

 楼主| 发表于 2019-7-11 21:42:59 | 显示全部楼层
wintoflash 发表于 2019-7-11 21:13
对于grub4dos,
(1)find --set-root /ISO/WIN10PE.ISO 语法正确
(2)find --set-root (hd0,msdos2)/IS ...

...
regexp --set=1:g4d_path '(/.*) "${grub_file}"
set cfgfile="find --set-root ${g4d_file};map --mem ${g4d_file} (0xff);map --hook;chainloader (0xff);boot"
...
多了个点,正确如下
regexp --set=1:g4d_path (/.*) "${grub_file}"
set cfgfile="find --set-root ${g4d_file};map --mem ${g4d_file} (0xff);map --hook;chainloader (0xff);boot"
...
回复

使用道具 举报

 楼主| 发表于 2019-7-11 22:00:20 | 显示全部楼层
请问W大,哪里有 grub2 regexp 相关资料,或者都比较全的GRUB2学习资料,曾经以为GRUB2不能取代grubdos4,用了W大的文件管理器之后才发现,万能的GRUB2

点评

regexp 用的正则表达式,随便找个教程就行了。 https://deerchao.net/tutorials/regex/regex.htm https://www.runoob.com/regexp/regexp-syntax.html 不过要注意这些教程里面有些不是标准正则表达式的语法,grub  详情 回复 发表于 2019-7-12 07:57
回复

使用道具 举报

 楼主| 发表于 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};
                        }
回复

使用道具 举报

发表于 2019-7-12 16:43:39 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

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

本版积分规则

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

闽公网安备 35020302032614号

GMT+8, 2024-4-19 02:13

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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