Skip to content

dkms fails to build modules in chroot with a different kernel, depending on scriptlet #605

Description

@mattaezell

A common use case on clusters is to build an image inside a chroot and/or container. Often times the kernel on the build host differs from what was installed into the image (possibly even cross-architecture with binfmt_misc). In general there are 2 "styles" of RPM scriptlets.

Legacy packages call common.postinst

The common.postinst script has special handling to build for the correct kernel. A redacted example:

  Running scriptlet: package-dkms-version-el9.noarch                407/661 
Loading new package/version DKMS files...
It is likely that 5.14.0-687.5.3.el9_8.x86_64 belongs to a chroot's host
Building for 5.14.0-687.41.1.el9_8.x86_64

This works well, although I believe common.postinst is somewhat deprecated.

Modern packages call dkms add/build/install

This fails to build the modules:

Error! Your kernel headers for kernel 5.14.0-570.113.1.el9_6.x86_64 cannot be found at /lib/modules/5.14.0-570.113.1.el9_6.x86_64/build or /lib/modules/5.14.0-570.113.1.el9_6.x86_64/source.
Please install your distribution's kernel headers package matching 5.14.0-570.113.1.el9_6.x86_64, or use the --kernelsourcedir option to tell DKMS where it's located.
warning: %post(package-version.arch) scriptlet failed, exit status 21

Proposed solution

Bring similar logic from common.postinst into dkms itself. If the headers for the running kernel is not found, and dkms is running in a chroot or container, try to detect the "best" kernel and build for that. Or should that happen unconditionally, even if not in a chroot?

I have a code proposal I can use to create a pull request, but I wanted to get some feedback before submitting it. Thanks!

Activity

  1. scaronni commented on Sep 3, 2026

    @scaronni
    Member

    Hello, a pull request is fine, thank you.

    Just a note on the logic; based on the same logic of not targeting the running kernel, what would then be the difference on a physical host?

    I think at that point, targeting the running kernel would not make sense, probably just targeting all kernels found on an actual system would be the more logic behaviour even on a physical system.

  2. mattaezell commented on Sep 3, 2026

    @mattaezell
    Author

    I like the idea of targeting all the kernels, but that's a little more complicated. There is a autoinstall_all_kernels variable in framework.conf that is not read by dkms, just common.postinst. A quick look at the code showed several places that reference ${kernelver[0]} which implies to me (but would need to look deeper to be sure) that there are still some code paths that don't yet support performing their action on mutiple kernels.

    Let's assume, for now, that multi-kernel actions are out of scope and can be tackled as a future enhancement.

    If I'm on a "normal" host without the headers for my running kernel, and I install a package-dkms rpm, I would expect it to fail and complain loudly. No matter what kernel it chooses it probably won't be loadable in the current boot. But inside a chroot/container, I have no expectation that it's going to try to load the module on the current kernel (we turn off modprobe_on_install, but it's also gated by $kernelver = "$(uname -r)").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions