Run script automatically after kernel upgrade ?

Latest response

We would like to run our site specific scripts after each kernel upgrade. But would like to do it automatically.
Is it possible somehow to do that ?



maybe use uname -r in a test condition to see if it is changed or of a higher numeric value. Just thinking out loud. Perhaps a cron job that tests this once a day for changes?

I would roll a custom rpm package and put your script in the %triggerin section. This also makes it easy to deploy (and update) your site specific scripts across your site.

Very good suggestion. Here's a useful link to learn about %triggerin:

For example:

%triggerin -- kernel
place script here to run whenever package "kernel" is installed

For more information, see here:

Note: the kernel package isn't normally updated in rpm terms, but is normally treated as a new install with an older kernel package typically being uninstalled. This behaviour is described in yum.


this solution seems promising and most sophisticated.
Do you use this solution ?

Hi Philip,

I have implemented your solution and it works like a charm.
Thanks :-)

I have made one assumption: you would like to do this after the host is updated and rebooted?

If I was in this position.. I would likely do the following:
create a "touch file" in the kernel directory of the running kernel at the end of your script

When the host reboots, it runs:



# Exit script if the file matches the running kernel
test -f /lib/modules/`uname -r`/.isupdated && exit 0

# If last test failed, then run the following:  (if successful, create new touch file, else exit 9)
/root/bin/ && touch /lib/modules/`uname -r`/.isupdated || exit 9
exit 0

You could either put that touch command in your update_script, or leave it in the check script (or both, I suppose).

If you don't have the kernel-devel package installed, you could do the same but change the location to somewhere else...

touch /root/.`uname -r`
touch /var/lib/.`uname -r`

I would put it somewhere that would not be impacted by a cleanup script or something.


it should be run after kernel upgrade but before reboot.
The script will update rc* scripts to include 3rd party software (which disappear after kernel upgrade).

I use something similar as the example I had given to update VMware tools on our VMs. If the host comes up and can't find the modules for the kernel that was started, then run the vmware tools installation. It's not "bullet proof" - but it's fairly solid for what we need.

Hi all,

thanks for your suggestions. I was hoping to have something like dkms in Debian or just plain config file (which I wasn't aware of so far ...) where I could set it up.