GRUB2 config parser behavior for "load_env -f"

Alan Dunn amdunn at google.com
Wed Jan 13 03:51:38 AEDT 2016


Hi Sam,

Thanks for the quick response!  I'll start work on a patch now.

GRUB2's manual discusses how to specify files here:
http://www.gnu.org/software/grub/manual/grub.html#File-name-syntax

The documentation for load_env (
http://www.gnu.org/software/grub/manual/grub.html#load_005fenv ) does not
specifically cite that discussion of how to specify files, but the code for
load_env is here:
http://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/commands/loadenv.c#n163

If you trace open_envblk_file, you'll see that when there is a filename it
just calls grub_file_open on filename, and grub_file_open has behavior as
described in the manual: It looks for a device name in parentheses via
grub_file_get_device_name (
http://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/kern/file.c#n70 ),
selecting the device specified by root if there isn't one (in
grub_device_open,
http://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/kern/device.c#n33 ).
For the filename part outside of parentheses it uses file->fs->open, which,
e.g., for ext2 comes down to grub_fshelp_find_file, which looks for an
absolute path and iteratively looks up path pieces (in
grub_fshelp_find_file_real,
http://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/fs/fshelp.c#n262 ).

Thanks,
- Alan

On Mon, Jan 11, 2016 at 6:13 PM, Sam Mendoza-Jonas <sam at mendozajonas.com>
wrote:

> Hi Alan,
>
> Patches are always welcome! I'm happy to test such a change on my end.
> Do you have a link to the GRUB2 source/docs that mentions this behaviour?
>
> Thanks,
> Sam
>
> On Mon, Jan 11, 2016 at 06:02:18PM -0800, Alan Dunn wrote:
> > Hi,
> >
> > From my reading of the code (in particular,
> >
> http://git.kernel.org/cgit/linux/kernel/git/geoff/petitboot.git/tree/discover/grub2/env.c?id=106276d3d1bfae163828e111d6a8596104fba400#n81
> > ) and experimentation, it looks like the current behavior of Petitboot's
> > GRUB2 config parser for "load_env -f <path>" is to always try and load an
> > environment file at "$prefix/<path>", with $prefix="" if unset.  However,
> > it seems like this is not the current behavior of GRUB2 (at least as of
> > GRUB2 2.02-beta2), which adds nothing to the path (from my reading of the
> > source and experimentation).
> >
> > It looks like GRUB2 accepts only absolute paths, which can be
> > filesystem-prefixed (e.g. "(hd0,gpt1)/boot/grub/grub.cfg"), falling back
> to
> > the device specified by $root for the filesystem if none is specified,
> with
> > $root normally being set based on the value of $prefix.  It looks like
> > Petitboot by default doesn't set root, but it seems like we could at
> least
> > accommodate the important case where the configuration doesn't manually
> set
> > the value of root (by pretending that it points to the filesystem where
> the
> > configuration file is) pretty easily.
> >
> > Would you folks be open to accepting a patch (that I will write) to put
> > Petitboot's behavior more in line with GRUB2 by eliminating the addition
> of
> > "$prefix/" in "load_env -f" and loading paths on the current filesystem
> > (and ensuring that this behavior is properly tested)?
> >
> > Thanks,
> > - Alan
>
> > _______________________________________________
> > Petitboot mailing list
> > Petitboot at lists.ozlabs.org
> > https://lists.ozlabs.org/listinfo/petitboot
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/petitboot/attachments/20160112/e894c634/attachment.html>


More information about the Petitboot mailing list