5

I'm currently having to recompile my wireless driver from source every time I get a new kernel release. Thinking it would be awesomely hackerish to automate this process, I symlinked my Bash build script to /etc/kernel/postinst.d. I've verified that it does, in fact, run when the latest kernel update is installed, but one thing is left as a problem: the driver compiles for the existing running version of the kernel.

For example, if I'm running 3.0.0-14-generic and apt-get dist-upgrade to kernel 3.0.0-15-generic, then it compiles for kernel 3.0.0-14-generic, which doesn't really help me at all.

Is there a way to tell from my kernel postinst script which version of the kernel has been installed so I can pass it to my make call so it can be compiled for the newly installed kernel?

3 Answers 3

2

This is no actual answer to your question, just a pointer to a tool that might be related and helpful:


Do you have dkms installed? (Some information here, the alioth page seems down at the moment.) It's supposed to do just that, if I'm not misled. It requires the appropriate linux-headers package and the module/firmware/something-like-that package to be installed; and it works for all installed linux-image packages. (I can't say anything about a generic module, but it worked fine when I used it with the non-free nvidia module.)

(There're more links here, like the manpage and this linuxjournal.com article which provides a non-Debian-ecosystem-centric explanation of the program.)

4
  • No, I think dkms is the answer.
    – bsd
    Jan 29, 2012 at 17:39
  • 1
    I think so, too (DKMS is it). You have to put it into auto-rebuild mode for the driver in the dkms.conf.
    – Nils
    Jan 29, 2012 at 21:07
  • How can I hook my script into it? There are a couple of different libraries which need to be installed, and both currently live in /opt. Jan 29, 2012 at 21:38
  • In /usr/share/doc/dkms/ there are docs as well as examples. Start by looking through the example dkms.conf files and then ask a followup question if you have any problems
    – bsd
    Jan 30, 2012 at 14:34
1

Although dkms may be the answer, I have an approach for you that may offer a solution that is simpler if you don't want to get involved with that or other complicated solutions.

Since you won't really need this until you do the reboot and begin running the new kernel anyway, why not just run the script just in time (on the next boot)?

You could use something self-contained like this for queueing your command to run on the next boot only, and script that from /etc/kernel/postinst.d.

0

dkms is indeed the answer if you're running a DKMS-enabled distro (like most of the popular ones). If you're running a distribution that doesn't use DKMS or you've spun your own Linux installation, read on.

The problem is that the postinst.d hook is called before the reboot, where uname still returns the old kernel version.

The solution is somewhat hackish but given that the entire matter revolves around a hack to prebuild modules after an upgrade, I'm sure that's ok :)

You just need to enumerate the files in /boot/ (unless you're running some extremely esoteric setup where the kernel is installed somewhere else), sort the contents by mdate, and extract the kernel version from the most recently installed kernel, along these lines:

KVERSION=$(ls -at /boot | sed -n 's/^vmlinuz-//;t p;b;:p;p;q')
# KVERSION will hold some value like 4.19.0-10-arm64

(This assumes kernel is compressed and installed as /boot/vmlinuz-${KVERSION})

2
  • It's not clear whether the wifi driver installer would be able to do the right thing off of simply having the new $KVERSION set.
    – Steven Lu
    Mar 17, 2021 at 22:19
  • @StevenLu this isn’t for use with a binary installer, it’s for use with an installer that builds drivers from source including headers and linking against the kernel based off a path that is derived from the version string. Mar 17, 2021 at 23:17

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.