Re: [PATCH v5] probe: Support probing for GPT partition UUID with -g
Hi Didier, On Mon, May 13, 2019 at 10:53 PM Didier Spaier wrote: > > Hello, > > On 13/05/2019 22:35, Jacob Kroon wrote: > > Hi Vladimir, > > > > On Mon, May 13, 2019 at 10:11 PM Vladimir 'phcoder' Serbinenko > > wrote: > >> > >> Ideally the option shouldn't be specific to GPT as other partmaps also > >> have stable IDs. I think it's better not to have short option at all > >> > > > > Ok, I have some questions below. > > > >> On Mon, 13 May 2019, 20:33 Jacob Kroon, wrote: > >>> > >>> Linux supports root=PARTUUID= boot argument, so add > >>> support for probing it. Compared to the fs UUID, the partition > >>> UUID does not change when reformatting a partition. > >>> > >>> Signed-off-by: Jacob Kroon > >>> --- > >>> docs/grub.texi | 2 +- > >>> grub-core/commands/probe.c | 34 ++ > >>> 2 files changed, 35 insertions(+), 1 deletion(-) > >>> > >>> Changes since v4: > >>> * Do endianess byte-swapping on the fly when formatting string > >>> > >>> diff --git a/docs/grub.texi b/docs/grub.texi > >>> index 308b25074..d85818744 100644 > >>> --- a/docs/grub.texi > >>> +++ b/docs/grub.texi > >>> @@ -4771,7 +4771,7 @@ a rest. > >>> @node probe > >>> @subsection probe > >>> > >>> -@deffn Command probe [@option{--set} var] > >>> @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label} > >>> device > >>> +@deffn Command probe [@option{--set} var] > >>> @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label}|@option{--part-uuid} > >>> device > >>> Retrieve device information. If option @option{--set} is given, assign > >>> result > >>> to variable @var{var}, otherwise print information on the screen. > >>> @end deffn > >>> diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c > >>> index 95d272287..b26cbe2cc 100644 > >>> --- a/grub-core/commands/probe.c > >>> +++ b/grub-core/commands/probe.c > >>> @@ -24,6 +24,7 @@ > >>> #include > >>> #include > >>> #include > >>> +#include > >>> #include > >>> #include > >>> #include > >>> @@ -45,6 +46,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}, > >>> +{"part-uuid", 'g', 0, N_("Determine GPT partition UUID."), 0, > >>> 0}, > > > > Is "part-uuid" ok ? I guess I should remove "GPT" from the help text ? > > If I may interfere, lsblk names it PARTUUID (actually the case doesn't matter) > so I'd suggest partuuidn withjout a hyphen. > I opted for "--part-uuid" since there already is "--fs-uuid", but I don't have a strong opinion on the matter. > And yes, this field exists also with a 'dos' partition label (or 'msdos" > as parted calls it), not only a 'gpt'. > > I can't say for other partition labels than those two, having only > used these. > > > > I've seen both 0 and -1 being passed as short option, do they both > > mean "no short option", or is there a preference which to use in this > > case ? > > > > /Jacob > > Best, > > Didier ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: grub-mkrescue: Problem with MBR partition table at start of EFI partition
On Sat, May 11, 2019 at 10:39:25PM +0200, Thomas Schmitt wrote: > Hi, > > Florian Pelz wrote: > > I guess this is off-topic and we cannot learn anything about the > > permissibility of mformat -k from Windows? > > Yes. > > The on-topic conclusion so far is that i cowardly propose to zeroize > the MBR partition table in the mformat result before populating it > by mcopy. > (Code snippets from SYS_AREA_SPARC around line 855 could be transplanted > and adapted to zeroize bytes 446 to 509 of efiimgfat.) > > Exploring the other differences between mformat with and without -k is > probably useless, because the big truck makes its own lane anyway. The thread is long and I am a bit lost. So, may I ask you to write a summary of your findings, what works and what does not and how the issue should be fixed and why this fix should land in the upcoming release. Daniel ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v5] probe: Support probing for GPT partition UUID with -g
Hello, On 13/05/2019 22:35, Jacob Kroon wrote: > Hi Vladimir, > > On Mon, May 13, 2019 at 10:11 PM Vladimir 'phcoder' Serbinenko > wrote: >> >> Ideally the option shouldn't be specific to GPT as other partmaps also have >> stable IDs. I think it's better not to have short option at all >> > > Ok, I have some questions below. > >> On Mon, 13 May 2019, 20:33 Jacob Kroon, wrote: >>> >>> Linux supports root=PARTUUID= boot argument, so add >>> support for probing it. Compared to the fs UUID, the partition >>> UUID does not change when reformatting a partition. >>> >>> Signed-off-by: Jacob Kroon >>> --- >>> docs/grub.texi | 2 +- >>> grub-core/commands/probe.c | 34 ++ >>> 2 files changed, 35 insertions(+), 1 deletion(-) >>> >>> Changes since v4: >>> * Do endianess byte-swapping on the fly when formatting string >>> >>> diff --git a/docs/grub.texi b/docs/grub.texi >>> index 308b25074..d85818744 100644 >>> --- a/docs/grub.texi >>> +++ b/docs/grub.texi >>> @@ -4771,7 +4771,7 @@ a rest. >>> @node probe >>> @subsection probe >>> >>> -@deffn Command probe [@option{--set} var] >>> @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label} >>> device >>> +@deffn Command probe [@option{--set} var] >>> @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label}|@option{--part-uuid} >>> device >>> Retrieve device information. If option @option{--set} is given, assign >>> result >>> to variable @var{var}, otherwise print information on the screen. >>> @end deffn >>> diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c >>> index 95d272287..b26cbe2cc 100644 >>> --- a/grub-core/commands/probe.c >>> +++ b/grub-core/commands/probe.c >>> @@ -24,6 +24,7 @@ >>> #include >>> #include >>> #include >>> +#include >>> #include >>> #include >>> #include >>> @@ -45,6 +46,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}, >>> +{"part-uuid", 'g', 0, N_("Determine GPT partition UUID."), 0, 0}, > > Is "part-uuid" ok ? I guess I should remove "GPT" from the help text ? If I may interfere, lsblk names it PARTUUID (actually the case doesn't matter) so I'd suggest partuuidn withjout a hyphen. And yes, this field exists also with a 'dos' partition label (or 'msdos" as parted calls it), not only a 'gpt'. I can't say for other partition labels than those two, having only used these. > I've seen both 0 and -1 being passed as short option, do they both > mean "no short option", or is there a preference which to use in this > case ? > > /Jacob Best, Didier ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v5] probe: Support probing for GPT partition UUID with -g
Hi Vladimir, On Mon, May 13, 2019 at 10:11 PM Vladimir 'phcoder' Serbinenko wrote: > > Ideally the option shouldn't be specific to GPT as other partmaps also have > stable IDs. I think it's better not to have short option at all > Ok, I have some questions below. > On Mon, 13 May 2019, 20:33 Jacob Kroon, wrote: >> >> Linux supports root=PARTUUID= boot argument, so add >> support for probing it. Compared to the fs UUID, the partition >> UUID does not change when reformatting a partition. >> >> Signed-off-by: Jacob Kroon >> --- >> docs/grub.texi | 2 +- >> grub-core/commands/probe.c | 34 ++ >> 2 files changed, 35 insertions(+), 1 deletion(-) >> >> Changes since v4: >> * Do endianess byte-swapping on the fly when formatting string >> >> diff --git a/docs/grub.texi b/docs/grub.texi >> index 308b25074..d85818744 100644 >> --- a/docs/grub.texi >> +++ b/docs/grub.texi >> @@ -4771,7 +4771,7 @@ a rest. >> @node probe >> @subsection probe >> >> -@deffn Command probe [@option{--set} var] >> @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label} >> device >> +@deffn Command probe [@option{--set} var] >> @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label}|@option{--part-uuid} >> device >> Retrieve device information. If option @option{--set} is given, assign >> result >> to variable @var{var}, otherwise print information on the screen. >> @end deffn >> diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c >> index 95d272287..b26cbe2cc 100644 >> --- a/grub-core/commands/probe.c >> +++ b/grub-core/commands/probe.c >> @@ -24,6 +24,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include >> @@ -45,6 +46,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}, >> +{"part-uuid", 'g', 0, N_("Determine GPT partition UUID."), 0, 0}, Is "part-uuid" ok ? I guess I should remove "GPT" from the help text ? I've seen both 0 and -1 being passed as short option, do they both mean "no short option", or is there a preference which to use in this case ? /Jacob ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v5] probe: Support probing for GPT partition UUID with -g
Ideally the option shouldn't be specific to GPT as other partmaps also have stable IDs. I think it's better not to have short option at all On Mon, 13 May 2019, 20:33 Jacob Kroon, wrote: > Linux supports root=PARTUUID= boot argument, so add > support for probing it. Compared to the fs UUID, the partition > UUID does not change when reformatting a partition. > > Signed-off-by: Jacob Kroon > --- > docs/grub.texi | 2 +- > grub-core/commands/probe.c | 34 ++ > 2 files changed, 35 insertions(+), 1 deletion(-) > > Changes since v4: > * Do endianess byte-swapping on the fly when formatting string > > diff --git a/docs/grub.texi b/docs/grub.texi > index 308b25074..d85818744 100644 > --- a/docs/grub.texi > +++ b/docs/grub.texi > @@ -4771,7 +4771,7 @@ a rest. > @node probe > @subsection probe > > -@deffn Command probe [@option{--set} var] > @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label} > device > +@deffn Command probe [@option{--set} var] > @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label}|@option{--part-uuid} > device > Retrieve device information. If option @option{--set} is given, assign > result > to variable @var{var}, otherwise print information on the screen. > @end deffn > diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c > index 95d272287..b26cbe2cc 100644 > --- a/grub-core/commands/probe.c > +++ b/grub-core/commands/probe.c > @@ -24,6 +24,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -45,6 +46,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}, > +{"part-uuid", 'g', 0, N_("Determine GPT partition UUID."), 0, 0}, > {0, 0, 0, 0, 0, 0} >}; > > @@ -98,6 +100,38 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, > char **args) >grub_device_close (dev); >return GRUB_ERR_NONE; > } > + if (state[6].set) > +{ > + /* ---- + null terminator */ > + char val[37] = "none"; > + if (dev->disk && dev->disk->partition && > + grub_strcmp(dev->disk->partition->partmap->name, "gpt") == 0) > + { > + struct grub_gpt_partentry entry; > + struct grub_partition *p = dev->disk->partition; > + grub_disk_t disk = grub_disk_open(dev->disk->name); > + if (!disk) > + return grub_errno; > + if (grub_disk_read(disk, p->offset, p->index, sizeof(entry), > )) > + return grub_errno; > + grub_disk_close(disk); > + grub_gpt_part_guid_t *guid = > + grub_snprintf (val, sizeof(val), > + > "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", > +grub_le_to_cpu32 (guid->data1), > +grub_le_to_cpu16 (guid->data2), > +grub_le_to_cpu16 (guid->data3), > +guid->data4[0], guid->data4[1], guid->data4[2], > +guid->data4[3], guid->data4[4], guid->data4[5], > +guid->data4[6], guid->data4[7]); > + } > + if (state[0].set) > + grub_env_set (state[0].arg, val); > + else > + grub_printf ("%s", val); > + grub_device_close (dev); > + return GRUB_ERR_NONE; > +} >fs = grub_fs_probe (dev); >if (! fs) > return grub_errno; > -- > 2.20.1 > > > ___ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel > ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v5] probe: Support probing for GPT partition UUID with -g
On Mon, May 13, 2019 at 03:32:22PM +0200, Jacob Kroon wrote: > Linux supports root=PARTUUID= boot argument, so add > support for probing it. Compared to the fs UUID, the partition > UUID does not change when reformatting a partition. > > Signed-off-by: Jacob Kroon Reviewed-by: Daniel Kiper Daniel ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH requesting feedback] resuce: allow disabling of the grub resuce shell
On Sat, May 11, 2019 at 08:41:20PM +0200, andr...@rammhold.de wrote: > On 13:30 10.05.19, Daniel Kiper wrote: > > I am OK with the idea but the patch requires polishing and maybe splitting > > into two or more. And certainly it is not a release material. > > Thanks for the feedback. Do you have some specific points that you would > like to see addressed? I certainly want the mentioned command line Nothing in particular. Just the patch seems to simple for me... OK, this is an RFC, so, maybe that is a problem. Anyway, please post full version and then I will take a closer look. > switches to opt-in to the feature and write the documentation pieces. Yeah, that is good idea. Daniel ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v2] Optimization calculation expression of FOR_MODULES(var)
As already noticed this is actually on purpose to align pointer on addr_t size. On Thu, 11 Apr 2019, 20:04 Milo Wenxiang Niu, wrote: > From: Milo Wenxiang X Niu > > It's just to remove the common factor: "sizeof (grub_addr_t)" from the > numerator and denominator of the fractional expression of next var. > Let me explain it: > Shortly: > H: struct grub_module_header ; > B: grub_uint32_t ; > A: grub_addr_t; > > Thus, original expression can be expressed as: > var = (H *)((B*)var) + ( offset_exp )) > ++ > (((H*)var)->size + sizeof(A) - 1)sizeof(A) | > offset_exp = - * --- | > sizeof(A) sizeof(B) | > ++ > Remove the common factor "sizeof(A)" of fractional offset_exp, we got the > result. > offset_exp_new = ((H*)->size + sizeof(A) - 1) / sizeof(B) >= ((struct grub_module_header *) var)->size + > sizeof (grub_addr_t) -1) / sizeof (grub_uint32_t) > > so: > var =(H *)(((B*)var) + ( (((H*)var)->size + sizeof(A) - 1) / sizeof(B) )) > That's what I do. > > Still, the new offset express is meaningfull: > *numerator: ((struct grub_module_header *) var)->size + sizeof > (grub_addr_t) -1) > it present the offset value united by byte. > *denominator: sizeof (grub_uint32_t) > it's means "struct grub_module_header" aligned by > sizeof(grub_uint32_t) > --- > include/grub/kernel.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/grub/kernel.h b/include/grub/kernel.h > index 133a37c..b257224 100644 > --- a/include/grub/kernel.h > +++ b/include/grub/kernel.h > @@ -104,7 +104,7 @@ extern grub_addr_t EXPORT_VAR (grub_modbase); >var && (grub_addr_t) var \ > < (grub_modbase + (((struct grub_module_info *) > grub_modbase)->size));\ >var = (struct grub_module_header *) \ > -(((grub_uint32_t *) var) + struct grub_module_header *) > var)->size + sizeof (grub_addr_t) - 1) / sizeof (grub_addr_t)) * (sizeof > (grub_addr_t) / sizeof (grub_uint32_t > +(((grub_uint32_t *) var) + struct grub_module_header *) > var)->size + sizeof (grub_addr_t) - 1) / sizeof (grub_uint32_t > > grub_addr_t grub_modules_get_end (void); > > -- > 1.8.3.1 > > > ___ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel > ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH v5] probe: Support probing for GPT partition UUID with -g
Linux supports root=PARTUUID= boot argument, so add support for probing it. Compared to the fs UUID, the partition UUID does not change when reformatting a partition. Signed-off-by: Jacob Kroon --- docs/grub.texi | 2 +- grub-core/commands/probe.c | 34 ++ 2 files changed, 35 insertions(+), 1 deletion(-) Changes since v4: * Do endianess byte-swapping on the fly when formatting string diff --git a/docs/grub.texi b/docs/grub.texi index 308b25074..d85818744 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -4771,7 +4771,7 @@ a rest. @node probe @subsection probe -@deffn Command probe [@option{--set} var] @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label} device +@deffn Command probe [@option{--set} var] @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label}|@option{--part-uuid} device Retrieve device information. If option @option{--set} is given, assign result to variable @var{var}, otherwise print information on the screen. @end deffn diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c index 95d272287..b26cbe2cc 100644 --- a/grub-core/commands/probe.c +++ b/grub-core/commands/probe.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,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}, +{"part-uuid", 'g', 0, N_("Determine GPT partition UUID."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -98,6 +100,38 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args) grub_device_close (dev); return GRUB_ERR_NONE; } + if (state[6].set) +{ + /* ---- + null terminator */ + char val[37] = "none"; + if (dev->disk && dev->disk->partition && + grub_strcmp(dev->disk->partition->partmap->name, "gpt") == 0) + { + struct grub_gpt_partentry entry; + struct grub_partition *p = dev->disk->partition; + grub_disk_t disk = grub_disk_open(dev->disk->name); + if (!disk) + return grub_errno; + if (grub_disk_read(disk, p->offset, p->index, sizeof(entry), )) + return grub_errno; + grub_disk_close(disk); + grub_gpt_part_guid_t *guid = + grub_snprintf (val, sizeof(val), +"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", +grub_le_to_cpu32 (guid->data1), +grub_le_to_cpu16 (guid->data2), +grub_le_to_cpu16 (guid->data3), +guid->data4[0], guid->data4[1], guid->data4[2], +guid->data4[3], guid->data4[4], guid->data4[5], +guid->data4[6], guid->data4[7]); + } + if (state[0].set) + grub_env_set (state[0].arg, val); + else + grub_printf ("%s", val); + grub_device_close (dev); + return GRUB_ERR_NONE; +} fs = grub_fs_probe (dev); if (! fs) return grub_errno; -- 2.20.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v3] probe: Support probing for GPT partition UUID with -q
On Fri, 10 May 2019, 19:05 Jacob Kroon, wrote: > Linux supports root=PARTUUID= boot argument, so add > support for probing it. Compared to the fs UUID, the partition > UUID does not change when reformatting a partition. > > Signed-off-by: Jacob Kroon > --- > grub-core/commands/probe.c | 35 +++ > 1 file changed, 35 insertions(+) > > Changes since v2: > > * Add a proper commit message > * Handle endianess in the same way as is currently done in >util/grub-probe.c:print_gpt_guid () > > diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c > index 95d272287..24742c181 100644 > --- a/grub-core/commands/probe.c > +++ b/grub-core/commands/probe.c > @@ -24,6 +24,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -45,6 +46,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", 'q', 0, N_("Determine GPT partition uuid."), 0, 0}, > {0, 0, 0, 0, 0, 0} >}; > > @@ -98,6 +100,39 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, > char **args) >grub_device_close (dev); >return GRUB_ERR_NONE; > } > + if (state[6].set) > +{ > + /* ---- + null terminator */ > + char val[37] = "none"; > + if (dev->disk && dev->disk->partition && > + grub_strcmp(dev->disk->partition->partmap->name, "gpt") == 0) > + { > + struct grub_gpt_partentry entry; > + struct grub_partition *p = dev->disk->partition; > + grub_disk_t disk = grub_disk_open(dev->disk->name); > + if (!disk) > + return grub_errno; > + if (grub_disk_read(disk, p->offset, p->index, sizeof(entry), > )) > + return grub_errno; > + grub_disk_close(disk); > + grub_gpt_part_guid_t *guid = > + guid->data1 = grub_le_to_cpu32 (guid->data1); > + guid->data2 = grub_le_to_cpu16 (guid->data2); > + guid->data3 = grub_le_to_cpu16 (guid->data3); > Please don't modify this in place. This can easily create hard to track endian-dependent bug. Instead you can transform them right before printing, in the same statement. Otherwise the patch is fine > + grub_snprintf (val, sizeof(val), > + > "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", > +guid->data1, guid->data2, guid->data3, > guid->data4[0], > +guid->data4[1], guid->data4[2], guid->data4[3], > +guid->data4[4], guid->data4[5], guid->data4[6], > +guid->data4[7]); > + } > + if (state[0].set) > + grub_env_set (state[0].arg, val); > + else > + grub_printf ("%s", val); > + grub_device_close (dev); > + return GRUB_ERR_NONE; > +} >fs = grub_fs_probe (dev); >if (! fs) > return grub_errno; > -- > 2.20.1 > > > ___ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel > ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH v4] probe: Support probing for GPT partition UUID with -g
Linux supports root=PARTUUID= boot argument, so add support for probing it. Compared to the fs UUID, the partition UUID does not change when reformatting a partition. Signed-off-by: Jacob Kroon --- docs/grub.texi | 2 +- grub-core/commands/probe.c | 35 +++ 2 files changed, 36 insertions(+), 1 deletion(-) Changes since v3: * Change from '-q'/'--partuuid' to '-g'/'--part-uuid' * Capitalize 'UUID' in help text * Document new flag --part-uuid in docs/grub.texi diff --git a/docs/grub.texi b/docs/grub.texi index 308b25074..d85818744 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -4771,7 +4771,7 @@ a rest. @node probe @subsection probe -@deffn Command probe [@option{--set} var] @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label} device +@deffn Command probe [@option{--set} var] @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label}|@option{--part-uuid} device Retrieve device information. If option @option{--set} is given, assign result to variable @var{var}, otherwise print information on the screen. @end deffn diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c index 95d272287..3c2412567 100644 --- a/grub-core/commands/probe.c +++ b/grub-core/commands/probe.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,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}, +{"part-uuid", 'g', 0, N_("Determine GPT partition UUID."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -98,6 +100,39 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args) grub_device_close (dev); return GRUB_ERR_NONE; } + if (state[6].set) +{ + /* ---- + null terminator */ + char val[37] = "none"; + if (dev->disk && dev->disk->partition && + grub_strcmp(dev->disk->partition->partmap->name, "gpt") == 0) + { + struct grub_gpt_partentry entry; + struct grub_partition *p = dev->disk->partition; + grub_disk_t disk = grub_disk_open(dev->disk->name); + if (!disk) + return grub_errno; + if (grub_disk_read(disk, p->offset, p->index, sizeof(entry), )) + return grub_errno; + grub_disk_close(disk); + grub_gpt_part_guid_t *guid = + guid->data1 = grub_le_to_cpu32 (guid->data1); + guid->data2 = grub_le_to_cpu16 (guid->data2); + guid->data3 = grub_le_to_cpu16 (guid->data3); + grub_snprintf (val, sizeof(val), +"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", +guid->data1, guid->data2, guid->data3, guid->data4[0], +guid->data4[1], guid->data4[2], guid->data4[3], +guid->data4[4], guid->data4[5], guid->data4[6], +guid->data4[7]); + } + if (state[0].set) + grub_env_set (state[0].arg, val); + else + grub_printf ("%s", val); + grub_device_close (dev); + return GRUB_ERR_NONE; +} fs = grub_fs_probe (dev); if (! fs) return grub_errno; -- 2.20.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v3] probe: Support probing for GPT partition UUID with -q
Hi Paul, On Mon, May 13, 2019 at 1:30 PM Paul Menzel wrote: > > Dear Jacob, > > > On 10.05.19 14:05, Jacob Kroon wrote: > > Linux supports root=PARTUUID= boot argument, so add > > support for probing it. Compared to the fs UUID, the partition > > UUID does not change when reformatting a partition. > > How did you choose the switch name `-q`? Are other tools using this > already, or was it just available? > Honestly I just picked the first character on the top-left of my keyboard :-) I'm not sure which char to pick, but I guess maybe 'g' as in gpt would make more sense ? Open to suggestions... > > Signed-off-by: Jacob Kroon > > --- > > grub-core/commands/probe.c | 35 +++ > > 1 file changed, 35 insertions(+) > > It’d be awesome if you also updated the documentation/manual > `docs/grub.texi`. > Ok, will do. > > Changes since v2: > > > > * Add a proper commit message > > * Handle endianess in the same way as is currently done in > > util/grub-probe.c:print_gpt_guid () > > > > diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c > > index 95d272287..24742c181 100644 > > --- a/grub-core/commands/probe.c > > +++ b/grub-core/commands/probe.c > > @@ -24,6 +24,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -45,6 +46,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", 'q', 0, N_("Determine GPT partition uuid."), 0, 0}, > > UUID is capitalized in the string above. Do it her too for consistency? > Yes, will fix. Thanks for reviewing, Regards Jacob ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v3] probe: Support probing for GPT partition UUID with -q
Dear Jacob, On 10.05.19 14:05, Jacob Kroon wrote: Linux supports root=PARTUUID= boot argument, so add support for probing it. Compared to the fs UUID, the partition UUID does not change when reformatting a partition. How did you choose the switch name `-q`? Are other tools using this already, or was it just available? Signed-off-by: Jacob Kroon --- grub-core/commands/probe.c | 35 +++ 1 file changed, 35 insertions(+) It’d be awesome if you also updated the documentation/manual `docs/grub.texi`. Changes since v2: * Add a proper commit message * Handle endianess in the same way as is currently done in util/grub-probe.c:print_gpt_guid () diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c index 95d272287..24742c181 100644 --- a/grub-core/commands/probe.c +++ b/grub-core/commands/probe.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,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", 'q', 0, N_("Determine GPT partition uuid."), 0, 0}, UUID is capitalized in the string above. Do it her too for consistency? […] Kind regards, Paul ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel