grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/1 V3] add --partuuid to probe


From: Steve Kenton
Subject: [PATCH 1/1 V3] add --partuuid to probe
Date: Tue, 21 Feb 2017 17:44:07 +0000

Support both EFI and NT Disk Signature for passing to kernel as 
root=PARTUUID=$val

Signed-off-by: Steve Kenton <address@hidden>
---
V3 revert bogus index change it V2, more style cleanups, skip nested partitions

This boots Ubuntu 16.04 properly, verified my checking /proc/cmdline

However, on an embedded system using Buildroot the system boots but shows this
message and sysfs does not get mounted, udev does not run etc. I thinks it's a
problem with Buildroot/Busybox but wanted to mention it. The system is usable
once sysfs is manually mounted on /sys.

mount: libmount/src/tab_parse.c:706: mnt_table_parse_stream: Assertion 
`fs->refcount == 1' failed.

 grub-core/commands/probe.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c
index cf2793e..fe23ad4 100644
--- a/grub-core/commands/probe.c
+++ b/grub-core/commands/probe.c
@@ -16,6 +16,7 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <stddef.h>
 #include <grub/types.h>
 #include <grub/misc.h>
 #include <grub/mm.h>
@@ -24,6 +25,8 @@
 #include <grub/device.h>
 #include <grub/disk.h>
 #include <grub/partition.h>
+#include <grub/gpt_partition.h>
+#include <grub/i386/pc/boot.h>
 #include <grub/net.h>
 #include <grub/fs.h>
 #include <grub/file.h>
@@ -45,6 +48,7 @@ static const struct grub_arg_option options[] =
     {"fs",             'f', 0, N_("Determine filesystem type."), 0, 0},
     {"fs-uuid",                'u', 0, N_("Determine filesystem UUID."), 0, 0},
     {"label",          'l', 0, N_("Determine filesystem label."), 0, 0},
+    {"partuuid",       'g', 0, N_("Determine partition GUID/UUID."), 0, 0}, /* 
GUID but Linux kernel calls it "PARTUUID" */
     {0, 0, 0, 0, 0, 0}
   };
 
@@ -154,6 +158,59 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char 
**args)
       grub_device_close (dev);
       return GRUB_ERR_NONE;
     }
+  if (state[6].set)
+    {
+      char *partuuid = NULL; /* NULL to silence a spurious GCC warning */
+      /* Nested partitions are not supported for now */
+      /* Non-nested partitions must have dev->disk->partition->parent == NULL" 
*/
+      if (dev->disk && dev->disk->partition && (dev->disk->partition->parent 
== NULL))
+       {
+         grub_partition_t p = dev->disk->partition;
+         if (grub_strcmp (p->partmap->name, "msdos") == 0)
+           {
+             /* little-endian 4-byte NT disk id "GUID" in the MBR */
+             grub_uint8_t diskid[4];
+             dev->disk->partition = p->parent;
+             err = grub_disk_read (dev->disk, 0, 
GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, sizeof diskid, diskid);
+             dev->disk->partition = p;
+             if (err)
+               return grub_errno;
+             partuuid = grub_xasprintf ("%02x%02x%02x%02x-%02x",
+                                        diskid[3], diskid[2], diskid[1], 
diskid[0],
+                                        p->number + 1); /* one based partition 
number */
+           }
+         else if (grub_strcmp (p->partmap->name, "gpt") == 0)
+           {
+             /* little-endian 16-byte GPT partition GUID in partition entry */
+             struct grub_gpt_partentry e;
+             dev->disk->partition = p->parent;
+             err = grub_disk_read (dev->disk, p->offset, p->index, sizeof e, 
&e);
+             dev->disk->partition = p;
+             if (err)
+               return grub_errno;
+             partuuid = grub_xasprintf 
("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+                                        e.guid[3], e.guid[2], e.guid[1], 
e.guid[0],
+                                        e.guid[5], e.guid[4],
+                                        e.guid[7], e.guid[6],
+                                        e.guid[8], e.guid[9],
+                                        e.guid[10], e.guid[11], e.guid[12], 
e.guid[13], e.guid[14], e.guid[15]);
+           }
+         else
+           return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+                              N_("partition map %s does not support partition 
UUIDs"),
+                              dev->disk->partition->partmap->name);
+       }
+      else
+       partuuid = grub_strdup (""); /* a freeable empty string */
+
+      if (state[0].set)
+       grub_env_set (state[0].arg, partuuid);
+      else
+       grub_printf ("%s", partuuid);
+      grub_free (partuuid);
+      grub_device_close (dev);
+      return GRUB_ERR_NONE;
+    }
   grub_device_close (dev);
   return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised target");
 }
-- 
2.9.0.137.gcf4c2cf




reply via email to

[Prev in Thread] Current Thread [Next in Thread]