DKMS on CentOS 7 - shawfdong/hyades GitHub Wiki

DKMS (Dynamic Kernel Module Support) is a software framework used to generate Linux kernel modules whose sources do not generally reside in the Linux kernel source tree. DKMS enables kernel device drivers to be automatically rebuilt when a new kernel is installed. RPM package for DKMS is available in the EPEL7 repo.

Download the newest version of epel-release for EL7 from https://fedoraproject.org/wiki/EPEL, and install it:

# rpm -ivh epel-release-7-0.2.noarch.rpm

Install DKMS:

# yum -y install dkms

RHEL/CentOS 7 uses systemd to manage services. Here is the service file for DKMS (/usr/lib/systemd/system/dkms.service):

[Unit]
Description=Builds and install new kernel modules through DKMS
Documentation=man:dkms(8)

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/sh -c 'dkms autoinstall --verbose --kernelver $(uname -r)'

[Install]
WantedBy=multi-user.target

Ensure that the kernel-devel package is installed.

The driver installation performed earlier, as described in CUDA on CentOS 7, appears to have installed 2 kernel modules in /lib/modules/$(uname -r)/kernel/drivers/video/: nvidia.ko and nvidia-uvm.ko. The installer has also copied the source code of the modules to /usr/src/nvidia-340.32/; so we don't have to perform those chores ourselves!

Note: In case we do it from scratch: 1. Extract the contents of NVDIA driver installer:

# ./NVIDIA-Linux-x86_64-340.32.run -x

2. Create a directory /usr/src/module-module-version

# mkdir /usr/src/nvidia-340.32

3. Copy the source code for the modules to that directory:

# cp -r NVIDIA-Linux-x86_64-340.32/kernel/* /usr/src/nvidia-340.32/

Even better, NVIDIA provides a dkms.conf file, so we don't have to write one ourselves!

# cat /usr/src/nvidia-340.32/dkms.conf 
PACKAGE_NAME="nvidia"
PACKAGE_VERSION="340.32"
BUILT_MODULE_NAME[0]="$PACKAGE_NAME"
DEST_MODULE_LOCATION[0]="/kernel/drivers/video"
MAKE[0]="make module KERNEL_UNAME=${kernelver}"
CLEAN="make clean"
AUTOINSTALL="yes"
BUILT_MODULE_NAME[1]="${PACKAGE_NAME}-uvm"
BUILT_MODULE_LOCATION[1]="uvm/"
DEST_MODULE_LOCATION[1]="/kernel/drivers/video"
MAKE[0]+="; make -C uvm module KERNEL_UNAME=${kernelver} KBUILD_EXTMOD=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build/uvm"
CLEAN+="; make -C uvm clean"

We do, however, need to add the modules to the DKMS tree:

# dkms add -m nvidia -v 340.32

To build the modules, under DKMS control:

# dkms build -m nvidia -v 340.32

To install nstall the module, again under DKMS control:

# dkms install -m nvidia -v 340.32

But it is unnecessary for us to perform the above 2 steps, since we already have the kernel modules installed. In the future, whenever a new kernel is installed, the kernel modules for NVIDIA card will be automatically rebuilt and installed.

References

⚠️ **GitHub.com Fallback** ⚠️