stages/grub2.iso: small refactoring
Small changes to the schema so it better aligns with the need of the stage: move the efi properties to the top-level kernel information is under `kernel` object kernel command line options is an array now Change `linuxefi` to `linux` which should work on RHEL 8 and is the only thing that works on arm64. Small PEP-8 fixes. Signed-off-by: Antonio Murdaca <runcom@linux.com>
This commit is contained in:
parent
dd13ec24fb
commit
fb2786e4dd
1 changed files with 42 additions and 40 deletions
|
|
@ -4,12 +4,14 @@ Create a boot filesystem tree, can be consumed to create
|
||||||
an efiboot.img.
|
an efiboot.img.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import string
|
import string
|
||||||
import osbuild.api
|
import osbuild.api
|
||||||
|
|
||||||
|
|
||||||
SCHEMA_2 = """
|
SCHEMA_2 = """
|
||||||
"options": {
|
"options": {
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
@ -25,35 +27,38 @@ SCHEMA_2 = """
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"kernel": {
|
"kernel": {
|
||||||
"type": "string"
|
"type": "object",
|
||||||
|
"required": ["dir"],
|
||||||
|
"properties": {
|
||||||
|
"dir": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"opts": {
|
||||||
|
"description": "Array of group names for this user",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"isolabel": {
|
"isolabel": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"efi": {
|
"architectures": {
|
||||||
"type": "object",
|
"type": "array",
|
||||||
"additionalProperties": false,
|
"items": {
|
||||||
"required": ["architectures", "vendor"],
|
|
||||||
"properties": {
|
|
||||||
"architectures": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"vendor": {
|
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"kernel_opts": {
|
"vendor": {
|
||||||
"description": "Additional kernel boot options",
|
"type": "string"
|
||||||
"type": "string"
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# The main grub2 configuration file template. Used for UEFI.
|
# The main grub2 configuration file template. Used for UEFI.
|
||||||
GRUB2_EFI_CFG_TEMPLATE = """
|
GRUB2_EFI_CFG_TEMPLATE = """
|
||||||
function load_video {
|
function load_video {
|
||||||
|
|
@ -77,43 +82,40 @@ search --no-floppy --set=root -l '${isolabel}'
|
||||||
|
|
||||||
### BEGIN /etc/grub.d/10_linux ###
|
### BEGIN /etc/grub.d/10_linux ###
|
||||||
menuentry 'Install ${product} ${version}' --class fedora --class gnu-linux --class gnu --class os {
|
menuentry 'Install ${product} ${version}' --class fedora --class gnu-linux --class gnu --class os {
|
||||||
linuxefi ${kernelpath} ${root} quiet
|
linux ${kernelpath} ${root} quiet
|
||||||
initrdefi ${initrdpath}
|
initrd ${initrdpath}
|
||||||
}
|
}
|
||||||
menuentry 'Test this media & install ${product} ${version}' --class fedora --class gnu-linux --class gnu --class os {
|
menuentry 'Test this media & install ${product} ${version}' --class fedora --class gnu-linux --class gnu --class os {
|
||||||
linuxefi ${kernelpath} ${root} rd.live.check quiet
|
linux ${kernelpath} ${root} rd.live.check quiet
|
||||||
initrdefi ${initrdpath}
|
initrd ${initrdpath}
|
||||||
}
|
}
|
||||||
submenu 'Troubleshooting -->' {
|
submenu 'Troubleshooting -->' {
|
||||||
menuentry 'Install ${product} ${version} in basic graphics mode' --class fedora --class gnu-linux --class gnu --class os {
|
menuentry 'Install ${product} ${version} in basic graphics mode' --class fedora --class gnu-linux --class gnu --class os {
|
||||||
linuxefi ${kernelpath} ${root} nomodeset quiet
|
linux ${kernelpath} ${root} nomodeset quiet
|
||||||
initrdefi ${initrdpath}
|
initrd ${initrdpath}
|
||||||
}
|
}
|
||||||
menuentry 'Rescue a ${product} system' --class fedora --class gnu-linux --class gnu --class os {
|
menuentry 'Rescue a ${product} system' --class fedora --class gnu-linux --class gnu --class os {
|
||||||
linuxefi ${kernelpath} ${root} inst.rescue quiet
|
linux ${kernelpath} ${root} inst.rescue quiet
|
||||||
initrdefi ${initrdpath}
|
initrd ${initrdpath}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def main(root, options):
|
def main(root, options):
|
||||||
name = options["product"]["name"]
|
name = options["product"]["name"]
|
||||||
version = options["product"]["version"]
|
version = options["product"]["version"]
|
||||||
isolabel = options["isolabel"]
|
isolabel = options["isolabel"]
|
||||||
efi = options.get("efi")
|
architectures = options["architectures"]
|
||||||
kopts = options.get("kernel_opts")
|
vendor = options["vendor"]
|
||||||
|
kdir = options["kernel"].get("dir", "/images/pxeboot")
|
||||||
# output directories
|
kopts = options["kernel"].get("opts")
|
||||||
imgdir = os.path.join(root, "images")
|
|
||||||
pxedir = os.path.join(imgdir, "pxeboot")
|
|
||||||
|
|
||||||
os.makedirs(imgdir)
|
|
||||||
|
|
||||||
efidir = os.path.join(root, "EFI", "BOOT")
|
efidir = os.path.join(root, "EFI", "BOOT")
|
||||||
os.makedirs(efidir)
|
os.makedirs(efidir)
|
||||||
|
|
||||||
#arch related data
|
# arch related data
|
||||||
for arch in efi["architectures"]:
|
for arch in architectures:
|
||||||
arch = arch.lower()
|
arch = arch.lower()
|
||||||
targets = [
|
targets = [
|
||||||
(f"shim{arch}.efi", f"BOOT{arch}.EFI".upper()),
|
(f"shim{arch}.efi", f"BOOT{arch}.EFI".upper()),
|
||||||
|
|
@ -122,7 +124,7 @@ def main(root, options):
|
||||||
]
|
]
|
||||||
|
|
||||||
for src, dst in targets:
|
for src, dst in targets:
|
||||||
shutil.copy2(os.path.join("/boot/efi/EFI/", efi["vendor"], src),
|
shutil.copy2(os.path.join("/boot/efi/EFI/", vendor, src),
|
||||||
os.path.join(efidir, dst))
|
os.path.join(efidir, dst))
|
||||||
|
|
||||||
# the font
|
# the font
|
||||||
|
|
@ -130,7 +132,6 @@ def main(root, options):
|
||||||
os.makedirs(fontdir, exist_ok=True)
|
os.makedirs(fontdir, exist_ok=True)
|
||||||
shutil.copy2("/usr/share/grub/unicode.pf2", fontdir)
|
shutil.copy2("/usr/share/grub/unicode.pf2", fontdir)
|
||||||
|
|
||||||
kdir = "/" + os.path.relpath(pxedir, start=root)
|
|
||||||
print(f"kernel dir at {kdir}")
|
print(f"kernel dir at {kdir}")
|
||||||
|
|
||||||
tplt = string.Template(GRUB2_EFI_CFG_TEMPLATE)
|
tplt = string.Template(GRUB2_EFI_CFG_TEMPLATE)
|
||||||
|
|
@ -140,16 +141,17 @@ def main(root, options):
|
||||||
"kernelpath": os.path.join(kdir, "vmlinuz"),
|
"kernelpath": os.path.join(kdir, "vmlinuz"),
|
||||||
"initrdpath": os.path.join(kdir, "initrd.img"),
|
"initrdpath": os.path.join(kdir, "initrd.img"),
|
||||||
"isolabel": isolabel,
|
"isolabel": isolabel,
|
||||||
"root": kopts
|
"root": " ".join(kopts)
|
||||||
})
|
})
|
||||||
|
|
||||||
config = os.path.join(efidir, "grub.cfg")
|
config = os.path.join(efidir, "grub.cfg")
|
||||||
with open(config, "w") as cfg:
|
with open(config, "w") as cfg:
|
||||||
cfg.write(data)
|
cfg.write(data)
|
||||||
|
|
||||||
if "IA32" in efi["architectures"]:
|
if "IA32" in architectures:
|
||||||
shutil.copy2(config, os.path.join(efidir, "BOOT.cfg"))
|
shutil.copy2(config, os.path.join(efidir, "BOOT.cfg"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = osbuild.api.arguments()
|
args = osbuild.api.arguments()
|
||||||
ret = main(args["tree"], args["options"])
|
ret = main(args["tree"], args["options"])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue