On Sun, 21 Jul 2024 12:43:58 +0100 Mike <deb...@norgie.net> wrote: > Hi all, > > I have a TV card in one of my boxen, which requires a kernel module to > be built. I've got that all nicely scripted and so I can kick it off > with relative ease. > > The issue is detecting when it needs to be done. ie after a change in > the running kernel. At the moment, it's detected by the TV guide > running out of data and triggering an Icinga alert, which then causes > me to investigate and rebuild the kernel module. I was hoping for > something a little more automated. I'm envisioning something which > starts on boot checking if the kernel has changed and if so, kicking > off the kernel module rebuild script. > > The question is: how to detect if the kernel has changed. Off the top > of my head I'm thinking: > > 1) lsmod | grep <driver> > > I conceed that doesn't actually indicate the kernel has changed, just > that the kernel module is missing. However, so far, it being missing > has consistent indicated a kernel change and rebuilding the driver on > a false positive isn't really an issue > > 2) last | grep "system boot" | head -n 2; then diff the values > > Probably a bit of a faff to extract the necessary information and > probably not wholey robust either. > > I thought that I'd just run it past the hive mind and see if anyone > has any better ideas? >
These may help: I always get a notification of a new kernel and therefore necessary reboot during an apt upgrade. needrestart -k can be parsed to detect a newer kernel available, though obviously only until the next reboot. When apt installs a new kernel, it will typically not remove the current oldest. apt autoremove will remove all but the current and last kernels, so when it finds a kernel which can be removed, a new one will have been installed since its last invocation. -- Joe