stages/fix-bls: support for different prefix

The paths for the kernel and the initrd in the BLS snippets are
meant to be relative to the root of the filesystem they are on.
The current code assumes that kernel and initrd are installed
under '/boot' and that '/boot' is on the root file system and
thus all paths get fixed up to start with '/boot/…'. But the
'/boot' directory can be on a separate partition and thus file
system, and then paths need to be relative to that and should
be fixed up with '/…'. Introduce a new option 'prefix' that
can be used to manually specify the prefix after the fixup,
defaulting to '/boot' for backwards compatibility.
NB: The canonical Boot Loader Specification[1] requires that
a separate partition is used boot related files and it will
be mounted at '/boot' (or '/efi').

[1] https://systemd.io/BOOT_LOADER_SPECIFICATION/
This commit is contained in:
Christian Kellner 2020-01-14 18:26:55 +01:00 committed by Tom Gundersen
parent b3ae34b07e
commit abfc4d6b5a

View file

@ -18,13 +18,14 @@ This stage reads and (re)writes all .conf files in /boot/loader/entries.
STAGE_OPTS = ""
def main(tree, _options):
def main(tree, options):
"""Fix broken paths in /boot/loader/entries.
grub2-mkrelpath uses /proc/self/mountinfo to find the source of the file
system it is installed to. This breaks in a container, because we
bind-mount the tree from the host.
"""
prefix = options.get("prefix", "/boot")
path_re = re.compile(r"(/.*)+/boot")
@ -34,7 +35,7 @@ def main(tree, _options):
with open(name, "w") as f:
for line in entry:
f.write(path_re.sub("/boot", line))
f.write(path_re.sub(prefix, line))
return 0