[Lunar-commits] r14782 - moonbase/trunk/utils/grub/plugin.d

Auke Kok sofar at lunar-linux.org
Tue May 17 10:01:07 UTC 2005


Author: sofar
Date: 2005-05-17 10:01:05 +0000 (Tue, 17 May 2005)
New Revision: 14782

Modified:
   moonbase/trunk/utils/grub/plugin.d/bootloader-grub.plugin
Log:
Heh, fully working grub device autodetection =^D (also works together with the ISO)


Modified: moonbase/trunk/utils/grub/plugin.d/bootloader-grub.plugin
===================================================================
--- moonbase/trunk/utils/grub/plugin.d/bootloader-grub.plugin	2005-05-17 06:58:44 UTC (rev 14781)
+++ moonbase/trunk/utils/grub/plugin.d/bootloader-grub.plugin	2005-05-17 10:01:05 UTC (rev 14782)
@@ -7,17 +7,60 @@
 #############################################################
 #                                                           #
 # Copyright 2005 by Auke Kok under GPLv2                    #
+# Copyright 2005 by Jaime Buffery under GPLv2               #
 #                                                           #
 #############################################################
 
 
-plugin_kernel_updatebootloader_grub() {
+map_device_to_grub() {
+    local LINE DISC DEVICE TARGET REALTARGET
+    debug_msg "map_device_to_grub ($@)"
+    # TODO - make sure partitions count continuously
+    # TODO - check if ide, scsi, md is the correct order
+    # TODO - this code doesn't see dev/md devices !!!
+    for LINE in $(
+        for N in $(ls -d1 /dev/discs/disc*/{disc,part*} 2> /dev/null) ; do
+            echo "$(readlink -f $N | sed -e 's/\/dev\/ide/0/g' \
+            -e 's/\/dev\/scsi/1/g' -e 's/\/dev\/md/2/g' | \
+            sort):$N:$(readlink -f $N)"
+        done); do
+        DEVICE=$(echo $LINE | cut -d: -f1)
+        TARGET=$(echo $LINE | cut -d: -f2)
+        REALTARGET=$(echo $LINE | cut -d: -f3)
+        if echo $DEVICE | grep -q "disc" ; then
+             (( DISC++ ))
+        fi
+        echo "hd$((DISC-1)),$(echo $DEVICE | sed -e 's/.*\///' -e 's/disc/0/' -e 's/part//'):$TARGET:$REALTARGET:"
+    done | grep ":$(readlink -f $1):" | cut -d: -f1
+}
+
+
+plugin_kernel_updatebootloader_grub()
+{(
 	# preferred? - master switch for experienced users
 	if [ -n "$BOOTLOADER" -a "$BOOTLOADER" != "grub" ]; then
 		return 2
 	fi
 	debug_msg "plugin_kernel_updatebootloader_grub ($@)"
 
+    # we need to determine $GRUB_ROOT and $GRUB_BOOT, but ONLY when we are
+	# not being called from the ISO, in which case we use the provided values
+	# this test only checks GRUB_ROOT, because GRUB_BOOT might be empty
+	if [ -z "$GRUB_ROOT" ]; then
+        # determine is BOOT is a separate partition:
+        BOOTPART=$(grep "^/dev/" /etc/mtab | awk '($2 == "/boot"){print $1}')
+        ROOTPART=$(grep "^/dev/" /etc/mtab | awk '($2 == "/"){print $1}')
+        if [ -n "$BOOTPART" ]; then
+            GRUB_BOOT=""
+            GRUB_ROOT="($(map_device_to_grub $BOOTPART))"
+        else
+            GRUB_BOOT="/boot"
+            GRUB_ROOT="($(map_device_to_grub $ROOTPART))"
+        fi
+        debug_msg "grub: Using GRUB_BOOT=\"$GRUB_BOOT\""
+        debug_msg "grub: Using GRUB_ROOT=\"$GRUB_ROOT\""
+	fi
+
 	if ! ( grep -q "$1" /boot/grub/menu.lst && grep -q "$1.old" /boot/grub/menu.lst ) ; then
 		IFS_OLD=$IFS
 		export IFS="
@@ -65,20 +108,14 @@
 		edit_file /boot/grub/menu.lst
 	fi
 
-cat << EOF
-* * * * * * * * * * * * * * * * * * * * * * * *
-*                                             *
-*              W A R N I N G                  *
-*                                             *
-*  Do not forget to install grub to your MBR  *
-*  if you haven't done so before rebooting    *
-*                                             *
-* * * * * * * * * * * * * * * * * * * * * * * *
-EOF
+    message ""
+    message "${MESSAGE_COLOR}Warning: Do not forget to install grub to your MBR${DEFAULT_COLOR}"
+    message "${MESSAGE_COLOR}if you have not done so before rebooting.${DEFAULT_COLOR}"
+	message ""
 
 	# right now we want to have it run all bootloaders?
 	return 2
-}
+)}
 
 
 plugin_register KERNEL_UPDATEBOOTLOADER plugin_kernel_updatebootloader_grub



More information about the Lunar-commits mailing list