FATフォーマットのコンパクトフラッシュにGRUBをインストールする

前回の続き。
いろいろGRUBのインストール周りについて徘徊したのだけれども、どうにもフロッピーからとかバックアップのためが多くて、シンプルにGRUBだけをCFからブートする方法が見当たらない。*1というわけで、できた方法をここに書いておく。

  • 前提

LinuxとCFを書き込むためのCFリーダライタが必要。
使用するLinuxにはgrubがインストールされていること。

  • 使った機材

openSUSE10.3
grub-0.97

  • CFの認識

USB-CFをopenSUSEに挿してデバイスを認識させる。
今回使った機材では/dev/sdcとして認識した。

  • CFのフォーマット

Windowsとかでもいいですが、以下のコマンドでFAT16になるらしい。

mkdosfs /dev/sdc1

FAT32にしたい場合は

mkdosfs -F 32 /dev/sdc1

らしい。

  • ブートファイルをコピーする

openSUSE上にあるブートフィルをCFへコピーする

mount /dev/sdc1 /media/disk
mkdir -p /media/disk/boot/grub
cp /boot/grub/stage1 /media/disk/boot/grub/
cp /boot/grub/stage2 /media/disk/boot/grub/
cp /boot/grub/fat_stage1_5 /media/disk/boot/grub/

  • device.mapの変更

openSUSEGRUBで使用しているdevice.mapを見て、CFのデバイスが無い場合は追加しておく。
こんな感じ。

(hd0) /dev/sda
(hd1) /dev/sdc

でもって、grubを起動してCFのMBRへ書き込む

vostro:/boot/grub # grub


GNU GRUB version 0.97 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename. ]
grub> root (hd1,0)
root (hd1,0)
Filesystem type is fat, partition type 0x6
grub> setup (hd1) (hd1,0)
setup (hd1) (hd1,0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/fat_stage1_5" exists... yes
Running "embed /boot/grub/fat_stage1_5 (hd1)"... 15 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded
Done.
grub> quit
quit

これでFAT形式のCFからGRUBがブートできるのでコマンドベースではいろいろいじれる。
あとはmenu.lstを書けばメニュー対応もOK

*1:と思ったらしげふみメモに同じことが書いてあった