Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Run a script after every kernel update?

  1. #1

    Default 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.

  2. #2
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,143
    Blog Entries
    2

    Default Re: Run a script after every kernel update?

    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
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  3. #3

    Default Re: Run a script after every kernel update?

    Quote Originally Posted by tsu2 View Post
    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.
    I don't know how to do that unfortunately. Can you give me an example?

  4. #4
    Join Date
    Apr 2016
    Location
    North America
    Posts
    532

    Default Re: Run a script after every kernel update?

    Did you try creating the directory?
    Tumbleweed, Xfce, Firefox, uBlock Origin

  5. #5
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,143
    Blog Entries
    2

    Default Re: Run a script after every kernel update?

    Quote Originally Posted by djatlas View Post
    I don't know how to do that unfortunately. Can you give me an example?

    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.
    Code:
    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
    2. Verify that the file exists with the above text in the file
    Code:
    cat My_MasterUpdate.sh
    3. Make your script executable
    Code:
    sudo chmod +x My_MasterUpdate.sh
    4. Now execute your script
    Code:
    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
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  6. #6

    Default Re: Run a script after every kernel update?

    Quote Originally Posted by ravas View Post
    Did you try creating the directory?
    Obviously I did. And it did not work.

  7. #7

    Default Re: Run a script after every kernel update?

    Quote Originally Posted by tsu2 View Post
    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?
    ...
    I guess this is a way to do it, tho not without shortcomings. Thanks.

  8. #8

    Default Re: Run a script after every kernel update?

    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?

  9. #9
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,143
    Blog Entries
    2

    Default Re: Run a script after every kernel update?

    Quote Originally Posted by djatlas View Post
    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
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  10. #10
    Join Date
    Sep 2012
    Posts
    5,027

    Default Re: Run a script after every kernel update?

    Quote Originally Posted by djatlas View Post
    Does anyone know how the symlinks to the latest vmlinuz and initrd images on /boot are created?
    This is done by kernel postinistall script. See
    Code:
    rpm -q --scripts kernel-default
    Quote Originally Posted by tsu2 View Post
    dracut is the tool that is used to compile the kernel...
    You made my day.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •