if kmods.exists():
return kmods
- log_step("Building kernel modules initrd")
-
- make_cpio(
- context.root,
- kmods,
- files=gen_required_kernel_modules(
- context,
- kver,
- modules_include=finalize_kernel_modules_include(
+ with complete_step("Building kernel modules initrd"):
+ make_cpio(
+ context.root,
+ kmods,
+ files=gen_required_kernel_modules(
context,
- include=context.config.kernel_modules_initrd_include,
- host=context.config.kernel_modules_initrd_include_host,
+ kver,
+ modules_include=finalize_kernel_modules_include(
+ context,
+ include=context.config.kernel_modules_initrd_include,
+ host=context.config.kernel_modules_initrd_include_host,
+ ),
+ modules_exclude=context.config.kernel_modules_initrd_exclude,
+ firmware_include=context.config.firmware_include,
+ firmware_exclude=context.config.firmware_exclude,
),
- modules_exclude=context.config.kernel_modules_initrd_exclude,
- firmware_include=context.config.firmware_include,
- firmware_exclude=context.config.firmware_exclude,
- ),
- sandbox=context.sandbox,
- )
+ sandbox=context.sandbox,
+ )
- if context.config.distribution.is_apt_distribution():
- # Older Debian and Ubuntu releases do not compress their kernel modules, so we compress the
- # initramfs instead. Note that this is not ideal since the compressed kernel modules will
- # all be decompressed on boot which requires significant memory.
- if context.config.distribution == Distribution.debian and context.config.release in (
- "sid",
- "testing",
- ):
- compression = Compression.none
- else:
- compression = Compression.zstd
+ if context.config.distribution.is_apt_distribution():
+ # Older Debian and Ubuntu releases do not compress their kernel modules, so we compress the
+ # initramfs instead. Note that this is not ideal since the compressed kernel modules will
+ # all be decompressed on boot which requires significant memory.
+ if context.config.distribution == Distribution.debian and context.config.release in (
+ "sid",
+ "testing",
+ ):
+ compression = Compression.none
+ else:
+ compression = Compression.zstd
- maybe_compress(context, compression, kmods, kmods)
+ maybe_compress(context, compression, kmods, kmods)
- if ArtifactOutput.kernel_modules_initrd in context.config.split_artifacts:
- shutil.copy(kmods, context.staging / context.config.output_split_kernel_modules_initrd)
+ if ArtifactOutput.kernel_modules_initrd in context.config.split_artifacts:
+ shutil.copy(kmods, context.staging / context.config.output_split_kernel_modules_initrd)
return kmods
from pathlib import Path
from typing import Optional
-from mkosi.log import log_step
+from mkosi.log import complete_step, log_step
from mkosi.run import SandboxProtocol, finalize_passwd_symlinks, nosandbox, run, workdir
from mkosi.sandbox import umask
from mkosi.util import PathString, chdir
def make_tar(src: Path, dst: Path, *, sandbox: SandboxProtocol = nosandbox) -> None:
- log_step(f"Creating tar archive {dst}…")
-
- with dst.open("wb") as f:
- run(
- [
- "tar",
- "--create",
- "--file", "-",
- "--directory", workdir(src, sandbox),
- "--acls",
- "--selinux",
- # --xattrs implies --format=pax
- "--xattrs",
- # PAX format emits additional headers for atime, ctime and mtime
- # that would make the archive non-reproducible.
- "--pax-option=delete=atime,delete=ctime,delete=mtime",
- "--sparse",
- "--force-local",
- *(["--owner=root:0"] if os.getuid() != 0 else []),
- *(["--group=root:0"] if os.getuid() != 0 else []),
- *tar_exclude_apivfs_tmp(),
- ".",
- ],
- stdout=f,
- # Make sure tar uses user/group information from the root directory instead of the host.
- sandbox=sandbox(
- options=[
- "--ro-bind", src, workdir(src, sandbox),
- *finalize_passwd_symlinks(workdir(src, sandbox)),
+ with complete_step(f"Creating tar archive {dst}…"):
+ with dst.open("wb") as f:
+ run(
+ [
+ "tar",
+ "--create",
+ "--file", "-",
+ "--directory", workdir(src, sandbox),
+ "--acls",
+ "--selinux",
+ # --xattrs implies --format=pax
+ "--xattrs",
+ # PAX format emits additional headers for atime, ctime and mtime
+ # that would make the archive non-reproducible.
+ "--pax-option=delete=atime,delete=ctime,delete=mtime",
+ "--sparse",
+ "--force-local",
+ *(["--owner=root:0"] if os.getuid() != 0 else []),
+ *(["--group=root:0"] if os.getuid() != 0 else []),
+ *tar_exclude_apivfs_tmp(),
+ ".",
],
- ),
- ) # fmt: skip
+ stdout=f,
+ # Make sure tar uses user/group information from the root directory instead of the host.
+ sandbox=sandbox(
+ options=[
+ "--ro-bind", src, workdir(src, sandbox),
+ *finalize_passwd_symlinks(workdir(src, sandbox)),
+ ],
+ ),
+ ) # fmt: skip
def can_extract_tar(src: Path) -> bool:
else:
files = sorted(files)
- log_step(f"Creating cpio archive {dst}…")
-
- with dst.open("wb") as f:
- run(
- [
- "cpio",
- "--create",
- "--reproducible",
- "--renumber-inodes",
- "--null",
- "--format=newc",
- "--quiet",
- "--directory", workdir(src, sandbox),
- *(["--owner=0:0"] if os.getuid() != 0 else []),
- ],
- input="\0".join(os.fspath(f) for f in files),
- stdout=f,
- sandbox=sandbox(
- options=[
- "--ro-bind", src, workdir(src, sandbox),
- *finalize_passwd_symlinks(workdir(src, sandbox))
+ with complete_step(f"Creating cpio archive {dst}…"):
+ with dst.open("wb") as f:
+ run(
+ [
+ "cpio",
+ "--create",
+ "--reproducible",
+ "--renumber-inodes",
+ "--null",
+ "--format=newc",
+ "--quiet",
+ "--directory", workdir(src, sandbox),
+ *(["--owner=0:0"] if os.getuid() != 0 else []),
],
- ),
- ) # fmt: skip
+ input="\0".join(os.fspath(f) for f in files),
+ stdout=f,
+ sandbox=sandbox(
+ options=[
+ "--ro-bind", src, workdir(src, sandbox),
+ *finalize_passwd_symlinks(workdir(src, sandbox))
+ ],
+ ),
+ ) # fmt: skip
include: Iterable[str],
exclude: Iterable[str],
) -> set[Path]:
- log_step("Applying firmware include/exclude configuration")
if include:
logging.debug(f"Firmware include directives: {' '.join(include)}")
if exclude:
allmodules = set(modulesd.rglob("*.ko*"))
nametofile = {module_path_to_name(m): m for m in allmodules}
- log_step("Running modinfo to fetch kernel module dependencies")
-
- # We could run modinfo once for each module but that's slow. Luckily we can pass multiple modules to
- # modinfo and it'll process them all in a single go. We get the modinfo for all modules to build two maps
- # that map the path of the module to its module dependencies and its firmware dependencies
- # respectively. Because there's more kernel modules than the max number of accepted CLI arguments, we
- # split the modules list up into chunks.
- info = ""
- for i in range(0, len(nametofile.keys()), 8500):
- chunk = list(nametofile.keys())[i : i + 8500]
- info += modinfo(context, kver, chunk)
+ with complete_step("Running modinfo to fetch kernel module dependencies"):
+ # We could run modinfo once for each module but that's slow. Luckily we can pass multiple modules to
+ # modinfo and it'll process them all in a single go. We get the modinfo for all modules to build
+ # two maps that map the path of the module to its module dependencies and its firmware dependencies
+ # respectively. Because there's more kernel modules than the max number of accepted CLI arguments, we
+ # split the modules list up into chunks.
+ info = ""
+ for i in range(0, len(nametofile.keys()), 8500):
+ chunk = list(nametofile.keys())[i : i + 8500]
+ info += modinfo(context, kver, chunk)
log_step("Calculating required kernel modules and firmware")
firmware = set()
# Include or exclude firmware explicitly configured
- firmware = filter_firmware(context.root, firmware, include=firmware_include, exclude=firmware_exclude)
+ with complete_step("Applying firmware include/exclude configuration"):
+ firmware = filter_firmware(
+ context.root, firmware, include=firmware_include, exclude=firmware_exclude
+ )
# /usr/lib/firmware makes use of symbolic links so we have to make sure the symlinks and their targets
# are all included.
modulesd = Path("usr/lib/modules") / kver
firmwared = Path("usr/lib/firmware")
- with complete_step("Applying kernel module filters"):
- required = set(
- gen_required_kernel_modules(
- context,
- kver,
- modules_include=modules_include,
- modules_exclude=modules_exclude,
- firmware_include=firmware_include,
- firmware_exclude=firmware_exclude,
- )
+ required = set(
+ gen_required_kernel_modules(
+ context,
+ kver,
+ modules_include=modules_include,
+ modules_exclude=modules_exclude,
+ firmware_include=firmware_include,
+ firmware_exclude=firmware_exclude,
)
+ )
+ with complete_step("Applying kernel module filters"):
with chdir(context.root):
modules = sorted(modulesd.rglob("*.ko*"), reverse=True)
firmware = sorted(firmwared.rglob("*"), reverse=True)