Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules and firmware includes #3312

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions mkosi/kmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from mkosi.log import complete_step, log_step
from mkosi.run import chroot_cmd, run
from mkosi.sandbox import chase
from mkosi.util import chdir, parents_below


Expand Down Expand Up @@ -180,6 +181,15 @@ def gen_required_kernel_modules(
mods = set(modulesd.rglob("*.ko*"))
firmware = set()

# Some firmware dependencies are symbolic links, so the targets for those must be included in the list
# of required firmware files too. Intermediate symlinks are not included, and so links pointing to links
# results in dangling symlinks in the final image.
for fw in firmware.copy():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the call to copy even required here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise this is mutating the set while it is being iterated over, which throws a RuntimeError: Set changed size during iteration.

if (root / fw).is_symlink():
target = Path(chase(os.fspath(root), os.fspath(fw)))
if target.exists():
DaanDeMeyer marked this conversation as resolved.
Show resolved Hide resolved
firmware.add(target.relative_to(root))

yield from sorted(
itertools.chain(
{
Expand Down
8 changes: 4 additions & 4 deletions mkosi/resources/man/mkosi.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -1016,10 +1016,10 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,

`KernelModulesInclude=`, `--kernel-modules-include=`
: Takes a list of regex patterns that specify kernel modules to include in the image. Patterns should be
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.
relative to `/usr/lib/modules/<kver>/<subdir>` paths. 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.

If the special value `default` is used, the default kernel modules
defined in the `mkosi-initrd` configuration are included as well.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_initrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ def test_initrd_size(config: ImageConfig) -> None:
maxsize = 1024**2 * {
Distribution.fedora: 63,
Distribution.debian: 62,
Distribution.ubuntu: 56,
Distribution.ubuntu: 57,
Distribution.arch: 83,
Distribution.opensuse: 64,
}.get(config.distribution, 57)
}.get(config.distribution, 58)

assert (Path(image.output_dir) / "image.initrd").stat().st_size <= maxsize
Loading