Ubuntu – Automatically Apply Module Patch and Compile Kernel on Update

compilingkernel-modulesUbuntuupgrade

I've recently applied a one-line patch to drivers/bluetooth/btusb.c in order to enable compatibility with my Bluetooth device. However, whenever I get a kernel upgrade, the patch will be lost until someone backports it (which isn't likely). Is there a way for me to run a script and patch each new kernel upgrade automatically?

DKMS seems like a good solution, but I'm not sure how to set things up. I don't want to recompile the entire Linux kernel every time I get an update, but I'd like to apply that patch to the btusb module, recompile it, and insert it into my kernel on every update. How can I do this using the source obtained from apt-get source linux-source-3.2.0? What files do I need to copy over? The critical make call is make M=drivers/bluetooth modules, but this depends on other kernel utilities to be built first. How can I assemble a DKMS module for this?

Details on how to apply the patch can be found here on Ask Ubuntu.

Best Answer

Yes, you should package up your changes as a DKMS module. Building modules for several installed kernels or automatically rebuilding them on an updated kernel is the main feature of DKMS.

Ubuntu community documention has a nice article on this topic here.

Related Question