grub2のgrub-mkconfigにlabelベースな設定を書かせるメモ


* 2013/08/18 挙動がかわったようなので更新しました
* /etc/grub/10_linux
--- 10_linux.backup 2013-06-21 02:20:47.436531219 +0900
+++ 10_linux 2013-06-22 18:53:47.000000000 +0900
@@ -136,8 +136,6 @@
fi

message="$(gettext_printf "Loading Linux %s ..." "${version}")"
+ auto_label="`e2label ${GRUB_DEVICE} 2>/dev/null`"
+ linux_root_device_thisversion="LABEL=${auto_label}"
sed "s/^/$submenu_indentation/" << EOF echo '$message' linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}

* /usr/share/grub/grub-mkconfig_lib
--- grub-mkconfig_lib.backup 2013-06-21 02:35:50.038459949 +0900
+++ grub-mkconfig_lib 2013-06-22 18:53:46.000000000 +0900
@@ -146,22 +146,20 @@
done
fi

- # If there's a filesystem UUID that GRUB is capable of identifying, use it;
- # otherwise set root as per value in device.map.
- fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
- if [ "x$fs_hint" != x ]; then
- echo "set root='$fs_hint'"
- fi
- if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
- hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
- echo "if [ x\$feature_platform_search_hint = xy ]; then"
- echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
- echo "else"
- echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}"
- echo "fi"
- fi
+# # If there's a filesystem UUID that GRUB is capable of identifying, use it;
+# # otherwise set root as per value in device.map.
+# fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
+# if [ "x$fs_hint" != x ]; then
+# echo "set root='$fs_hint'"
+# fi
+# if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+# hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
+# echo "if [ x\$feature_platform_search_hint = xy ]; then"
+# echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+# echo "else"
+# echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+# echo "fi"
+# fi
+auto_label="`e2label "$@" 2>/dev/null`"↲
+echo "search --no-floppy --label ${auto_label} --set root"↲
}

grub_get_device_id ()

grub2とUUID


* 標準だとgrub2はファイルシステムのUUIDを元にどのデバイスかを区別しており、このままだと複製したbackup diskから起動しようとした時にそのUUIDのファイルシステムがのったデバイスがないといってrescue modeに落ちてしまいます。
* そこでUUIDで区別しないようにgrub2を設定してみます
====== grub2からuuidを排除 ======
* /etc/default/grubの#GRUB_DISABLE_LINUX_UUID=trueをコメントアウト
* 以下のパッチを当てる
[root@archlinux-proxmox grub]# diff -ur /usr/share/grub/grub-mkconfig_lib /backup/usr/share/grub/grub-mkconfig_lib
--- /usr/share/grub/grub-mkconfig_lib 2012-08-07 22:24:23.649377433 +0900
+++ /backup/usr/share/grub/grub-mkconfig_lib 2012-08-07 22:24:38.432711843 +0900
@@ -146,20 +146,20 @@
done
fi

- # If there's a filesystem UUID that GRUB is capable of identifying, use it;
- # otherwise set root as per value in device.map.
- fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
- if [ "x$fs_hint" != x ]; then
- echo "set root='$fs_hint'"
- fi
- if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
- hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
- echo "if [ x$feature_platform_search_hint = xy ]; then"
- echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
- echo "else"
- echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}"
- echo "fi"
- fi
+# # If there's a filesystem UUID that GRUB is capable of identifying, use it;
+# # otherwise set root as per value in device.map.
+# fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
+# if [ "x$fs_hint" != x ]; then
+# echo "set root='$fs_hint'"
+# fi
+# if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+# hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
+# echo "if [ x$feature_platform_search_hint = xy ]; then"
+# echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+# echo "else"
+# echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+# echo "fi"
+# fi
}

grub_get_device_id ()

* grub-install /dev/sda

====== backupディスクにgrubを書き込む ======
* 以下のような状況の場合を説明しています
* mount /dev/sdb3 /backup
* mount /dev/sdb1 /backup/boot
* mount -t proc proc /backup/proc
* mount –bind /dev /backup/dev
* chroot /backup
* grub-install /dev/sdb

====== grub rescueモードでの操作 ======
* ls
* ls (hd0,msdos1)/grub
* set prefix=(hd0,msdos1)/grub
* insmod (hd0,msdos1)/grub/i386-pc/normal.mod
* normal