stages/grub2: redirect cfg as template

Extract the grub.cfg redirect config as GRUB_REDIRECT_TEMPLATE,
meant to be used via python's string.Template class. Document
its intended use and also the template options.
This commit is contained in:
Christian Kellner 2020-05-13 19:20:55 +02:00 committed by David Rheinsberg
parent 06b2c8c99b
commit f19effd70a

View file

@ -156,6 +156,20 @@ blscfg
"""
# The grub2 redirect configuration template. This is used in case of
# hybrid (uefi + legacy) boot. In this case this configuration, which
# is located in the EFI directory, will redirect to the main grub.cfg
# (GRUB_CFG_TEMPLATE).
# The parameters are:
# - $root: specifies the path to the grub2 directory relative to
# to the file-system where the directory is located on
GRUB_REDIRECT_TEMPLATE = """
search --no-floppy --set prefix --file ${root}grub2/grub.cfg
set prefix=($$prefix)${root}grub2
configfile $$prefix/grub.cfg
"""
def fs_spec_decode(spec):
for key in ["uuid", "label"]:
val = spec.get(key)
@ -237,12 +251,16 @@ class GrubConfig:
"""Write a grub config pointing to the other cfg"""
print("hybrid boot support enabled. Writing alias grub config")
# options for the configuration string
root = "/" if self.separate_boot else "/boot/"
# configuration options for the template
config = {
"root": "/" if self.separate_boot else "/boot/"
}
tplt = string.Template(GRUB_REDIRECT_TEMPLATE)
data = tplt.safe_substitute(config)
with open(os.path.join(tree, path), "w") as cfg:
cfg.write(f"search --no-floppy --set prefix --file {root}grub2/grub.cfg\n"
f"set prefix=($prefix){root}grub2\n"
"configfile $prefix/grub.cfg\n")
cfg.write(data)
def main(tree, options):