grub2-menu
update 2012-04-17

fedora17より複数のカーネルが有る場合はサブメニューが作成されるようになった。
fedora16よりgrub2が採用された。
※fedora15までのgrub2との主な違いは、後述の「参考:1」を参照。

レガシーメニュー(テキスト表示)
基本設定ファイル(/etc/default/grub)に背景画像やグラフィカルメニューの指定が無い場合はテキスト表示となる。
grub2-menu1.png

レガシーメニュー(背景画像)
基本設定ファイルで背景画像やフォントを設定する。
grub2-menu2.png

グラフィカルメニュー
基本設定ファイルに指定したテーマ(theme.txt) でデザインしたグラフィカルメニューを表示する。
grub2-menu3.png

サブメニューにもテーマでデザインした表示が反映される。
grub2-menu4.png

/etc/default/grub ファイル
/etc/default/grubファイルで基本的な項目を設定する。
default.png

grub2-mkconfig 実行時にincludeされ、/boot/grub2/grub.cfg に反映される。
参照マニュアル:http://www.gnu.org/software/grub/manual/grub.html#Simple-configuration

例:/etc/default/grubファイル
GRUB_DEFAULT=saved
GRUB_TIMEOUT=none
GRUB_DISTRIBUTOR="fedora"
GRUB_CMDLINE_LINUX="rd.md=0 rd.lvm=0 rd.dm=0 SYSFONT=False rd.luks=0 LANG=ja_JP.UTF-8  KEYTABLE=jp106"

# 背景画像
GRUB_TERMINAL_OUTPUT=gfxterm
GRUB_GFXMODE=640x480
GRUB_BACKGROUND=/usr/share/backgrounds/tiles/default_blue.jpg
GRUB_FONT=/boot/grub2/unifont.pf2

# グラフィカルメニュー
GRUB_THEME=/boot/grub2/themes/fedora/theme.txt


/boot/grub2/grub.cfg の作成

grub_cfg.png

grub.cfg ファイルは grub2-mkconfig コマンドを使用して作成する。
grub2-mkconfigを実行すると次のファイルがincludeされてgrub.cfgに反映される。
  /etc/default/grub
  /etc/grub.d フォルダ内に有る実行可能な設定ファイル
grub2-mkconfig オプション無しで実行すると処理結果は画面に表示されるので確認用として使うことができる。
grub2-mkconfig -o /boot/grub2/grub.cfg でファイルに出力する。

unifont.pf2 フォントファイルの作成

unifont.png

Unifont Glyphs のページ http://unifoundry.com/unifont.html より unifont-5.1.20080820.bdf.gz をダウンロードして展開する。
wget http://unifoundry.com/unifont-5.1.20080820.bdf.gz
gunzip unifont-5.1.20080820.bdf.gz

grub2-mkfont を実行して /boot/grub2 フォルダに unifont.pf2 ファイルを作成する。
grub2-mkfont --output=/boot/grub2/unifont.pf2 unifont-5.1.20080820.bdf

※ 各種のフォントファイル作成例については「参考:3」grub2-mkfontの使用例を参照。


レガシーメニューへのフォント反映


1. 任意のフォントファイルを作成する。
※ ここでは DejaVuSansMono.ttf より DejaVuSansMono-12.pf2 を作成するものとする。
grub2-mkfont --verbose --size=12 --output=/boot/grub2/fonts/DejaVuSansMono-12.pf2 /usr/share/fonts/dejavu/DejaVuSansMono.ttf

2. 基本設定ファイル(/etc/default/grub)にフォントファイル名を記述する。
GRUB_FONT=/boot/grub2/fonts/DejaVuSansMono-12.pf2

3. カスタム設定ファイル(/etc/grub.d/40_custom)に loadfont を記述して、grub2起動時に load するようにする。
loadfont /boot/grub2/fonts/DejaVuSansMono-12.pf2

4.grub2-mkconfig で設定を反映させる。
grub2-mkconfig -o /boot/grub2/grub.cfg


グラフィカル メニューの作成

1. /etc/default/grubファイルにグラフィカルメニューのテーマを記述した theme.txt を使用することを記述する。
GRUB_THEME=/boot/grub2/themes/fedora/theme.txt

2. テーマ作成に必要な環境作成
/boot/grubフォルダに次のようなフォルダを作成する。
grub2-folder.png

(1)/boot/grub2/fonts フォルダを作成し、使用したいpf2 フォントファイルを置いておく。
※ pf2フォントファイルを作成する各種の ttfフォントは /usr/share/fontsフォルダに在る。
fontを使用する場合は loadfont /boot/grub2/fonts/dejavu-sans-bold-16.pf2 のようにフォントファイルを load して使用する。

(2)/boot/grub2/images フォルダを作成し、背景画像などに使用する イメージファイルを置いておく。

(3)/boot/grub2/themes フォルダを作成し、メニューテーマの各種設定ファイルを置いておく。
このフォルダ内のtheme.txtでグラフィカルメニューの配置などを定義する。

たとえば /boot/grub2/themes/fedora フォルダを作成し、下記のようなメニューテーマの設定ファイルを置いておく。

設定ファイルには次のファイルがある。

(1) theme.txt (GRUB gfxmenuの設定ファイル)
※theme.txtのサンプルは後述の「theme.txt ファイルのサンプル」参照。
theme_txt.png

(2) デスクトップ画面の背景
desktop-image.png

(3) menubox(メニュー表示枠)としての9分割の画像
menubox.png

(4) select(メニューアイテム選択枠)としての9分割の画像
select.png

(5) /boot/grub2/themes/fedora/icons フォルダを作成しメニューに表示するicon用の xxx.png ファイルを置いておく。
icons.png

3. theme.txtファイルにグラフィカルメニューのデザインを設定する。
※参照マニュアル:http://www.gnu.org/software/grub/manual/grub.html#Theme-file-format

theme.txt ファイルのサンプル
ここでは boot_menu セクションのみの設定例を示す。
/boot/grub2/themes/fedora/theme.txt
theme.txtでのフォントは grub2-mkfont で作成した際の「フォント名」で指定する。(フォントファイル名 pf2ではない)
# GRUB gfxmenu theme "fedora"
# Designed for 640x480 resolution

title-text: ""
title-font: "DejaVu Sans Bold 12"
title-color: "salmon"
message-font: "DejaVu Sans Bold 10"
message-color: "white"
message-bg-color: "black"
desktop-image: "default_blue.png"
terminal-box: "select_blue_*.png"

+ boot_menu {
   left = 50
   width = 540
   top = 100
   height = 280
   item_font = "DejaVu Sans Bold 18"
   selected_item_font = "DejaVu Sans Bold 18"
   item_color = "linen"
   selected_item_color = "orange"
   menu_pixmap_style = "menubox_*.png"
   selected_item_pixmap_style = "select_blue_*.png"
   icon_width = 32
   icon_height = 32
   item_height = 32
   item_padding = 0
   item_icon_space = 3
   item_spacing = 10
   max_items_shown = 7
}

4. テーマ作成に必要な環境が完成したらgrub2-mkconfigコマンドで設定ファイル(grub.cfg)を作成する。



参考:1
項目
fedora16
fedora15までのgrub2情報
設定ファイル
/boot/grub2/grub.cfgファイル
/boot/grub/grub.cfgファイル
基本設定ファイル /etc/default/grubファイル
/usr/local/etc/default/grubファイル
メニュー設定用ファイル
/etc/grub.dフォルダ内に置く
/usr/local/etc/grub.d フォルダ内に置く
フォント作成 コマンド
grub2-mkfont
grub-mkfont
grub.cfg作成 コマンド
grub2-mkconfig grub-mkconfig
インストール コマンド
grub2-install
バージョン確認は grub2-install -v
grub-install
バージョン確認は grub-install -v
※fedora15までのgrub2については http://ftlabo.sakura.ne.jp/linux/grub2/grub2.html 参照。

参考:2
メニュー項目(エントリ)の追加
fedoraが認識したデバイスのbootについては grub2-mkconfig コマンドで自動作成してくれるので、手作業で記述する必要は無い。
あえて記述する場合は /etc/grub.d/40_customファイルに記述する。
grub_d.png

/etc/grub.d/40_customファイルの設定例
--class windows、--class redo、--class exitなどの指定はiconを表示する指定なので
/boot/grub2/themes/fedora/icons ディレクトリ内のアイコン(xxx.png)に対応するファイル名(xxx)を記述しておく。
#!/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.

menuentry "Windows8" --class windows {
    insmod chain
    set root=(hd0,1)
    chainloader +1
}
menuentry "reboot" --class redo {
    reboot
}

menuentry "halt" --class exit {
    halt
}

# 1台目のhddのパーティション1にWindowsがある場合はremappingは不要。
# この記述例ではWindows8 ブートローダー(bootmgr)が起動する。
menuentry "Windows 8" --class windows {
    insmod chain
    set root=(hd0,1)
    chainloader +1
}

# 2台目のhddのパーティション1にWindowsがある場合はremappingをおこなう。
menuentry "Windows 8" --class windows {
    insmod chain
    set root=(hd1,1)
    drivemap -s hd0 hd1
    chainloader +1
}

# WindowsのMBRが設定されているデバイスの場合はパーティション番号は省略できる。remappingも不要。
menuentry "Windows 8" --class windows {
    insmod chain
    set root=(hd1)
    chainloader +1
}

# メモリーテスト
# memtest86+ のzipファイルをダウンロードして展開して memtest.bin を /boot/memtest86plus フォルダに置く。
menuentry "Memtest86+" --class memtest {
    insmod bsd
    linux16 /boot/memtest86plus/memtest.bin
}


例:レガシーメニューの背景画像を反映させる
if background_image /usr/share/backgrounds/tiles/default_blue.jpg ; then
set color_normal=white/black
set color_highlight=magenta/black
else
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue
fi


参考:3

grub2-mkfontの使用例
構文は grub2-mkfont [OPTIONS] FONT_FILES
※詳しくはヘルプ参照

例1:DejaVuSans.ttfからfontを作成

/usr/share/fonts/dejavu/DejaVuSans.ttf ファイルから各種サイズのfontを作成する。
出力先は/boot/grub2/fontsフォルダとする。
--verboseを指定すると、下記のような「フォント名」が表示される。
grub2-mkfont --verbose --range=0x0-0x7F --size=12 --output=/boot/grub2/fonts/dejavu-sans-12.pf2 /usr/share/fonts/dejavu/DejaVuSans.ttf
Font name: DejaVu Sans Regular 12 
このフォント名はグラフィカルメニューのtheme.txtにてフォント指定の「フォント名」として使用する。

Boldフォントを作成する

grub2-mkfont --verbose --range=0x0-0x7F --size=18 --output=/boot/grub2/fonts/dejavu-sans-bold-18.pf2 /usr/share/fonts/dejavu/DejaVuSans-Bold.ttf
Font name: DejaVu Sans Bold 18

例2:ダウンロードした ipagp.ttf ファイルからfontを作成

grub2-mkfont --verbose --range=0x0-0x7F --size=10 --output=/boot/grub2/ipagp-10.pf2 /root/ipagp.ttf
Font name: IPAPGothic Regular 10

grub2-mkfont --verbose --range=0x0-0x7F --size=18 --bold --output=/boot/grub2/fonts/ipagp-18-bold.pf2 /sda2/ipa-font/ipagp.ttf
Font name: IPAPGothic Bold 18

end of list