Run a script after every kernel update?

How can I set a script to be run after every kernel update? Supposedly in other distros you can do it by adding a script to /etc/kernel/postinst.d/. The problem is that path does not exist in openSUSE.

Just to make it clear, what I am trying to accomplish is to have special symlinks to the latest vmlinuz and initrd which reside in a separate boot partition which is shared among multiple distros. Yeah opensuse already create them, but I want them to have a unique suffix, like ‘vmlinuz-tw’. Basically I’m trying to implement this answer in opensuse.

I’ve never heard of such a thing in openSUSE.
And, a quick search of my system doesn’t have any directory with “postinst” in the name.

That said,
It’s trivial to run a general post installation script, just not something specific to a kernel install. I supposed you could insert a few lines of code to detect a kernel installation and then to activate whatever you want…

Just create your own master shell script that first invokes your installation (or an update) and after that command the lines of code you want to run.

TSU

I don’t know how to do that unfortunately. Can you give me an example?

Did you try creating the directory?

Not suggesting anything particularly complicated…

The following is a heredoc which shows how you can create a scriptfile fully populated without creating the file, opening it up in a text editor and typing… Of course, you can skip this heredoc business and do what I just described… Create a file, open it in a text editor and paste the text into the file and save. But isn’t running a heredoc a bit of magic and fun?

  1. Open a console (recommend an enhanced terminal that’s anything but Xterm so it supports the clipboard, for example on KDE use Konsole) Copy the following and paste into the console, then hit <ENTER> on your keyboard to complete the process of creating a file in your current location with the following contents.
cat >> My_MasterUpdate.sh << EOF
# This script is a simple demo how to create a master script to string together multiple commands
# This example illustrates 
# 1. Prepending something that happens before a system update
# 2. A System Update
# 3. Appending something that happens after a system update
#
# Something before running a system update. Let's simply echo something to stdout
#
echo About to update the system...
sleep 1
#
# A System Update
# Note use of dup because this script will run on a Tumbleweed
#
zypper dup
#
# Something that can happen after the system update. Let's simply send something to stdout
#
echo Done!
EOF
  1. Verify that the file exists with the above text in the file
cat My_MasterUpdate.sh
  1. Make your script executable
sudo chmod +x My_MasterUpdate.sh 
  1. Now execute your script
sudo ./My_MasterUpdate.sh

This simple “My_MasterUpdate.sh” script should prepend some text to the screen before your system update runs, then after your update completes should display a “Done!”

This simple demo script doesn’t do much, but you can substitute other commands in place of the text being sent to stdout… a series of commands or you can call a sub-script with its own commands.
And, others should note that I’m not trying to make this script completely unattended, the User will be prompted for any decisions.

HTH,
TSU

Obviously I did. And it did not work.

I guess this is a way to do it, tho not without shortcomings. Thanks.

Does anyone know how the symlinks to the latest vmlinuz and initrd images on /boot are created? I mean, which component, file, etc invokes the creation of those symlinks and updates them?

Not sure if it’s what you’re asking for, but dracut is the tool that is used to compile the kernel… and I’d assume would bring in whatever is needed.

Keep in mind though that the vmlinuz and initrd can be considered the “base” part of today’s modular kernels… Unless something is specifically in that part of the kernel you probably shouldn’t need to recompile it.

With today’s modular kernel, modules are compiled which can be attached to the base part, thereby comprising the full kernel. Modules are all generally pre-compiled and may or may not be enabled on boot. Many are simply latently available, ready for you to manually invoke (and optionally configure to attach on boot).

Also, a good part of the base kernel can be re-configured later without re-compiling… If the functionality is there but simply needs to be re-configured, then that can be done by passing values to /proc either directly or by a bootup script like /etc/sysctl.config

TSU

This is done by kernel postinistall script. See

rpm -q --scripts kernel-default

You made my day.

You’re right. So I guess it’s impossible to add our own custom scripts to be run after kernel update/installation, right?

You can create dummy RPM package with trigger that is called after kernel install/before kernel remove. Note that script won’t receive information about kernel version, only indirectly the information that kernel package is installed/removed.