GNU GRUBを使う

Last Update : 2002/05/18


[Back to Index][Back to Top]
・関連リンク
GNU GRUBとは…高機能ブートローダーです。
今までLinuxでブートローダーといえば"LILO(LInux LOder)"が伝統的に使われてきたのだが、最近の流行はより高機能なGNU GRUBになってきました。
赤帽でも標準ブートローダーとしても採用してます。
  1. GRUBパッケージのダウンロード
    ftp://ftp.kddlabs.co.jp/pub/Linux/packages/Kondara/pub/Kondara-2.1/Zoo/i586/grub-0.90-8k.i586.rpm

    ※2002/05/18現在の最新版はftp://ftp4.kondara.org/pub/Linux/Kondara/Kondara-2.1/PKGS/i586/grub-0.91-0.02001121104k.i586.rpmです。

  2. GRUBパッケージのインストール

    # rpm -ivh grub-0.90-8k.i586.rpm


    ※2002/05/18現在の最新パッケージはgrub-0.91-0.02001121104k.i586.rpmです。

  3. GRUBをフロッピーにインストール

    # dd if=/usr/share/grub/i386-redhat/stage1 of=/dev/fd0 count=1 bs=512
    1+0 records in
    1+0 records out
    # dd if=/usr/share/grub/i386-redhat/stage2 of=/dev/fd0 seek=1 bs=512
    186+1 records in
    186+1 records out


  4. フロッピーで起動
    フロッピーからブートするとGRUBが起動してプロンプトが出るので、Linuxを起動してみます。
    (私のマシンはプライマリマスタHDDの先頭パーティションがWindows 2000、第2パーティションがLinuxのルートパーティションになってますので、それを前提に書きます。)
    Asumiのカーネルバージョンは2.4.18-10kで、GRUBの場合第1HDDは"hd0"、第2HDDは"hd1"、第1パーティションは"0"、第2パーティションは"1"のように指定します。
    また、GRUBのシェルでは英字キーボードの扱いになるので、日本語キーボードの場合は"("、")"、"="を入力するときは注意しませう。
    英字キーボードの扱いになっているときの日本語キーボードでの入力は以下のような対応になります。
    入力文字 ( ) =
    通常の入力 [SHIFT]+[8] [SHIFT]+[9] [SHIFT]+[-]
    GRUBでの入力 [SHIFT]+[9] [SHIFT]+[0] [^]

    GRUBのシェルはbashのようにTABキーで補完が効きますし、プロンプトで"help"と入力するとヘルプが出ます。

    grub> root (hd0,1) ← ルートデバイスの指定(第1HDDの第2パーティション)
    grub> kernel /boot/vmlinuz-2.4.18-10k root=/dev/hda2 ← 起動カーネルの指定
    grub> initrd /boot/initrd-2.4.18-10k.img ← initrdの指定
    grub> boot ← Kernel起動


  5. GRUBをMBRにインストールする。

    # /sbin/grub-install /dev/hda
    Installation finished. No error reported.
    This is the contents of the device map /boot/grub/device.map.
    Check if this is correct or not. If any of the lines is incorrect,
    fix it and re-run the script `grub-install'.

    (fd0) /dev/fd0
    (hd0) /dev/hda
    (hd1) /dev/hdb

    これで、HDDからブートしてもGRUBが起動します。

  6. HDDからLinuxをブートする。
    再起動して、GRUBのプロンプトが出たらフロッピーブートのときと全く同様に入力し、Linuxを起動します。

    grub> root (hd0,1) ← ルートデバイスの指定(第1HDDの第2パーティション)
    grub> kernel /boot/vmlinuz-2.4.18-10k root=/dev/hda2 ← 起動カーネルの指定
    grub> initrd /boot/initrd-2.4.18-10k.img ← initrdの指定
    grub> boot ← Kernel起動


  7. HDDからWindowsをブートする。
    同様に、GRUBのプロンプトが出たら以下の様に入力し、Windows 2000を起動します。

    grub> root (hd0,0) ← ルートデバイスの指定(第1HDDの第1パーティション)
    grub> makeactive ← おまじない(笑)
    grub> chainloader +1 ← 同じくおまじない(笑)
    grub> boot ← Windows起動


  8. 起動メニューを作る
    いちいちブートの度にコマンド入れてらんないんで、起動メニューを作成します。
    /boot/grub/ に menu.lst というファイルを作ります。
    ついでにグラフィカルなブートメニューにしちまいます。
    Asumi の場合、/boot/grub/splash.xpm.gz というのがあります。 ただ、このままだと色数が多くてエラいこっちゃになるので、一度gzipで解凍して色数を落とします。
    (サイズは640*480で14色の画像にするらしい…誰か絵作ってぇ〜(^-^;)

    # cp /boot/grub/splash.xpm.gz /root
    # gzip -d splash.xpm.gz
    # convert splash.xpm splash.jpg
    # convert -colors 14 splash.jpg splash.xpm
    # gzip splash.xpm
    # cp splash.xpm.gz /boot/grub


    で、menu.lst はこんな感じ。


    # Time Out (Sec)
    timeout 30

    # Default Entry (up to 0,1,2,3...)
    default 0

    # Foreground Color
    foreground = 88ccff

    # Background Color
    background = cc6600

    # Border Color
    border = ff0000

    # Display Image
    splashimage = (hd0,1)/boot/grub/splash.xpm.gz

    ## Kondara MNU/Linux Boot
    title Kondara MNU/Linux 2.1 (Asumi)
    root (hd0,1)
    kernel /boot/vmlinuz-2.4.17-14k root=/dev/hda2 acpi=no-idle apm=on ← Kernelに渡すオプションはKernelコマンドの後ろに続けて書く
    initrd /boot/initrd-2.4.17-14k.img

    ## Windows 2000
    title Microsoft Windows 2000
    root (hd0,0)
    makeactive
    chainloader +1


    で、これを /boot/grub/ にぶち込む。

    # cp menu.lst /boot/grub


  9. GRUBを再度MBRにインストール
    でも、ただぶち込むだけでは再起動しても起動メニューは出てこない。
    ただGRUBのプロンプトが出てくるだけです。
    なぜかというと、/boot/grub に grab.conf というのが無いからなのです。
    Kondaraの場合、grab.conf はただ単に menu.lst へのシンボリックリンクとなっていて /sbin/grub-install を実行すれば勝手に作ってくれます。
    なんでさっき実行したときに作ってくれなかったかというと…勘の良い方ならすでにお分かりでしょうが、そうです!リンク先の menu.lst が存在してないからです(笑)

    # /sbin/grub-install /dev/hda
    Installation finished. No error reported.
    This is the contents of the device map /boot/grub/device.map.
    Check if this is correct or not. If any of the lines is incorrect,
    fix it and re-run the script `grub-install'.

    (fd0) /dev/fd0
    (hd0) /dev/hda
    (hd1) /dev/hdb


これですべて完了です!
再起動すればGRUBの起動メニューが表示されます。
ちなみに私の設定での起動メニューはこんな感じ!



[Back to Index][Back to Top]