On Sat, May 05, 2007 at 03:21:38PM +0200, Marco Gerards wrote:
> > I've looked into this, but I need some advice. What's the simplest way to
> > obtain the corresponding grub_partition_t structure for a partition by
> > knowing
> > its drive name?
>
> You can use grub_partition_iterate. Or open the disk and use
> ->partition. You can read the name of the partitioning scheme. The
> is also done in grub-setup.c, in the code you altered.
Patch attached. Let me know if it's correct (I had my doubts about hardcoding
the the whole partition_map list in grub-probe.c, but then again I think safety
is more important).
--
Robert Millan
My spam trap is [EMAIL PROTECTED] Note: this address is only intended
for spam harvesters. Writing to it will get you added to my black list.
2007-05-07 Robert Millan <[EMAIL PROTECTED]>
* util/i386/pc/grub-probe.c: Add `grub-probe -t ptable' parameter to
determine partition table module.
* util/i386/pc/grub-install.in: Use this feature to decide which
partition module to load, instead of hardcoding pc and gpt.
diff -ur grub2-1.95+20070505.1.old/util/i386/pc/grub-install.in grub2-1.95+20070505.1/util/i386/pc/grub-install.in
--- grub2-1.95+20070505.1.old/util/i386/pc/grub-install.in 2007-05-07 10:53:25.000000000 +0200
+++ grub2-1.95+20070505.1/util/i386/pc/grub-install.in 2007-05-07 10:54:27.000000000 +0200
@@ -216,8 +216,16 @@
exit 1
fi
-# Typically, _chain, pc and gpt are required.
-modules="$modules $fs_module _chain pc gpt"
+# Then the partition table module.
+ptable_module=`$grub_probe --target=ptable --device-map=${device_map} ${grubdir}`
+if test "x$ptable_module" = x -a "x$modules" = x; then
+ echo "Auto-detection of a partition table module failed." 1>&2
+ echo "Please specify the module with the option \`--modules' explicitly." 1>&2
+ exit 1
+fi
+
+# _chain is often useful
+modules="$modules $fs_module $ptable_module _chain"
$grub_mkimage --output=${grubdir}/core.img $modules || exit 1
diff -ur grub2-1.95+20070505.1.old/util/i386/pc/grub-probe.c grub2-1.95+20070505.1/util/i386/pc/grub-probe.c
--- grub2-1.95+20070505.1.old/util/i386/pc/grub-probe.c 2007-05-07 10:53:26.000000000 +0200
+++ grub2-1.95+20070505.1/util/i386/pc/grub-probe.c 2007-05-07 10:55:44.000000000 +0200
@@ -50,6 +50,7 @@
#define PRINT_FS 0
#define PRINT_DRIVE 1
#define PRINT_DEVICE 2
+#define PRINT_PTABLE 3
int print = PRINT_FS;
@@ -123,6 +124,23 @@
if (! dev)
grub_util_error ("%s", grub_errmsg);
+ if (print == PRINT_PTABLE)
+ {
+ if (strcmp (dev->disk->partition->partmap->name, "amiga_partition_map") == 0)
+ printf ("amiga\n");
+ else if (strcmp (dev->disk->partition->partmap->name, "apple_partition_map") == 0)
+ printf ("apple\n");
+ else if (strcmp (dev->disk->partition->partmap->name, "gpt_partition_map") == 0)
+ printf ("gpt\n");
+ else if (strcmp (dev->disk->partition->partmap->name, "pc_partition_map") == 0)
+ printf ("pc\n");
+ else if (strcmp (dev->disk->partition->partmap->name, "sun_partition_map") == 0)
+ printf ("sun\n");
+ else
+ grub_util_error ("Unknown partition table %s", dev->disk->partition->partmap->name);
+ goto end;
+ }
+
fs = grub_fs_probe (dev);
if (! fs)
grub_util_error ("%s", grub_errmsg);
@@ -160,7 +178,8 @@
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) print filesystem module, GRUB drive or system device [default=fs]\n\
+ -t, --target=(fs|drive|device|ptable)\n\
+ print filesystem module, GRUB drive, system device or partition table module [default=fs]\n\
-h, --help display this message and exit\n\
-V, --version print version information and exit\n\
-v, --verbose print verbose messages\n\
@@ -204,6 +223,8 @@
print = PRINT_DRIVE;
else if (!strcmp (optarg, "device"))
print = PRINT_DEVICE;
+ else if (!strcmp (optarg, "ptable"))
+ print = PRINT_PTABLE;
else
usage (1);
break;
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel