I have a system that needs patching a file in kernel to work properly. The system is running Ubuntu 14.04.

The patch patches a file in drivers/hwmon.

So after every kernel update I need to download the kernel sources, apply the patch, rebuild the kernel and install it.

Essentially, my question is very similar to Automatically apply module patch and compile kernel when updated? , where using DKMS is suggested. There is a link to general DKMS docs provided, but it doesn't cover the situation of patching a module.

Could you please show me how to configure DKMS to perform the patching automatically? Thanks!


Patching a module does not really change the way. What you basically need is to put all files you need to compile an out-of-tree build of your particular kernel module into a folder /usr/src/<modulename>-</moduleversion>/ and you need to add a configuration file dkms.conf into that folder.

Basically it should look like this:

MAKE="make -C $kernel_source_dir M=\$(pwd)"

For patches, you should have a look at the man page for dkms linked to below, as an excerpt:

          Use  the  PATCH directive array to specify patches which should be applied to
          your source before a build occurs.  All patches are expected  to  be  in  -p1
          format  and  are  applied  with the patch -p1 command.  Each directive should
          specify the filename of the patch to apply, and all patches must  be  located
          in  the  patches  subdirectory  of  your  source  directory  ( /usr/src/<mod‐
          ule>-<module-version>/patches/ ).  If any patch fails  to  apply,  the  build
          will  be  halted  and  the rejections can be inspected in /var/lib/dkms/<mod‐
          ule>/<module-version>/build/.  If a PATCH should only be  applied  condition‐
          ally,  the  PATCH_MATCH[#]  array should be used, and a corresponding regular
          expression should be placed in PATCH_MATCH[#] which will alert dkms  to  only
          use that PATCH[#] if the regular expression matches the kernel which the mod‐
          ule is currently being built for.

          See the above description for PATCH[#] directives. If you only want  a  patch
          applied  in  certain  scenarios,  the PATCH_MATCH array should be utilized by
          giving a regular expression which matches the kernels you intend  the  corre‐
          sponding PATCH[#] to be applied to before building that module.

Then you want to register it with dkms, build and install the module

dkms add     -m hwmon -v
dkms build   -m hwmon -v
dkms install -m hwmon -v

I've used placeholders for module name and version, but you should get the idea. This is all covered in the man page for dkms.

  • Thanks! I'll try it in January and thn mark your answer as accepted. Dec 18 '15 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.