Grub2 添加自定义启动项


此文非教程,仅作记录之用。

目的:为了从硬盘加载Clonezilla live,添加自定义启动项

预期结果:BIOS启动后,shift键后进入Grub菜单,可以选择加载Clonezilla live

步骤:
1. 在Grub2的/etc/grub.d/40_custom里加入menuentry。
2. 用update-grub2 更新/boot/grub/grub.cfg 这个启动配置文件。
3. 重启

问题:
1. Be careful not to change the 'exec tail' line above.

40_custom 文件如下所示。不要去改动前面两行,因为'exec tail -n +3 $0',已经暗示我们这个文件会从第三行开始读取有效配置。这点可以从update-grub2后生成的grub.cfg 中得到印证。所以如果你想要改任何的东东,哪怕是加注释或者空行。需要去更新正确的行数到-n后面。

#!/bin/sh
exec tail -n +3 $0 
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

比如,有人希望在update-grub2时候看到有处理40_custom的动作,在'exec tail -n +3 $0'前面加入了
echo “processing the 40_custom\r” 1>2&
那就把你的+3改成+4就ok了,就像下面那样。

#!/bin/sh
echo "processing 40_custom\r" 1>&2
exec tail -n +4 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

所以,不要只看注释写的,说不动'exec tail‘那句话就ok,你不动那句,动了它周边的位置,也会有问题哦~~

2. Simply type the menu entries you want to add after this comment.
把要添加的menuentry直接紧跟着40_custom的注释之后,不要添加空行。否则会在grub.cfg 里也产生空行,这样启动的时候Grub2读grub.cfg 产生启动选项的时候,会不显示你添加的东东。
正确定制如下,
#!/bin/sh
echo "processing 40_custom\r" 1>&2
exec tail -n +4 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "Clonezilla live" {
    ...
    your customized boot entry
    ...
}

相关内容