- The `versionlock` plugin is now enabled by default for dnf with a noop
configuration.
- `Repositories=` is now implemented for zypper.
+- `KernelModulesInclude=` and `KernelModulesInitrdInclude=` now take the
+ special values `host` and `default` to include the host's loaded
+ modules and the default kernel modules defined in `mkosi-initrd`
+ respectively.
+- `KernelModulesIncludeHost=` and `KernelModulesInitrdIncludeHost=` are
+ now deprecated.
## v22
"--extra-tree", f"/usr/lib/modules/{context.kernel_version}:/usr/lib/modules/{context.kernel_version}",
"--extra-tree=/usr/lib/firmware:/usr/lib/firmware",
"--kernel-modules-exclude=.*",
- "--kernel-modules-include-host=yes",
+ "--kernel-modules-include=host",
"--include=mkosi-initrd",
]
from mkosi.context import Context
from mkosi.distributions import Distribution
from mkosi.installer import clean_package_manager_metadata
-from mkosi.kmod import gen_required_kernel_modules, process_kernel_modules
+from mkosi.kmod import gen_required_kernel_modules, loaded_modules, process_kernel_modules
from mkosi.log import ARG_DEBUG, complete_step, die, log_notice, log_step
from mkosi.manifest import Manifest
from mkosi.mounts import finalize_crypto_mounts, finalize_source_mounts, mount_overlay
return [microcode]
+def finalize_kernel_modules_include(context: Context, *, include: Sequence[str], host: bool) -> set[str]:
+ final = {i for i in include if i not in ("default", "host")}
+ if "default" in include:
+ initrd = finalize_default_initrd(context.args, context.config, resources=context.resources)
+ final.update(initrd.kernel_modules_include)
+ if host or "host" in include:
+ final.update(loaded_modules())
+
+ return final
+
+
def build_kernel_modules_initrd(context: Context, kver: str) -> Path:
kmods = context.workspace / f"kernel-modules-{kver}.initrd"
if kmods.exists():
context.root, kmods,
files=gen_required_kernel_modules(
context.root, kver,
- include=context.config.kernel_modules_initrd_include,
+ include=finalize_kernel_modules_include(
+ context,
+ include=context.config.kernel_modules_initrd_include,
+ host=context.config.kernel_modules_initrd_include_host,
+ ),
exclude=context.config.kernel_modules_initrd_exclude,
- host=context.config.kernel_modules_initrd_include_host,
sandbox=context.sandbox,
),
sandbox=context.sandbox,
if not cache:
process_kernel_modules(
context.root, kver,
- include=context.config.kernel_modules_include,
+ include=finalize_kernel_modules_include(
+ context,
+ include=context.config.kernel_modules_include,
+ host=context.config.kernel_modules_include_host,
+ ),
exclude=context.config.kernel_modules_exclude,
- host=context.config.kernel_modules_include_host,
sandbox=context.sandbox,
)
import os
import re
import subprocess
-from collections.abc import Iterator, Sequence
+from collections.abc import Iterable, Iterator
from pathlib import Path
from mkosi.log import complete_step, log_step
return [fr"{line.split()[0]}\.ko" for line in Path("/proc/modules").read_text().splitlines()]
-def filter_kernel_modules(
- root: Path,
- kver: str,
- *,
- include: Sequence[str],
- exclude: Sequence[str],
- host: bool,
-) -> list[Path]:
+def filter_kernel_modules(root: Path, kver: str, *, include: Iterable[str], exclude: Iterable[str]) -> list[Path]:
modulesd = root / "usr/lib/modules" / kver
modules = set(modulesd.rglob("*.ko*"))
- if host:
- include = [*include, *loaded_modules()]
-
keep = set()
if include:
regex = re.compile("|".join(include))
def resolve_module_dependencies(
root: Path,
kver: str,
- modules: Sequence[str],
+ modules: Iterable[str],
*,
sandbox: SandboxProtocol = nosandbox,
) -> tuple[set[Path], set[Path]]:
root: Path,
kver: str,
*,
- include: Sequence[str],
- exclude: Sequence[str],
- host: bool,
+ include: Iterable[str],
+ exclude: Iterable[str],
sandbox: SandboxProtocol = nosandbox,
) -> Iterator[Path]:
modulesd = root / "usr/lib/modules" / kver
# we have to take the slow path to make sure we don't copy firmware into the initrd that is not depended on by any
# kernel modules.
if exclude or (root / "usr/lib/firmware").glob("*"):
- modules = filter_kernel_modules(root, kver, include=include, exclude=exclude, host=host)
+ modules = filter_kernel_modules(root, kver, include=include, exclude=exclude)
names = [module_path_to_name(m) for m in modules]
mods, firmware = resolve_module_dependencies(root, kver, names, sandbox=sandbox)
else:
root: Path,
kver: str,
*,
- include: Sequence[str],
- exclude: Sequence[str],
- host: bool,
+ include: Iterable[str],
+ exclude: Iterable[str],
sandbox: SandboxProtocol = nosandbox,
) -> None:
if not exclude:
return
with complete_step("Applying kernel module filters"):
- required = set(
- gen_required_kernel_modules(root, kver, include=include, exclude=exclude, host=host, sandbox=sandbox)
- )
+ required = set(gen_required_kernel_modules(root, kver, include=include, exclude=exclude, sandbox=sandbox))
for m in sorted((root / "usr/lib/modules" / kver).rglob("*.ko*"), reverse=True):
if m in required:
relative to the `/usr/lib/modules/<kver>/kernel` directory. mkosi checks for a match anywhere in the module
path (e.g. `i915` will match against `drivers/gpu/drm/i915.ko`). All modules that match any of the
specified patterns are included in the image. All module and firmware dependencies of the matched modules
- are included in the image as well. This setting takes priority over `KernelModulesExclude=` and only makes
+ are included in the image as well.
+
+ If the special value `default` is used, the default kernel modules
+ defined in the `mkosi-initrd` configuration are included as well.
+
+ If the special value `host` is used, the currently loaded modules on
+ the host system are included as well.
+
+ This setting takes priority over `KernelModulesExclude=` and only makes
sense when used in combination with it because all kernel modules are included in the image by default.
`KernelModulesExclude=`, `--kernel-modules-exclude=`
`KernelModulesInclude=` except that all modules that match any of the specified patterns are excluded from
the image.
-`KernelModulesIncludeHost=`, `--kernel-modules-include-host=`
-: Takes a boolean. Specifies whether to include the currently loaded
- modules on the host system in the image. This setting takes priority
- over `KernelModulesExclude=` and only makes sense when used in
- combination with it because all kernel modules are included in the
- image by default.
-
`KernelModulesInitrd=`, `--kernel-modules-initrd=`
: Enable/Disable generation of the kernel modules initrd when building a bootable image. Enabled by default.
If enabled, when building a bootable image, for each kernel that we assemble a unified kernel image for we
`KernelModulesInitrdExclude=`, `--kernel-modules-initrd-exclude=`
: Like `KernelModulesExclude=`, but applies to the kernel modules included in the kernel modules initrd.
-`KernelModulesInitrdIncludeHost=`, `--kernel-modules-initrd-include-host=`
-: Like `KernelModulesIncludeHost=`, but applies to the kernel modules included in the kernel modules initrd.
-
`Locale=`, `--locale=`, `LocaleMessages=`, `--locale-messages=`, `Keymap=`, `--keymap=`, `Timezone=`, `--timezone=`, `Hostname=`, `--hostname=`, `RootShell=`, `--root-shell=`
: The settings `Locale=`, `--locale=`, `LocaleMessages=`, `--locale-messages=`,
`Keymap=`, `--keymap=`, `Timezone=`, `--timezone=`, `Hostname=`,