DKMS policy

Материал из Rosalab Wiki
Перейти к: навигация, поиск
This page contains the guidelines for packaging kernel modules as DKMS packages in ROSA Linux.


All dkms packages should be named dkms-foo, replacing foo with the driver name (not always same as the module name). They have to have:

Group: System/Kernel and hardware
Requires: dkms
Requires(post): dkms
Requires(preun): dkms

The module source files are installed into %{_usrsrc}/%{name}-%{version}-%{release}. A file named dkms.conf that contains directives for dkms is also installed into this directory. Conditional patches (patches that will be applied depending on kernel version) should be installed into the patches/ subdirectory.

The package should not have any other files or requires, as these are not carried into the possible binary-only dkms packages.

DKMS packages should not be required by any other package, to make binary-only DKMS packages possible.

A DKMS package is generally noarch, unless it contains binary blobs or it is a subpackage of a non-noarch package.

RPM scripts

The following scripts should be used in dkms packages to update dkms data:

%post -n dkms-%{name}
dkms add     -m %{name} -v %{version}-%{release} --rpm_safe_upgrade &&
dkms build   -m %{name} -v %{version}-%{release} --rpm_safe_upgrade &&
dkms install -m %{name} -v %{version}-%{release} --rpm_safe_upgrade --force

%preun -n dkms-%{name}
dkms remove  -m %{name} -v %{version}-%{release} --rpm_safe_upgrade --all
  • --rpm_safe-upgrade prevents the uninstallation of the driver in case a package with the same version-release is reinstalled.
  • --force in install prevents dkms from aborting the installation in case DKMS detects that there is already a module installed with the same or higher version in its version tag. Note that not all modules contain the version tag.
  • true prevents the failure of the script, allowing rpm to continue installing/removing the package.

DKMS configuration file


The driver name. Should be the one which is in the package name itself.


Using %release in the package-version forces dkms to rebuild the module after the package is upgraded, even if %version was not modified. This allows patching the module.


The module is automatically built when booting a new kernel.

MAKE[0]="make -C \${kernel_source_dir} M=\\\$(pwd)"
MAKE[0]="make KERNEL_LOCATION=\${kernel_source_dir} KERNVER=\${kernelver}"

MAKE[0] defines the module build command. The first of the above examples can be used if the Makefile is a standard kernel kbuild makefile. DKMS sets $kernel_source_dir to contain the kernel source directory and $kernelver to contain the kernel version. At least $kernel_source_dir has to be used in the MAKE[0] line to allow building modules for other kernels than the running one.

CLEAN="make -C \${kernel_source_dir} M=\\\$(pwd) clean"
CLEAN="make clean"

CLEAN specifies the command that is run after the build to clean the module build tree.


The names of the modules that this dkms package contains.


(optional) The location in the module build tree that these modules are in after the build. If no BUILT_MODULE_LOCATION is set, "." is assumed.


The location inside the kernel module tree that these modules should be installed into. The directories have to already exist to prevent leaving stale directories behind after the module is removed. (TODO: make dkms remove stale directories in order to allow installing into /dkms/%{name}).


(optional) Renames the module to "foo" after the build. This should obviously normally not be done.


(optional) Applies foo.patch when kernel version matches the PATCH_MATCH regexp. Note that cross-version compatible patches should be preferred instead of this. If a patch should be applied unconditionally, it should be done in %prep when building the rpm, as in other packages.

(optional) Run a script at the specified stage. The script should be in the dkms module source dir.

MODULES_CONF="options foo no_foo=1"

(optional) Adds the specified line to /etc/modprobe.conf when installing the module. It will be removed when the dkms package is uninstalled. (TODO: use /etc/modprobe.d).


(optional) Remake initrd after module installation.

This Policy is based on the Mandriva DKMS Packaging Policy.