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!
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.postinstscript has special handling to build for the correct kernel. A redacted example:This works well, although I believe
common.postinstis somewhat deprecated.Modern packages call dkms add/build/install
This fails to build the modules:
Proposed solution
Bring similar logic from
common.postinstinto 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!