歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Grub2 添加自定義啟動項

Grub2 添加自定義啟動項

日期:2017/2/28 16:23:23   编辑:Linux教程

此文非教程,僅作記錄之用。

目的:為了從硬盤加載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
...
}

Copyright © Linux教程網 All Rights Reserved