Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: automatically recompile kernel modules after kernel update

  1. #1

    Default automatically recompile kernel modules after kernel update

    I don't know how many times you have to do something before you decide that enough is enough. I wrote a service to autorecompile kernel modules. It checks in a config file (/etc/modautocompile.conf) which modules to autorecompile and if they are not found in the /lib/modules directory of the current kernel runs the command associated with the module to recompile it. I bet such a service already exists hundred times under different names ... but it's going to save me time and probably explanations (as the ATI fglrx module should be the first of your list!)
    Here's a sample config file (adding modules to that list and comment them out would be a good idea).

    Code:
    # kernel modules to autocompile after kernel update
    # name              command
    vboxdrv             service vboxdrv setup
    fglrx               /usr/bin/fglrx-kernel-build.sh
    And here's the script:
    Code:
    #! /bin/sh
    # Linux kernel module init script
    
    #: Title       : modautocompile
    #: Date Created: Sat Oct 16 06:00:29 PDT 2010
    #: Last Edit   : Sat Oct 16 06:00:29 PDT 2010
    #: Author      : please_try_again
    #: Version     : 1.0
    #: Description : Automatically recompile modules after kernel update
    
    
    # chkconfig: 35 30 70
    # description: recompile modules
    #
    ### BEGIN INIT INFO
    # Provides:       modautocompile 
    # Required-Start: $syslog
    # Required-Stop:
    # Default-Start:  2 3 4 5
    # Default-Stop:   0 1 6
    # Short-Description: recomppile kernel modules
    ### END INIT INFO
    
    # Define the modules you want to autorecompile in the file /etc/modautocompile.conf
    # or in the file specified by the variable CFG below
    CFG=/etc/modautocompile.conf
    
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # /etc/modautocompile.conf example 
    # kernel modules to autocompile after kernel update
    # module	      command
    # vboxdrv         service vboxdrv setup
    # fglrx           /usr/bin/fglrx-kernel-build.sh
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    #
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
    
    start()
    {
    
    # check if $CFG exist
    if [ ! -e $CFG ] ; then
    	echo $CFG not found
    	exit 1
    fi
    
    # parse /etc/modautocompile.conf
    eval `awk 'BEGIN { I=-1 } ; !/^#/ { if ( NF ) { MOD=$1 ; I++ ; $1="" ; sub(/ /, "", $0) ;  printf "MOD[%i]=%s; CMD[%i]=\"%s\";",  I, MOD, I, $0 } }' $CFG`
    
    # exit if no modules defined in /etc/modautocompile.conf
    
    if [ ${#MOD[*]} -eq 0 ] ; then
    	exit 2
    fi
    
    # kernel modules dir
    MDIR=/lib/modules/$(uname -r)
    
    i=0
    while [ $i -lt ${#MOD[*]} ] ; do
    	mod=${MOD[$i]}
    	cmd=${CMD[$i]}
    	unset mof	
    	if [ "x$mod"!="x" -a "x$cmd"!="x" ] ; then
    		mod=${mod}.ko
    		mof=`find $MDIR -name $mod`
    		if [ "$mof" == "" ] ; then
    			echo " - compiling module $mod"
    			$cmd
    		fi
    	fi
    	let i++
    done
    }
    
    case "$1" in
    start)
        start
        ;;
    esac
    
    exit 0
    copy/paste the script into a file, name it modautocompile, put it in /etc/rc.d, chmod to 755, enable with insserv.

  2. #2
    Join Date
    Jun 2008
    Location
    Florida, USA
    Posts
    650

    Default Re: automatically recompile kernel modules after kernel update

    This looks like a great addition, thanks.

    I believe the recompile will run as the machine is rebooting after the kernel upgrade, Correct?

  3. #3

    Default Re: automatically recompile kernel modules after kernel update

    Quote Originally Posted by cmcgrath5035 View Post
    I believe the recompile will run as the machine is rebooting after the kernel upgrade, Correct?
    Correct .

  4. #4
    Join Date
    Mar 2010
    Location
    Austin - Texas
    Posts
    10,500
    Blog Entries
    48

    Smile Re: automatically recompile kernel modules after kernel update

    Even more amazing stuff from please_try_again. Might I ask if your script would work for anyone using the nVidia driver as well? Would you add this to your config file?

    Thank You,
    My Blog: https://forums.opensuse.org/blogs/jdmcdaniel3/

    Software efficiency halves every 18 months, thus compensating for Moore's Law

    Its James again from Austin, Texas

  5. #5

    Default Re: automatically recompile kernel modules after kernel update

    Quote Originally Posted by jdmcdaniel3 View Post
    Even more amazing stuff from please_try_again. Might I ask if your script would work for anyone using the nVidia driver as well? Would you add this to your config file?
    Hi James,
    You can autorecompile any module you need, but
    1. you have to provide the name of the module (without the extension .ko) and this file is expected to be a 'real' file (not a symlink) in the kernel /lib/modules directory.
    2. you have to provide the command or the script used to compile the module.


    I haven't compiled the nvidia module a single time since I installed 11.3. I use nvidia-gfxG02-kmp from the Nvidia repo and the nividia module I have is actually a symlink to the one installed with the first kernel.

    Code:
    /lib/modules/2.6.34.7-0.4-desktop/weak-updates/updates/nvidia.ko -> /lib/modules/2.6.34-12-desktop/updates/nvidia.ko
    /lib/modules/2.6.34-12-desktop/updates/nvidia.ko
    I think I already experienced some Xorg no-start issues whenever this symlink was missing - maybe on Fedora, I don't remember.

    If you need to recompile the nvidia module and the expected result is the file nvidia.ko (not a symlink!) in the /lib/module subdirectory of the updated kernel, yes, it should work, provided you put the correct command or script to compile it in /etc/modautocompile.conf (I don't know that command).

  6. #6
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,941
    Blog Entries
    4

    Default Re: automatically recompile kernel modules after kernel update

    Not trying to put down your contribution (thanks) but isn't this what DKMS is supposed to address?

  7. #7

    Default Re: automatically recompile kernel modules after kernel update

    @ken_yap
    No problem. It was clear to me that I wasn't reinventing the wheel, I was just tired of recompiling and reexplaining, but I was quite sure that something should take care of that (it would have been absurd otherwise). DKMS? Yes, that's what I was looking for. How do we enable/use it?

  8. #8

    Default Re: automatically recompile kernel modules after kernel update

    Ok, I found it in some personnal repos for 11.3. It wasn't that obvious after all! A framework? Does it mean that you have to rewrite each service for each module? Well ... I think for now i'll stick with a single line of awk. But I will pay attention when modules get recompiled automatically, as I think I saw that already happening on other distros (not sure though).

  9. #9
    Join Date
    Jul 2008
    Location
    Athens
    Posts
    224

    Default Re: automatically recompile kernel modules after kernel update

    I really like your script, but how do you know that you have an updated kernel? Or it is simply recompiles the modules at every restart?

  10. #10
    Join Date
    Nov 2010
    Location
    Russia, Khabarovsk
    Posts
    28

    Default Re: automatically recompile kernel modules after kernel update

    tpe, this piece of code checks if the module present - it will be built otherwise:
    mof=`find $MDIR -name $mod`
    if [ "$mof" == "" ] ; then
    please_try_again, thanks! Just the thing I need exactly for vboxdrv and nvidia!

Page 1 of 3 123 LastLast

Tags for this Thread

Posting Permissions

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