无忧启动论坛

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

[求助] grub2能否查找活动分区的bootmgr?

[复制链接]
1#
发表于 2021-12-14 12:38:04 | 显示全部楼层
probe --bootable hdx,y -s aaa
检测分区是否为可启动分区(对于mbr分区表,指的是已激活分区,对于gpt分区表,指的是ESP分区)
若有可启动标志,则将变量aaa的值设为bootable,否则设为none。
使用for循环遍历分区,即可满足要求。参考代码:
https://github.com/a1ive/grub2-f ... fm/osdetect.sh#L131

点评

感觉还是有点复杂,还要考虑ntldr的情况,我看还是绕弯解决吧。 menuentry "0.Windows" "/bootmgr" --hotkey=0 { if search --no-floppy --set --file /bootmgr ; then chainloader +1 elif search --no-flopp  详情 回复 发表于 2021-12-14 14:05
回复

使用道具 举报

2#
发表于 2021-12-14 15:03:10 | 显示全部楼层
本帖最后由 wintoflash 于 2021-12-14 15:05 编辑

没有你想像的那么难。以下是伪代码,仅供参考:
for d in (hd*,msdos*) do
  if [ -e ${d} ] then
    regexp --set=disk '\((.*)\)' "${d}"
  else
    continue
  fi
  probe --set=flag -b ${disk}
  if [ "${flag}" = "none" ] then
    continue
  fi
  if [ -f "(${disk})/ntldr" ] then
    menuentry "BOOT NTLDR" { ... }
  elif [ -f "(${disk})/bootmgr" ] then
    menuentry "BOOT BOOTMGR" { ... }
  fi
done

点评

menuentry "01.Windows" "/bootmgr" --hotkey=0 { for d in (hd*,msdos*) do if [ -e ${d} ] then regexp --set=disk '\((.*)\)' "${d}" else continue fi probe --set=flag -b ${disk} i  详情 回复 发表于 2021-12-14 21:42
回复

使用道具 举报

3#
发表于 2021-12-16 08:20:00 | 显示全部楼层
liuzhaoyzz 发表于 2021-12-14 21:42
menuentry "01.Windows" "/bootmgr" --hotkey=0 {
for d in (hd*,msdos*) do
  if [ -e ${d} ] then

用 grub-script-check 可以检查脚本的语法错误。

不能 menuentry 套 menuentry。

评分

参与人数 1无忧币 +10 收起 理由
liuzhaoyzz + 10 很给力!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

闽公网安备 35020302032614号

GMT+8, 2024-6-15 19:28

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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