使用 dkms 构建内核模块

Building kernel module using dkms

我无法让 dkms 在 Centos 7 上工作。我一直在尝试更改 dkms.conf 中的内容,但没有任何进展。 内核升级触发 dkms(同样无效)。我的最小非工作示例是 dkms build。有什么建议吗?

dkms.conf:

root@localhost ~# cat /usr/src/cs2-3.2.5/dkms.conf
MAKE="make -C src/ KERNELDIR=/lib/modules/${kernelver}/source"
CLEAN="make -C src/ clean"
BUILT_MODULE_NAME=cs2
BUILT_MODULE_LOCATION=src
DEST_MODULE_LOCATION=/extra
PACKAGE_NAME=cs2
PACKAGE_VERSION=3.2.5
#REMAKE_INITRD=yes
AUTOINSTALL=yes

正在dkms中注册模块:

root@localhost ~# dkms add -m cs2 -v 3.2.5

Creating symlink /var/lib/dkms/cs2/3.2.5/source ->
                 /usr/src/cs2-3.2.5

DKMS: add completed.

使用 dkms 构建模块不起作用:

root@localhost ~# dkms build -m cs2 -v 3.2.5 --verbose

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
make -C src/ clean
make: Entering directory `/var/lib/dkms/cs2/3.2.5/build/src'
rm -f cs2.o cs2.mod.?
rm -f .cs2.ko.cmd .cs2.mod.o.cmd .cs2.o.cmd
rm -rf .tmp_versions Module.symvers modules.order
make: Leaving directory `/var/lib/dkms/cs2/3.2.5/build/src'

{ make -j4 KERNELRELEASE=3.10.0-1127.el7.x86_64 -C src/ KERNELDIR=/lib/modules/3.10.0-1127.el7.x86_64/source; } >> /var/lib/dkms/cs2/3.2.5/build/make.log 2>&1

Error!  Build of cs2.ko failed for: 3.10.0-1127.el7.x86_64 (x86_64)
Consult the make.log in the build directory
/var/lib/dkms/cs2/3.2.5/build/ for more information.

咨询/var/lib/dkms/cs2/3.2.5/build/make.log 帮助不大:

编辑: /var/lib/dkms/cs2/3.2.5/build/make.log 看起来更像是 make install ....

的输出
root@localhost ~# cat /var/lib/dkms/cs2/3.2.5/build/make.log
DKMS make.log for cs2-3.2.5 for kernel 3.10.0-1127.el7.x86_64 (x86_64)
Tue Apr 28 23:29:56 CEST 2020
make: Entering directory `/var/lib/dkms/cs2/3.2.5/build/src'
make -C /lib/modules/3.10.0-1127.el7.x86_64/source SUBDIRS=/var/lib/dkms/cs2/3.2.5/build/src modules_install
make[1]: Entering directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
  DEPMOD  3.10.0-1127.el7.x86_64
make[1]: Leaving directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
make: Leaving directory `/var/lib/dkms/cs2/3.2.5/build/src'

但是,手动调用 make 就可以了:

root@localhost /var/lib/dkms/cs2/3.2.5/build# make -C src/ KERNELDIR=/lib/modules/$(uname -r)/source
make: Entering directory `/var/lib/dkms/cs2/3.2.5/build/src'
make -C /lib/modules/3.10.0-1127.el7.x86_64/source SUBDIRS=/var/lib/dkms/cs2/3.2.5/build/src modules
make[1]: Entering directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
  CC [M]  /var/lib/dkms/cs2/3.2.5/build/src/cs2.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /var/lib/dkms/cs2/3.2.5/build/src/cs2.mod.o
  LD [M]  /var/lib/dkms/cs2/3.2.5/build/src/cs2.ko
make[1]: Leaving directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
make: Leaving directory `/var/lib/dkms/cs2/3.2.5/build/src'

我相信我有所有需要的包:

root@localhost ~# yum list kernel*
...
Installed Packages
kernel.x86_64                3.10.0-1062.9.1.el7    @updates
kernel.x86_64                3.10.0-1127.el7        @base
kernel-devel.x86_64          3.10.0-1127.el7        @base
kernel-headers.x86_64        3.10.0-1127.el7        @base
kernel-tools.x86_64          3.10.0-1127.el7        @base
kernel-tools-libs.x86_64     3.10.0-1127.el7        @base

Makefile 可能存在一些问题,因为 dkms build 使用此 dkms.config:

PACKAGE_VERSION="3.2.5"

PACKAGE_NAME="cs2"
MAKE[0]="make -C ${kernel_source_dir} SUBDIRS=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build/src modules"
CLEAN="make -C ${kernel_source_dir} SUBDIRS=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build/src clean"

BUILT_MODULE_LOCATION[0]=src/
BUILT_MODULE_NAME[0]="cs2"
DEST_MODULE_LOCATION[0]="/extra/"

#REMAKE_INITRD="yes"
#AUTOINSTALL="yes"