place boot-related files directly into the ISO root

The debian-cd scripts did this game of placing boot-related files in a
separate directory that was then passed to xorriso to include on the
ISO. Stop doing that and just put the files directly into the ISO root
that is already passed to xorriso.
This commit is contained in:
michael.hudson@canonical.com 2026-02-19 12:56:30 +13:00
parent ff3addb2f8
commit a5cffa8414
No known key found for this signature in database
GPG Key ID: 80E627A0AB757E23
7 changed files with 50 additions and 66 deletions

View File

@ -59,9 +59,6 @@ class AMD64BootConfigurator(UEFIBootConfigurator):
# ## Set up the mkisofs options for UEFI boot.
opts.extend(self.get_uefi_mkisofs_opts())
# ## Add cd-boot-tree to the ISO
opts.append(str(self.boot_tree))
return opts
def extract_files(self) -> None:
@ -75,7 +72,7 @@ class AMD64BootConfigurator(UEFIBootConfigurator):
grub_pc_pkg_dir = self.scratch.joinpath("grub-pc-pkg")
self.download_and_extract_package("grub-pc-bin", grub_pc_pkg_dir)
grub_boot_dir = self.boot_tree.joinpath("boot", "grub", "i386-pc")
grub_boot_dir = self.iso_root.joinpath("boot", "grub", "i386-pc")
grub_boot_dir.mkdir(parents=True, exist_ok=True)
src_grub_dir = grub_pc_pkg_dir.joinpath("usr", "lib", "grub", "i386-pc")
@ -84,12 +81,15 @@ class AMD64BootConfigurator(UEFIBootConfigurator):
shutil.copy(src_grub_dir.joinpath("boot_hybrid.img"), self.scratch)
copy_grub_modules(
src_grub_dir, grub_boot_dir, ["*.mod", "*.lst", "*.o"]
grub_pc_pkg_dir,
self.iso_root,
"i386-pc",
["*.mod", "*.lst", "*.o"],
)
def generate_grub_config(self) -> None:
"""Generate grub.cfg and loopback.cfg for the boot tree."""
boot_grub_dir = self.boot_tree.joinpath("boot", "grub")
boot_grub_dir = self.iso_root.joinpath("boot", "grub")
boot_grub_dir.mkdir(parents=True, exist_ok=True)
grub_cfg = boot_grub_dir.joinpath("grub.cfg")

View File

@ -26,7 +26,6 @@ class ARM64BootConfigurator(UEFIBootConfigurator):
opts.extend(self.get_uefi_mkisofs_opts())
# ARM64-specific: partition cylinder alignment
opts.extend(["-partition_cyl_align", "all"])
opts.append(self.boot_tree)
return opts
def extract_files(self) -> None:
@ -38,7 +37,7 @@ class ARM64BootConfigurator(UEFIBootConfigurator):
"""Generate grub.cfg for ARM64."""
kernel_params = default_kernel_params(self.project)
grub_cfg = self.boot_tree.joinpath("boot", "grub", "grub.cfg")
grub_cfg = self.iso_root.joinpath("boot", "grub", "grub.cfg")
# Write common GRUB header
self.write_grub_header(grub_cfg)

View File

@ -42,7 +42,6 @@ class BaseBootConfigurator(ABC):
def create_dirs(self, workdir):
self.scratch = workdir.joinpath("boot-stuff")
self.scratch.mkdir(exist_ok=True)
self.boot_tree = self.scratch.joinpath("cd-boot-tree")
def download_and_extract_package(
self, pkg_name: str, target_dir: pathlib.Path

View File

@ -7,10 +7,8 @@ from abc import abstractmethod
from .base import BaseBootConfigurator
def copy_grub_common_files_to_boot_tree(
grub_pkg_dir: pathlib.Path, boot_tree: pathlib.Path
) -> None:
fonts_dir = boot_tree.joinpath("boot", "grub", "fonts")
def copy_grub_common_files(grub_pkg_dir: pathlib.Path, iso_root: pathlib.Path) -> None:
fonts_dir = iso_root.joinpath("boot", "grub", "fonts")
fonts_dir.mkdir(parents=True, exist_ok=True)
src = grub_pkg_dir.joinpath("usr", "share", "grub", "unicode.pf2")
@ -19,9 +17,16 @@ def copy_grub_common_files_to_boot_tree(
def copy_grub_modules(
src_dir: pathlib.Path, dest_dir: pathlib.Path, patterns: list[str]
grub_pkg_dir: pathlib.Path,
iso_root: pathlib.Path,
grub_target: str,
patterns: list[str],
) -> None:
"""Copy GRUB module files matching given patterns from src to dest."""
src_dir = grub_pkg_dir.joinpath("usr", "lib", "grub", grub_target)
dest_dir = iso_root.joinpath("boot", "grub", grub_target)
dest_dir.mkdir(parents=True, exist_ok=True)
for pat in patterns:
for file in src_dir.glob(pat):
shutil.copy(file, dest_dir)

View File

@ -4,7 +4,7 @@ import pathlib
import shutil
from .grub import (
copy_grub_common_files_to_boot_tree,
copy_grub_common_files,
copy_grub_modules,
GrubBootConfigurator,
)
@ -16,8 +16,7 @@ class PPC64ELBootConfigurator(GrubBootConfigurator):
def mkisofs_opts(self) -> list[str | pathlib.Path]:
"""Return mkisofs options for PPC64EL."""
# Add cd-boot-tree to the ISO
return [self.boot_tree]
return []
def extract_files(self) -> None:
"""Download and extract bootloader packages for PPC64EL."""
@ -30,14 +29,11 @@ class PPC64ELBootConfigurator(GrubBootConfigurator):
self.download_and_extract_package("grub-ieee1275-bin", grub_pkg_dir)
# Add common files for GRUB to tree
copy_grub_common_files_to_boot_tree(grub_pkg_dir, self.boot_tree)
copy_grub_common_files(grub_pkg_dir, self.iso_root)
# Add IEEE1275 ppc boot files
ppc_dir = self.boot_tree.joinpath("ppc")
ppc_dir.mkdir(parents=True, exist_ok=True)
grub_boot_dir = self.boot_tree.joinpath("boot", "grub", "powerpc-ieee1275")
grub_boot_dir.mkdir(parents=True, exist_ok=True)
ppc_dir = self.iso_root.joinpath("ppc")
ppc_dir.mkdir()
src_grub_dir = grub_pkg_dir.joinpath("usr", "lib", "grub", "powerpc-ieee1275")
@ -49,17 +45,19 @@ class PPC64ELBootConfigurator(GrubBootConfigurator):
# Copy eltorito.elf to boot/grub as powerpc.elf
shutil.copy(
src_grub_dir.joinpath("eltorito.elf"),
self.boot_tree.joinpath("boot", "grub", "powerpc.elf"),
self.iso_root.joinpath("boot", "grub", "powerpc.elf"),
)
# Copy GRUB modules
copy_grub_modules(src_grub_dir, grub_boot_dir, ["*.mod", "*.lst"])
copy_grub_modules(
grub_pkg_dir, self.iso_root, "powerpc-ieee1275", ["*.mod", "*.lst"]
)
def generate_grub_config(self) -> None:
"""Generate grub.cfg for PPC64EL."""
kernel_params = default_kernel_params(self.project)
grub_cfg = self.boot_tree.joinpath("boot", "grub", "grub.cfg")
grub_cfg = self.iso_root.joinpath("boot", "grub", "grub.cfg")
# Write common GRUB header
self.write_grub_header(grub_cfg)

View File

@ -3,16 +3,16 @@
import pathlib
import shutil
from .grub import GrubBootConfigurator, copy_grub_common_files_to_boot_tree
from .grub import GrubBootConfigurator, copy_grub_common_files, copy_grub_modules
def copy_unsigned_monolithic_grub_to_boot_tree(
def copy_unsigned_monolithic_grub(
grub_pkg_dir: pathlib.Path,
efi_suffix: str,
grub_target: str,
boot_tree: pathlib.Path,
iso_root: pathlib.Path,
) -> None:
efi_boot_dir = boot_tree.joinpath("EFI", "boot")
efi_boot_dir = iso_root.joinpath("EFI", "boot")
efi_boot_dir.mkdir(parents=True, exist_ok=True)
shutil.copy(
@ -27,14 +27,7 @@ def copy_unsigned_monolithic_grub_to_boot_tree(
efi_boot_dir.joinpath(f"boot{efi_suffix}.efi"),
)
grub_boot_dir = boot_tree.joinpath("boot", "grub", f"{grub_target}-efi")
grub_boot_dir.mkdir(parents=True, exist_ok=True)
src_grub_dir = grub_pkg_dir.joinpath("usr", "lib", "grub", f"{grub_target}-efi")
for mod_file in src_grub_dir.glob("*.mod"):
shutil.copy(mod_file, grub_boot_dir)
for lst_file in src_grub_dir.glob("*.lst"):
shutil.copy(lst_file, grub_boot_dir)
copy_grub_modules(grub_pkg_dir, iso_root, f"{grub_target}-efi", ["*.mod", "*.lst"])
class RISCV64BootConfigurator(GrubBootConfigurator):
@ -86,11 +79,9 @@ class RISCV64BootConfigurator(GrubBootConfigurator):
self.download_and_extract_package("u-boot-sifive", u_boot_dir)
# Add GRUB to tree
copy_grub_common_files_to_boot_tree(grub_pkg_dir, self.boot_tree)
copy_grub_common_files(grub_pkg_dir, self.iso_root)
copy_unsigned_monolithic_grub_to_boot_tree(
grub_pkg_dir, "riscv64", "riscv64", self.boot_tree
)
copy_unsigned_monolithic_grub(grub_pkg_dir, "riscv64", "riscv64", self.iso_root)
# Extract DTBs to tree
self.logger.log("extracting device tree files")
@ -113,22 +104,14 @@ class RISCV64BootConfigurator(GrubBootConfigurator):
)
# Copy DTBs if they exist
dtb_dir = self.boot_tree.joinpath("dtb")
dtb_dir = self.iso_root.joinpath("dtb")
dtb_dir.mkdir(parents=True, exist_ok=True)
firmware_dir = kernel_layer.joinpath("usr", "lib", "firmware")
device_tree_files = list(firmware_dir.glob("*/device-tree/*"))
if device_tree_files:
for dtb_file in device_tree_files:
if dtb_file.is_file():
shutil.copy(dtb_file, dtb_dir)
# Clean up kernel layer
shutil.rmtree(kernel_layer)
# Copy tree contents to live-media rootfs
self.logger.run(["cp", "-aT", self.boot_tree, self.iso_root], check=True)
for dtb_file in firmware_dir.glob("*/device-tree/*"):
if dtb_file.is_file():
shutil.copy(dtb_file, dtb_dir)
# Create ESP image with GRUB and dtbs
efi_img = self.scratch.joinpath("efi.img")
@ -137,7 +120,7 @@ class RISCV64BootConfigurator(GrubBootConfigurator):
)
# Add EFI files to ESP
efi_dir = self.boot_tree.joinpath("EFI")
efi_dir = self.iso_root.joinpath("EFI")
self.logger.run(["mcopy", "-s", "-i", efi_img, efi_dir, "::/."], check=True)
# Add DTBs to ESP

View File

@ -4,17 +4,17 @@ import pathlib
import shutil
from ..builder import Logger
from .grub import copy_grub_common_files_to_boot_tree, GrubBootConfigurator
from .grub import copy_grub_common_files, GrubBootConfigurator
def copy_signed_shim_grub_to_boot_tree(
def copy_signed_shim_grub(
shim_pkg_dir: pathlib.Path,
grub_pkg_dir: pathlib.Path,
efi_suffix: str,
grub_target: str,
boot_tree: pathlib.Path,
iso_root: pathlib.Path,
) -> None:
efi_boot_dir = boot_tree.joinpath("EFI", "boot")
efi_boot_dir = iso_root.joinpath("EFI", "boot")
efi_boot_dir.mkdir(parents=True, exist_ok=True)
shutil.copy(
@ -38,7 +38,7 @@ def copy_signed_shim_grub_to_boot_tree(
efi_boot_dir.joinpath(f"grub{efi_suffix}.efi"),
)
grub_boot_dir = boot_tree.joinpath("boot", "grub", f"{grub_target}-efi")
grub_boot_dir = iso_root.joinpath("boot", "grub", f"{grub_target}-efi")
grub_boot_dir.mkdir(parents=True, exist_ok=True)
src_grub_dir = grub_pkg_dir.joinpath("usr", "lib", "grub", f"{grub_target}-efi")
@ -49,10 +49,10 @@ def copy_signed_shim_grub_to_boot_tree(
def create_eltorito_esp_image(
logger: Logger, boot_tree: pathlib.Path, target_file: pathlib.Path
logger: Logger, iso_root: pathlib.Path, target_file: pathlib.Path
) -> None:
logger.log("creating El Torito ESP image")
efi_dir = boot_tree.joinpath("EFI")
efi_dir = iso_root.joinpath("EFI")
# Calculate size: du -s --apparent-size --block-size=1024 + 1024
result = logger.run(
@ -106,20 +106,20 @@ class UEFIBootConfigurator(GrubBootConfigurator):
self.download_and_extract_package(pkg, grub_pkg_dir)
# Add common files for GRUB to tree
copy_grub_common_files_to_boot_tree(grub_pkg_dir, self.boot_tree)
copy_grub_common_files(grub_pkg_dir, self.iso_root)
# Add EFI GRUB to tree
copy_signed_shim_grub_to_boot_tree(
copy_signed_shim_grub(
shim_pkg_dir,
grub_pkg_dir,
self.efi_suffix,
self.grub_target,
self.boot_tree,
self.iso_root,
)
# Create ESP image for El-Torito catalog and hybrid boot
create_eltorito_esp_image(
self.logger, self.boot_tree, self.scratch.joinpath("cd-boot-efi.img")
self.logger, self.iso_root, self.scratch.joinpath("cd-boot-efi.img")
)
def write_uefi_menu_entries(self, grub_cfg: pathlib.Path) -> None: