diff --git a/stages/org.osbuild.xorrisofs b/stages/org.osbuild.xorrisofs index 85fdd6aa..2570be00 100755 --- a/stages/org.osbuild.xorrisofs +++ b/stages/org.osbuild.xorrisofs @@ -6,7 +6,89 @@ import sys import osbuild.api -def main(inputs, output_dir, options): +# Create a grub2 bootable iso +def grub2(inputs, output_dir, options): + tree = inputs["tree"]["path"] + boot = options.get("boot", {}) + filename = options["filename"] + vol_id = options["volid"] + sys_id = options.get("sysid") + efi = options.get("efi") + isolevel = options.get("isolevel") + grub2mbr = options.get("grub2mbr") + + cmd = [ + "/usr/bin/xorrisofs", + "-verbose", + "-rock", + "-joliet", + ] + + if isolevel: + cmd += [ + "-iso-level", str(isolevel) + ] + + cmd += [ + "-V", vol_id + ] + + if sys_id: + cmd += [ + "-sysid", sys_id + ] + + if not os.path.exists(grub2mbr): + raise RuntimeError(f"{grub2mbr} is missing from the buildroot") + cmd += [ + "--grub2-mbr", grub2mbr + ] + + if efi: + efi_path = os.path.join(tree, efi.lstrip("/")) + cmd += [ + "-partition_offset", "16", + "-appended_part_as_gpt", + "-append_partition", "2", "C12A7328-F81F-11D2-BA4B-00A0C93EC93B", efi_path, + ] + + cmd += [ + "-iso_mbr_part_type", "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7" + ] + + if boot: + image = boot["image"] + catalog = boot["catalog"] + cmd += [ + "-b", image, + "-c", catalog, + "--boot-catalog-hide", + "-no-emul-boot", + "-boot-load-size", "4", + "-boot-info-table", + "--grub2-boot-info", + ] + if efi: + cmd += [ + "-eltorito-alt-boot", + "-e", "--interval:appended_partition_2:all::", + ] + + cmd += [ + "-no-emul-boot" + ] + + cmd += [ + '-o', os.path.join(output_dir, filename), + tree + ] + + print(cmd) + subprocess.run(cmd, check=True) + + +# Create an syslinux bootable iso +def syslinux(inputs, output_dir, options): tree = inputs["tree"]["path"] boot = options.get("boot", {}) filename = options["filename"] @@ -46,6 +128,7 @@ def main(inputs, output_dir, options): cmd += [ "-b", image, "-c", catalog, + "--boot-catalog-hide", "-boot-load-size", "4", "-boot-info-table", "-no-emul-boot" @@ -74,6 +157,13 @@ def main(inputs, output_dir, options): subprocess.run(cmd, check=True) +def main(inputs, output_dir, options): + if "grub2mbr" not in options: + return syslinux(inputs, output_dir, options) + + return grub2(inputs, output_dir, options) + + if __name__ == '__main__': args = osbuild.api.arguments() ret = main(args["inputs"], diff --git a/stages/org.osbuild.xorrisofs.meta.json b/stages/org.osbuild.xorrisofs.meta.json index 0f8e803d..d27b10d7 100644 --- a/stages/org.osbuild.xorrisofs.meta.json +++ b/stages/org.osbuild.xorrisofs.meta.json @@ -54,6 +54,10 @@ "efi": { "type": "string" }, + "grub2mbr": { + "type": "string", + "description": "Install the argument (buildroot) as grub2 mbr, and create a grub2 bootable iso" + }, "isohybridmbr": { "type": "string", "description": "Install the argument (buildroot) as ISOLINUX isohybrid MBR"