On 03/28/2010 03:50 PM, Guido Günther wrote:
> Hi,
> I just tried your fix from 1.97+experimental.20091127-1 and it doesn't
> work. I'm currently chainloading from grub-legacy into grub2. I see:
>
> Welcome to GRUB!
>
> Error no such partition.
> Entering rescue mode...
> grub rescue>
>
>   
Reading current code I see that this problem is probably fixed as long
as multipath devices are named as dev/mapper/mpath-*. If it's not the
attached patch should fix it for good independently of device name. I
have no multipath system to test though
> The auto generatd grub.cfg is attched.
>
> /dev/mapper/mpath0 is the multipath device. It has two partitions:
>       /dev/mapper/mpath0-part1 - boot device
>       /dev/mapper/mpath0-part2 - VG mp1 
> The volume group mp1 contains the LV mp1-root - the actual "/"-device.
> This is the standard partitioning when using root on LVM on multipath in
> d-i.
> Cheers,
>  -- Guido
>   
>
>
> _______________________________________________
> Pkg-grub-devel mailing list
> [email protected]
> http://lists.alioth.debian.org/mailman/listinfo/pkg-grub-devel


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko

=== modified file 'grub-core/kern/emu/getroot.c'
--- grub-core/kern/emu/getroot.c	2010-09-30 21:05:56 +0000
+++ grub-core/kern/emu/getroot.c	2010-11-08 15:53:53 +0000
@@ -32,6 +32,10 @@
 #include <stdint.h>
 #include <grub/util/misc.h>
 
+#ifdef HAVE_DEVICE_MAPPER
+# include <libdevmapper.h>
+#endif
+
 #ifdef __GNU__
 #include <hurd.h>
 #include <hurd/lookup.h>
@@ -560,30 +564,66 @@
 }
 
 static int
-grub_util_is_dmraid (const char *os_dev)
+grub_util_is_lvm (const char *os_dev)
 {
-  if (! strncmp (os_dev, "/dev/mapper/nvidia_", 19))
-    return 1;
-  else if (! strncmp (os_dev, "/dev/mapper/isw_", 16))
-    return 1;
-  else if (! strncmp (os_dev, "/dev/mapper/hpt37x_", 19))
-    return 1;
-  else if (! strncmp (os_dev, "/dev/mapper/hpt45x_", 19))
-    return 1;
-  else if (! strncmp (os_dev, "/dev/mapper/via_", 16))
-    return 1;
-  else if (! strncmp (os_dev, "/dev/mapper/lsi_", 16))
-    return 1;
-  else if (! strncmp (os_dev, "/dev/mapper/pdc_", 16))
-    return 1;
-  else if (! strncmp (os_dev, "/dev/mapper/jmicron_", 20))
-    return 1;
-  else if (! strncmp (os_dev, "/dev/mapper/asr_", 16))
-    return 1;
-  else if (! strncmp (os_dev, "/dev/mapper/sil_", 16))
-    return 1;
-
-  return 0;
+  if ((strncmp ("/dev/mapper/", os_dev, 12) != 0))
+    return 0;
+  
+#ifdef HAVE_DEVICE_MAPPER
+  {
+    struct dm_tree *tree;
+    uint32_t maj, min;
+    struct dm_tree_node *node = NULL, *child;
+    void *handle;
+    const char *node_uuid, *mapper_name = NULL, *child_uuid, *child_name;
+    struct stat st;
+
+    if (stat (os_dev, &st) < 0)
+      return 0;
+
+    tree = dm_tree_create ();
+    if (! tree)
+      {
+	grub_printf ("Failed to create tree\n");
+	grub_dprintf ("hostdisk", "dm_tree_create failed\n");
+	return 0;
+      }
+
+    maj = major (st.st_rdev);
+    min = minor (st.st_rdev);
+
+    if (! dm_tree_add_dev (tree, maj, min))
+      {
+	grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n");
+	dm_tree_free (tree);
+	return 0;
+      }
+
+    node = dm_tree_find_node (tree, maj, min);
+    if (! node)
+      {
+	grub_dprintf ("hostdisk", "dm_tree_find_node failed\n");
+	dm_tree_free (tree);
+	return 0;
+      }
+    node_uuid = dm_tree_node_get_uuid (node);
+    if (! node_uuid)
+      {
+	grub_dprintf ("hostdisk", "%s has no DM uuid\n", os_dev);
+	dm_tree_free (tree);
+	return 0;
+      }
+    if (strncmp (node_uuid, "LVM-", 4) != 0)
+      {
+	dm_tree_free (tree);
+	return 0;
+      }
+    dm_tree_free (tree);
+    return 1;
+  }
+#else
+  return 1;
+#endif /* HAVE_DEVICE_MAPPER */
 }
 
 int
@@ -595,9 +635,7 @@
     return GRUB_DEV_ABSTRACTION_NONE;
 
   /* Check for LVM.  */
-  if (!strncmp (os_dev, "/dev/mapper/", 12)
-      && ! grub_util_is_dmraid (os_dev)
-      && strncmp (os_dev, "/dev/mapper/mpath", 17) != 0)
+  if (grub_util_is_lvm (os_dev))
     return GRUB_DEV_ABSTRACTION_LVM;
 
   /* Check for RAID.  */

=== modified file 'grub-core/kern/emu/hostdisk.c'
--- grub-core/kern/emu/hostdisk.c	2010-11-08 15:52:45 +0000
+++ grub-core/kern/emu/hostdisk.c	2010-11-08 15:53:53 +0000
@@ -1035,6 +1035,55 @@
   return ret;
 }
 
+#ifdef HAVE_DEVICE_MAPPER
+static int
+grub_util_get_dm_node_linear_info (const char *dev,
+				   int *maj, int *min)
+{
+  struct dm_task *dmt;
+  void *next = NULL;
+  uint64_t length, start;
+  char *target, *params;
+  const char *node_name;
+  char *ptr;
+  int major, minor;
+
+  dmt = dm_task_create(DM_DEVICE_TABLE);
+  if (!dmt)
+    return 0;
+  
+  if (!dm_task_set_name(dmt, dev))
+    return 0;
+  dm_task_no_open_count(dmt);
+  if (!dm_task_run(dmt))
+    return 0;
+  next = dm_get_next_target(dmt, next, &start, &length,
+			    &target, &params);
+  if (grub_strcmp (target, "linear") != 0)
+    return 0;
+  major = grub_strtoul (params, &ptr, 10);
+  if (grub_errno)
+    {
+      grub_errno = GRUB_ERR_NONE;
+      return 0;
+    }
+  if (*ptr != ':')
+    return 0;
+  ptr++;
+  minor = grub_strtoul (ptr, 0, 10);
+  if (grub_errno)
+    {
+      grub_errno = GRUB_ERR_NONE;
+      return 0;
+    }
+  if (maj)
+    *maj = major;
+  if (min)
+    *min = minor;
+  return 1;
+}
+#endif
+
 static char *
 convert_system_partition_to_system_disk (const char *os_dev, struct stat *st)
 {
@@ -1211,9 +1260,29 @@
 	      node = NULL;
 	      goto devmapper_out;
 	    }
-	  else if (strncmp (node_uuid, "DMRAID-", 7) != 0)
-	    {
+	  if (strncmp (node_uuid, "LVM-", 4) == 0)
+	    {
+	      grub_dprintf ("hostdisk", "%s is an LVM\n", path);
+	      node = NULL;
+	      goto devmapper_out;
+	    }
+	  if (strncmp (node_uuid, "DMRAID-", 7) != 0)
+	    {
+	      int major, minor;
+	      const char *node_name;
 	      grub_dprintf ("hostdisk", "%s is not DM-RAID\n", path);
+
+	      if ((node_name = dm_tree_node_get_name (node))
+		  && grub_util_get_dm_node_linear_info (node_name,
+							&major, &minor))
+		{
+		  if (tree)
+		    dm_tree_free (tree);
+		  free (path);
+		  char *ret = grub_find_device (NULL, (major << 8) | minor);
+		  return ret;
+		}
+
 	      node = NULL;
 	      goto devmapper_out;
 	    }

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to