On Wed, Jan 09, 2008 at 10:00:37AM +0100, Jan Nieuwenhuizen wrote:
> Robert Millan writes:
> 
> > >     grub-mkimage --output=/boot/grub/core.img --prefix=/boot/grub ext2 
> > > lvm pc gpt biosdisk _chain
> 
> > What happens if you change grub-mkimage parameter order?  Put "lvm" as the
> > last one.
> 
> Yes, that's it.  For the archives, this
> 
>     grub-mkimage --output=/boot/grub/core.img ext2 pc gpt biosdisk lvm
> 
> works for me.  Thanks!

I reworked and cleaned up the patch a bit.  Please, can you test this one?

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
diff -x configure -x config.h.in -ur ../grub2/include/grub/util/getroot.h ./include/grub/util/getroot.h
--- ../grub2/include/grub/util/getroot.h	2007-07-22 01:32:25.000000000 +0200
+++ ./include/grub/util/getroot.h	2008-01-09 12:36:13.000000000 +0100
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2003, 2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2003, 2007, 2008  Free Software Foundation, Inc.
  *
  *  GRUB is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -19,8 +19,16 @@
 #ifndef GRUB_UTIL_GETROOT_HEADER
 #define GRUB_UTIL_GETROOT_HEADER	1
 
+enum grub_dev_abstraction_types {
+  GRUB_DEV_ABSTRACTION_NONE,
+  GRUB_DEV_ABSTRACTION_LVM,
+  GRUB_DEV_ABSTRACTION_RAID,
+  GRUB_DEV_ABSTRACTION_UNKNOWN,
+};
+
 char *grub_guess_root_device (const char *dir);
 char *grub_get_prefix (const char *dir);
-char *grub_util_get_grub_dev (const char *os_dev);
+int grub_util_get_dev_abstraction (const char *os_dev);
+char *grub_util_get_grub_dev (const int dev_abstraction, const char *os_dev);
 
 #endif /* ! GRUB_UTIL_GETROOT_HEADER */
diff -x configure -x config.h.in -ur ../grub2/util/getroot.c ./util/getroot.c
--- ../grub2/util/getroot.c	2007-07-22 01:32:31.000000000 +0200
+++ ./util/getroot.c	2008-01-09 12:36:23.000000000 +0100
@@ -1,7 +1,7 @@
 /* getroot.c - Get root device */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 1999,2000,2001,2002,2003,2006,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2006,2007,2008  Free Software Foundation, Inc.
  *
  *  GRUB is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
 
 #include <grub/util/misc.h>
 #include <grub/util/biosdisk.h>
+#include <grub/util/getroot.h>
 
 static void
 strip_extra_slashes (char *dir)
@@ -239,27 +240,45 @@
   return os_dev;
 }
 
-char *
-grub_util_get_grub_dev (const char *os_dev)
+int
+grub_util_get_dev_abstraction (const char *os_dev)
 {
   /* Check for LVM.  */
   if (!strncmp (os_dev, "/dev/mapper/", 12))
-    {
-      char *grub_dev = xmalloc (strlen (os_dev) - 12 + 1);
-
-      strcpy (grub_dev, os_dev+12);
-
-      return grub_dev;
-    }
+    return GRUB_DEV_ABSTRACTION_LVM;
 
   /* Check for RAID.  */
   if (!strncmp (os_dev, "/dev/md", 7))
+    return GRUB_DEV_ABSTRACTION_RAID;
+
+  /* No abstraction found.  */
+  return GRUB_DEV_ABSTRACTION_NONE;
+}
+
+char *
+grub_util_get_grub_dev (int abstraction, const char *os_dev)
+{
+  char *grub_dev;
+
+  if (abstraction == GRUB_DEV_ABSTRACTION_UNKNOWN)
+    abstraction = grub_util_get_dev_abstraction (os_dev);
+
+  switch (abstraction)
     {
-      const char *p;
-      char *grub_dev = xmalloc (20);
+    case GRUB_DEV_ABSTRACTION_LVM:
+      grub_dev = xmalloc (strlen (os_dev) - 12 + 1);
+
+      strcpy (grub_dev, os_dev + 12);
+
+      break;
+
+    case GRUB_DEV_ABSTRACTION_RAID:
+      grub_dev = xmalloc (20);
 
       if (os_dev[7] == '_' && os_dev[8] == 'd')
 	{
+	  const char *p;
+
 	  /* This a partitionable RAID device of the form /dev/md_dNNpMM. */
 	  int i;
 
@@ -297,17 +316,17 @@
 	}
       else if (os_dev[7] >= '0' && os_dev[7] <= '9')
 	{
-	  p = os_dev + 5;
-	  memcpy (grub_dev, p, 7);
+	  memcpy (grub_dev, os_dev + 5, 7);
 	  grub_dev[7] = '\0';
 	}
       else
 	grub_util_error ("Unknown kind of RAID device `%s'", os_dev);
 
+      break;
 
-      return grub_dev;
+    default:  /* GRUB_DEV_ABSTRACTION_NONE */
+      grub_dev = grub_util_biosdisk_get_grub_dev (os_dev);
     }
 
-  /* If it's not RAID or LVM, it should be a biosdisk.  */
-  return grub_util_biosdisk_get_grub_dev (os_dev);
+  return grub_dev;
 }
diff -x configure -x config.h.in -ur ../grub2/util/grub.d/00_header.in ./util/grub.d/00_header.in
--- ../grub2/util/grub.d/00_header.in	2007-07-22 01:32:31.000000000 +0200
+++ ./util/grub.d/00_header.in	2008-01-09 12:35:33.000000000 +0100
@@ -1,7 +1,7 @@
 #! /bin/sh -e
 
 # update-grub helper script.
-# Copyright (C) 2006,2007  Free Software Foundation, Inc.
+# Copyright (C) 2006,2007,2008  Free Software Foundation, Inc.
 #
 # GRUB is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -24,6 +24,12 @@
 # for convert_system_path_to_grub_path()
 . ${libdir}/grub/update-grub_lib
 
+# Do this as early as possible, since other commands might depend on it.
+# (e.g. the `font' command might need lvm or raid modules)
+for i in ${GRUB_PRELOAD_MODULES} ; do
+  echo "insmod $i"
+done
+
 if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
 if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
 
diff -x configure -x config.h.in -ur ../grub2/util/grub-probe.c ./util/grub-probe.c
--- ../grub2/util/grub-probe.c	2007-07-22 21:17:26.000000000 +0200
+++ ./util/grub-probe.c	2008-01-09 12:36:36.000000000 +0100
@@ -1,7 +1,7 @@
 /* grub-probe.c - probe device information for a given path */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2005,2006,2007 Free Software Foundation, Inc.
+ *  Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc.
  *
  *  GRUB is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -39,10 +39,13 @@
 #define _GNU_SOURCE	1
 #include <getopt.h>
 
-#define PRINT_FS	0
-#define PRINT_DRIVE	1
-#define PRINT_DEVICE	2
-#define PRINT_PARTMAP	3
+enum {
+  PRINT_FS,
+  PRINT_DRIVE,
+  PRINT_DEVICE,
+  PRINT_PARTMAP,
+  PRINT_ABSTRACTION,
+};
 
 int print = PRINT_FS;
 
@@ -74,6 +77,7 @@
 {
   char *device_name;
   char *drive_name = NULL;
+  int abstraction_type;
   grub_device_t dev;
   grub_fs_t fs;
   
@@ -87,7 +91,29 @@
       goto end;
     }
 
-  drive_name = grub_util_get_grub_dev (device_name);
+  abstraction_type = grub_util_get_dev_abstraction (device_name);
+  /* No need to check for errors; lack of abstraction is permissible.  */
+  
+  if (print == PRINT_ABSTRACTION)
+    {
+      char *abstraction_name;
+      switch (abstraction_type)
+	{
+	case GRUB_DEV_ABSTRACTION_NONE:
+	  grub_util_info ("did not find LVM/RAID in %s, assuming raw device", device_name);
+	  goto end;
+	case GRUB_DEV_ABSTRACTION_LVM:
+	  abstraction_name = "lvm";
+	  break;
+	case GRUB_DEV_ABSTRACTION_RAID:
+	  abstraction_name = "raid";
+	  break;
+	}
+      printf ("%s\n", abstraction_name);
+      goto end;
+    }
+
+  drive_name = grub_util_get_grub_dev (abstraction_type, device_name);
   if (! drive_name)
     grub_util_error ("cannot find a GRUB drive for %s.\n", device_name);
   
@@ -159,7 +185,7 @@
 Probe device information for a given path.\n\
 \n\
   -m, --device-map=FILE     use FILE as the device map [default=%s]\n\
-  -t, --target=(fs|drive|device|partmap)\n\
+  -t, --target=(fs|drive|device|partmap|abstraction)\n\
                             print filesystem module, GRUB drive, system device or partition map module [default=fs]\n\
   -h, --help                display this message and exit\n\
   -V, --version             print version information and exit\n\
@@ -206,6 +232,8 @@
 	      print = PRINT_DEVICE;
 	    else if (!strcmp (optarg, "partmap"))
 	      print = PRINT_PARTMAP;
+	    else if (!strcmp (optarg, "abstraction"))
+	      print = PRINT_ABSTRACTION;
 	    else
 	      usage (1);
 	    break;
diff -x configure -x config.h.in -ur ../grub2/util/i386/pc/grub-install.in ./util/i386/pc/grub-install.in
--- ../grub2/util/i386/pc/grub-install.in	2007-12-30 09:52:06.000000000 +0100
+++ ./util/i386/pc/grub-install.in	2008-01-09 12:36:50.000000000 +0100
@@ -1,7 +1,7 @@
 #! /bin/sh
 
 # Install GRUB on your drive.
-# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007  Free Software Foundation, Inc.
+# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008  Free Software Foundation, Inc.
 #
 # GRUB is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -223,8 +223,11 @@
 # filesystem will be accessible).
 partmap_module=`$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`
 
+# Device abstraction module, if any (lvm, raid).
+devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_map} ${grubdir}`
+
 # _chain is often useful
-modules="$modules $fs_module $partmap_module biosdisk _chain"
+modules="$modules $fs_module $partmap_module biosdisk $devabstraction_module _chain"
 
 $grub_mkimage --output=${grubdir}/core.img --prefix=`make_system_path_relative_to_its_root ${grubdir}` $modules || exit 1
 
diff -x configure -x config.h.in -ur ../grub2/util/i386/pc/grub-setup.c ./util/i386/pc/grub-setup.c
--- ../grub2/util/i386/pc/grub-setup.c	2008-01-05 13:20:28.000000000 +0100
+++ ./util/i386/pc/grub-setup.c	2008-01-09 12:37:04.000000000 +0100
@@ -1,7 +1,7 @@
 /* grub-setup.c - make GRUB usable */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008  Free Software Foundation, Inc.
  *
  *  GRUB is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -668,7 +668,7 @@
   if (! dest_dev)
     {
       /* Possibly, the user specified an OS device file.  */
-      dest_dev = grub_util_get_grub_dev (argv[optind]);
+      dest_dev = grub_util_get_grub_dev (GRUB_DEV_ABSTRACTION_UNKNOWN, argv[optind]);
       if (! dest_dev)
 	{
 	  fprintf (stderr, "Invalid device `%s'.\n", argv[optind]);
@@ -694,7 +694,7 @@
     }
   else
     {
-      root_dev = grub_util_get_grub_dev (grub_guess_root_device (dir ? : DEFAULT_DIRECTORY));
+      root_dev = grub_util_get_grub_dev (GRUB_DEV_ABSTRACTION_UNKNOWN, grub_guess_root_device (dir ? : DEFAULT_DIRECTORY));
       if (! root_dev)
 	{
 	  grub_util_info ("guessing the root device failed, because of `%s'",
@@ -734,7 +734,7 @@
 		 dir ? : DEFAULT_DIRECTORY,
 		 boot_file ? : DEFAULT_BOOT_FILE,
 		 core_file ? : DEFAULT_CORE_FILE,
-		 root_dev, grub_util_get_grub_dev (devicelist[i]), 1);
+		 root_dev, grub_util_get_grub_dev (GRUB_DEV_ABSTRACTION_UNKNOWN, devicelist[i]), 1);
 	}
 
       free (raid_prefix);
diff -x configure -x config.h.in -ur ../grub2/util/update-grub.in ./util/update-grub.in
--- ../grub2/util/update-grub.in	2007-12-30 09:52:06.000000000 +0100
+++ ./util/update-grub.in	2008-01-09 12:37:24.000000000 +0100
@@ -1,7 +1,7 @@
 #! /bin/sh -e
 
 # Generate grub.cfg by inspecting /boot contents.
-# Copyright (C) 2006,2007  Free Software Foundation, Inc.
+# Copyright (C) 2006,2007,2008  Free Software Foundation, Inc.
 #
 # GRUB is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -121,7 +121,7 @@
 
 # These are defined in this script, export them here so that user can
 # override them.
-export GRUB_DEVICE GRUB_FS GRUB_DRIVE GRUB_DRIVE_BOOT GRUB_DRIVE_BOOT_GRUB GRUB_FONT_PATH
+export GRUB_DEVICE GRUB_FS GRUB_DRIVE GRUB_DRIVE_BOOT GRUB_DRIVE_BOOT_GRUB GRUB_FONT_PATH GRUB_PRELOAD_MODULES
 
 # These are optional, user-defined variables.
 export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_TERMINAL GRUB_SERIAL_COMMAND
diff -x configure -x config.h.in -ur ../grub2/util/update-grub_lib.in ./util/update-grub_lib.in
--- ../grub2/util/update-grub_lib.in	2007-12-25 10:09:43.000000000 +0100
+++ ./util/update-grub_lib.in	2008-01-09 12:37:42.000000000 +0100
@@ -1,5 +1,5 @@
 # Helper library for update-grub
-# Copyright (C) 2007  Free Software Foundation, Inc.
+# Copyright (C) 2007,2008  Free Software Foundation, Inc.
 #
 # GRUB is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -93,19 +93,14 @@
 
 font_path ()
 {
-  if [ "x${GRUB_FONT_PATH}" = "x" ] ; then : ; else
-    echo "${GRUB_FONT_PATH}"
-    return 0
-  fi
-
   # Prefer system path for space reasons (/boot/grub might be a very small
   # partition in case of OpenFirmware, etc).
   for dir in ${pkgdatadir} /usr/share/grub /boot/grub ; do
     # Prefer complete fonts over incomplete ones.
     for basename in unicode unifont ascii ; do
-      if path=`convert_system_path_to_grub_path ${dir}/${basename}.pff` ; then
-        GRUB_FONT_PATH="${path}"
-        echo "${GRUB_FONT_PATH}"
+      path="${dir}/${basename}.pff"
+      if convert_system_path_to_grub_path ${path} ; then
+        GRUB_PRELOAD_MODULES="`${GRUB_PRELOAD_MODULES} ${grub-probe} -t abstraction ${path}`"
         return 0
       fi
     done
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to