FreeBSD8.1 amd64 + grub2 のパッチ

FreeBSD8.1-amd64-release で grub2のインストールに失敗する

バグだそうです

検証環境
CPU PhenomII x4 905e (2.5GHz 4-core)
メモリ DDR3-1066 4GB x 2
HDD SATA 250GB
グラフィック GA-880GM-USB3 (Gigabyte) オンボード
サウンド GA-880GM-USB3 (Gigabyte) オンボード
ネットワーク GA-880GM-USB3 (Gigabyte) オンボード GbE
OS FreeBSD8.1-amd64-release

先日 上記の構成でパソコンを購入して 64bit IPv6 環境を構築しようか という矢先に

# grub-install /dev/ad4
/usr/local/sbin/grub-probe: error: cannot find a device for /boot/grub (is /dev mounted?).
No path or device is specified.
Try `/usr/local/sbin/grub-probe --help' for more information.
Auto-detection of a filesystem module failed.
Please specify the module with the option `--modules' explicitly.
 

のような 謎のエラーでインストールできない
–modulesを指定しても やっぱりエラー

ネットで検索したところ 結局バグだったということで対処方法も記載されていたので備忘録です

バイナリパッケージは 結局バグってるので一旦アンインストールします

# pkg_delete grub2-1.98
 

portsからソースファイルを拾ってきます

# cd /usr/ports/sysutils/grub2
# make fetch
〜
# make extract
〜
#
 

ここで portsで提供されている patch-util-getroot.c パッチを削除 (これが間違ってるらしい)

# rm files/patch-util-getroot.c
 

代わりに files/patch-include-grub-gpt_partition.h を下記の内容で作成
(vi などのエディッタで作成)

--- include/grub/gpt_partition.h.orig   2010-03-06 12:51:37.000000000 -0800
+++ include/grub/gpt_partition.h        2010-10-10 02:57:26.000000000 -0700
@@ -40,6 +40,17 @@
     { 0x74, 0x4e, 0x65, 0x65, 0x64, 0x45, 0x46, 0x49 } \
   }

+#define GRUB_GPT_PARTITION_TYPE_FREEBSD_BOOT \
+  { grub_cpu_to_le32 (0x83BD6B9D), grub_cpu_to_le16 (0x7F41), grub_cpu_to_le16 (0x11DC), \
+    { 0xBE, 0x0B, 0x00, 0x15, 0x60, 0xB8, 0x4F, 0x0F } \
+  }
+
+#define GRUB_GPT_PARTITION_TYPE_SOLARIS_BOOT \
+  { grub_cpu_to_le32 (0x6A82CB45), grub_cpu_to_le16 (0x1DD2), grub_cpu_to_le16 (0x11B2), \
+    { 0x99, 0xA6, 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } \
+  }
+
+
 struct grub_gpt_header
 {
   grub_uint8_t magic[8];
 

もうひとつ files/patch-util-i386-pc-grub-setup.c を下記の内容で作成

--- util/i386/pc/grub-setup.c.orig      2010-03-06 12:51:37.000000000 -0800
+++ util/i386/pc/grub-setup.c   2010-10-10 02:56:55.000000000 -0700
@@ -38,7 +38,8 @@
 #include <grub/util/getroot.h>

 static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT;
-
+static const grub_gpt_part_type_t grub_gpt_partition_type_freebsd_boot = GRUB_GPT_PARTITION_TYPE_FREEBSD_BOOT;
+static const grub_gpt_part_type_t grub_gpt_partition_type_solaris_boot = GRUB_GPT_PARTITION_TYPE_SOLARIS_BOOT;
 #include <grub_setup_init.h>

 #include <stdio.h>
@@ -138,7 +139,9 @@
       struct grub_gpt_partentry *gptdata = p->data;

       /* If there's an embed region, it is in a dedicated partition.  */
-      if (! memcmp (&gptdata->type, &grub_gpt_partition_type_bios_boot, 16))
+      if (! memcmp (&gptdata->type, &grub_gpt_partition_type_bios_boot, 16) ||
+             ! memcmp (&gptdata->type, &grub_gpt_partition_type_freebsd_boot, 16) ||
+                 ! memcmp (&gptdata->type, &grub_gpt_partition_type_solaris_boot, 16))
        {
          embed_region.start = p->start;
          embed_region.end = p->start + p->len;
 

ビルド インストールします

# make build
〜
# make install

途中で 依存性のある portsのインストールについても聞かれるかもしれません
(とりあえず ハイと答えておく)
一応これで grub2のツール一式はインストールされます

いよいよ grubのセットアップをします

# mkdir /boot/grub
#
 

/boot/grub/grub.cfg を下記の感じで作成します
背景画像の /boot/grub/bg1.tga は必要あれば各自で準備します 640×480 32bit tga画像です

set default=0
set timeout=20

set root=(hd0,1,a)
set gfxmode=640x480
set menu_color_normal=white/black
set menu_color_highlight=white/green

insmod terminal
insmod gfxterm
insmod vbe
insmod tga

terminal gfxterm
background_image (hd0,1,a)/boot/grub/bg1.tga

menuentry "FreeBSD" {
 set root=(hd0,1,a)
 kfreebsd /boot/loader
}
 

/boot/grub/device.map を作成します 次のコマンドで自動生成してくれます

# grub-mkdevicemap
#
 

最後に ハードディスクの MBR(マスターブートレコード)を書き換えます
慎重に!!
ハードディスクの MBRにインストールするのか PBRにインストールするのかは各環境に応じてください

# grub-install /dev/ad4
Installation finished. No error reported.
 

エラーメッセージは出ず 正常に動作したように見えます
(バグの原因はルートデバイス情報を うまく取得できないことによる不具合だったらしい…)
後はシステムをリブートして確認するだけです

ちなみに 検証環境ではうまく GRUBが動作したが
背景画像が表示されず真っ暗でしたー