如何使用grub引导grub?
Tofloor
poster avatar
iseric
deepin
2018-04-25 21:17
Author
我依照这个帖子在U盘上安装了grub和其他的东西【2017.12.25】deepin安装U盘制作,支持 BIOS+UEFI,deepin_Recovery+Win PE

我想添加一条菜单,由U盘上的grub引导硬盘上的grub启动系统,即“正常启动”

请问能否做到呢?

目前我的grub配置是这样写的
  1. menuentry "[d] (实验性) 正常启动"                  --hotkey=d{
  2.     echo "正在启动 chainloader +1,请等待...."
  3.     set root=(hd1,1)
  4.     chainloader +1
  5.     boot
  6. }
Copy the Code
但是我遇到了这个错误
  1. 错误:invalid EFI file path.
Copy the Code

用 grub shell 也不行


请问我该如何处理这个错误呢?

Reply Favorite View the author
All Replies
avatar
DeepinOS
deepin
2018-04-26 01:50
#1
你是用EFI模式的启动吗?
如果是的话,你用chainloader  你U盘中grub.efi文件位置,这样就可以
Reply View the author
avatar
iseric
deepin
2018-04-26 01:58
#2
https://bbs.deepin.org/post/155707
你是用EFI模式的启动吗?
如果是的话,你用chainloader  你U盘中grub.efi文件位置,这样就可以 ...

可是我是想用U盘引导硬盘啊……你确定是 chainload U盘里面的grub么
如果是要chainload硬盘里面的grub的话,我看了一下,(hd1,1)/EFI/deepin/ 下面好像只有grubx64.efi,你说的是这个么
Reply View the author
avatar
A·S·M·X·T 😏😜
deepin
2018-04-26 04:35
#3
本帖最后由 liululin 于 2018-4-25 20:38 编辑

可以用grub文件管理器直接加载硬盘/boot/grub/grub.cfg作为外置grub菜单打开deepin
Reply View the author
avatar
窄口牛
deepin
2018-04-26 15:12
#4
菜单写的是legacy命令,硬盘是efi启动。
Reply View the author
avatar
窄口牛
deepin
2018-04-27 01:26
#5
我是插上优盘的时候,显示优盘启动。
Reply View the author
avatar
iseric
deepin
2018-04-27 08:32
#6
自己琢磨出了解决方案
  1. menuentry "[d] (实验性) 正常启动"                  --hotkey=d{
  2.       echo "正在链式启动,请等待...."
  3.       insmod part_gpt
  4.       insmod fat
  5.       set root=(hd1,1)
  6.       search --label --no-floppy --set=root EFI
  7.       search --file --no-floppy --set=root /EFI/ubuntu/grubx64.efi
  8.       search --file --no-floppy --set=root /EFI/Microsoft/Boot/bootmgfw.efi
  9.       #若存在深度安装的grub则引导
  10.       if [ -e /EFI/deepin/grubx64.efi ]; then
  11.           chainloader (${root})/EFI/deepin/grubx64.efi
  12.       #否则,若存在Ubuntu安装的grub则引导
  13.       elif [ -e /EFI/ubuntu/grubx64.efi ]; then
  14.           chainloader (${root})/EFI/ubuntu/grubx64.efi
  15.       #否则,若存在Windows则引导
  16.       elif [ -e /EFI/Microsoft/Boot/bootmgfw.efi ]; then
  17.           chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi
  18.       else
  19.           echo "找不到主硬盘中的grub2,请拔下U盘,按Ctrl+Alt+Del重启电脑!"
  20.           echo "Couln't find Grub2 in HDD, please remove the flash disk and press CTRL+ALT+DEL to reboot!"
  21.       fi
  22.       boot
  23. }
Copy the Code


总结下来就是这句
  1. chainloader (${root})/EFI/deepin/grubx64.efi
Copy the Code

与MBR时代的
  1. chainloader +1
Copy the Code

不同。

UEFI需要自己去寻找efi文件来启动,不像MBR,直接+1就可以读到硬编码在磁盘分区表里面的bootloader
Reply View the author
avatar
iseric
deepin
2018-04-27 08:41
#7
https://bbs.deepin.org/post/155707
你是用EFI模式的启动吗?
如果是的话,你用chainloader  你U盘中grub.efi文件位置,这样就可以 ...

感谢你的回答!我已经解决了问题!
十分感谢!
Reply View the author
avatar
窄口牛
deepin
2018-04-27 15:26
#8
写成搜到哪个就显示哪个菜单,回车启动更好些。
Reply View the author
avatar
iseric
deepin
2018-04-27 19:43
#9
https://bbs.deepin.org/post/155707
可以用grub文件管理器直接加载硬盘/boot/grub/grub.cfg作为外置grub菜单打开deepin
...

想了一下,似乎你这样的方案适应性更强一些……我改一下吧
Reply View the author
avatar
iseric
deepin
2018-04-28 09:21
#10
更新:使用configfile代替了chainloader,避免重新载入grub,并且大幅减少了代码量
  1. #########################
  2. # 06_pc.cfg
  3. # UEFI 模式启动
  4. if [ 'efi' == $grub_platform ] ; then
  5.     menuentry "[b] (实验性) 正常启动"                  --hotkey=b{
  6.         configfile "${prefix}/Config/NormalBootList.cfg"
  7.     }
  8. fi

  9. #############################
  10. # NormalBootList.cfg
  11. set timeout=10
  12. set default=0

  13. search --file --no-floppy --set=root /efi/deepin/grub.cfg
  14. search --file --no-floppy --set=root /efi/Microsoft/Boot/bootmgfw.efi

  15. if [ -e /efi/deepin/grub.cfg ] ; then
  16.     menuentry "[g] 启动 grub" --hotkey=g{
  17.         configfile ($root)/efi/deepin/grub.cfg
  18.     }
  19. fi
  20. if [ -e /efi/Microsoft/Boot/bootmgfw.efi ] ; then
  21.     menuentry "[w] 启动 Windows" --hotkey=w{
  22.         chainloader ($root)/efi/Microsoft/Boot/bootmgfw.efi
  23.         boot
  24.     }
  25. fi
Copy the Code

感谢https://bbs.deepin.org/user/52450 https://bbs.deepin.org/user/51492 https://bbs.deepin.org/user/94453 提供的思路
Reply View the author
avatar
save
deepin
2018-04-29 06:44
#11
小白求教,想用u盘装deepin和win10双系统,然后装好了deepin之后重启就在grub命令行界面了,请问可以用什么命令启动系统
Reply View the author
avatar
窄口牛
deepin
2018-04-29 14:56
#12
live运行是什么情况?
Reply View the author
avatar
iseric
deepin
2018-04-29 18:54
#13
https://bbs.deepin.org/post/155707
小白求教,想用u盘装deepin和win10双系统,然后装好了deepin之后重启就在grub命令行界面了,请问可以用什么 ...
  1. search --file --set=root /efi/deepin/grub.cfg
  2. configfile /efi/deepin/grub.cfg
Copy the Code

试试看?不行的话efi换成大写
再不行就
  1. search --file --set=root /boot/grub/grub.cfg
  2. configfile /boot/grub/grub.cfg
Copy the Code

要是还不行的话,那就用ls遍历磁盘分区找一个叫做vmlinuz的文件
  1. ls (hd0,1)/
  2. ls (hd0,2)/
  3. ls (hd1,1)/
  4. ...
Copy the Code

找到了之后,记住它所在的磁盘分区,我们在这里假设是(hd0,1)
那么就
  1. set root=(hd0,1)
  2. linux /vmlinuz root=/dev/sda1
  3. initrd /initrd.img
  4. boot
Copy the Code

就可以了
如果是在(hd0,2),那set root=(hd0,2), root=/dev/sda2
如果是在(hd1,1),那set root=(hd1,1), root=/dev/sdb1
以此类推
Reply View the author
avatar
iseric
deepin
2018-04-29 18:57
#14
https://bbs.deepin.org/post/155707
live运行是什么情况?

没看懂你想说什么……
引导iso镜像当然是live运行啊……不然呢
如果想把整个Linux和pe一起安装到u盘上……应该也可以的,你可以试试看
Reply View the author
avatar
iseric
deepin
2018-04-29 18:58
#15
https://bbs.deepin.org/post/155707
小白求教,想用u盘装deepin和win10双系统,然后装好了deepin之后重启就在grub命令行界面了,请问可以用什么 ...

参见
https://www.linux.com/learn/how-rescue-non-booting-grub-2-Linux
Reply View the author
avatar
窄口牛
deepin
2018-04-29 20:40
#16
哦,忘了它是进系统再安装。
Reply View the author