How do I permanently load a kernel module?

38,818

So to gather all the data to an answer, here it is:

  1. After the first compile of the new module, I had the module file r8101.ko in /lib/modules/$(uname -r)/kernel/drivers/net.

  2. I added r8101 to /etc/modules and blacklist r8169 to /etc/modprobe.d/blacklist.conf but I was still booting to the old module.

  3. Then I run sudo update-initramfs -u and then after restart the new module was loaded as expected (thanks to @papukaija comment).

Share:
38,818

Related videos on Youtube

Radu Maris
Author by

Radu Maris

Happily married for more than 12 years, father of an 8y energetic boy. Currently remote working as a System Designer, for a very nice company in southern Germany. I love software development (create things), I think that with software you could build everything, it's just a metter of how hard it is to build it, and I don't like to settle for anything less than high quality software. For me, high quality means: great user experience, fast and most important reliable. I need technical challenges in my day to day life, without them I would be really bored. I'm addicted to science and technology (software, internet, physics, mechanics, astronomy, you name it).

Updated on September 17, 2022

Comments

  • Radu Maris
    Radu Maris almost 2 years

    I have a Compaq Presario CQ-61 320SQ, I am using Ubuntu 10.04 because after update to 10.10 my mouse and touchpad won't work, network won't work, sound won't work ... (I managed to fix most of them after almost a month of googling, but not all, my 2 Desktops have no problem with 10.10) so I decided to switch back to 10.04, where I have a problem:

    My broadband speed is very low beacause of the kernel module r8169, I downloaded the good module r8101 and every time the computer boots have a rc.local entry to fix this.

    Question:
    Can I load the modul permanently from a specific location. I heard about /etc/modules but there I need the module name, but I have to load it from a specific path (where is the default path for that) ?

    Thank you.

    So I studied the script:

    It creates the file r8101.ko in /lib/modules/`uname -r`/kernel/drivers/net so I think as long as nobody will delete that file, and I don't update the kernel, maybe adding r8108 to /etc/modules will work, and add r8169 to blacklist ... I will give it a try.

    EDIT2:
    So I added r8101 to /etc/modules and blacklist r8169 to /etc/modprobe.d/blacklist.conf. It still uses the old module.:

    radu@adu:~$ lsmod | grep r8
    r8101                  67626  0 
    r8169                  34108  0 
    mii                     4381  1 r8169
    

    EDIT: The module is loaded using this script that came with it.:

    #!/bin/sh
    
    # invoke insmod with all arguments we got
    # and use a pathname, as insmod doesn't look in . by default
    
    TARGET_PATH=/lib/modules/`uname -r`/kernel/drivers/net
    echo
    echo "Check old driver and unload it." 
    check=`lsmod | grep r8169`
    if [ "$check" != "" ]; then
            echo "rmmod r8169"
            /sbin/rmmod r8169
    fi
    
    check=`lsmod | grep r8101`
    if [ "$check" != "" ]; then
            echo "rmmod r8101"
            /sbin/rmmod r8101
    fi
    
    echo "Build the module and install"
    echo "-------------------------------" >> log.txt
    date 1>>log.txt
    make all 1>>log.txt || exit 1
    module=`ls src/*.ko`
    module=${module#src/}
    module=${module%.ko}
    
    if [ "$module" == "" ]; then
        echo "No driver exists!!!"
        exit 1
    elif [ "$module" != "r8169" ]; then
        if test -e $TARGET_PATH/r8169.ko ; then
            echo "Backup r8169.ko"
            if test -e $TARGET_PATH/r8169.bak ; then
                i=0
                while test -e $TARGET_PATH/r8169.bak$i
                do
                    i=$(($i+1))
                done
                echo "rename r8169.ko to r8169.bak$i"
                mv $TARGET_PATH/r8169.ko $TARGET_PATH/r8169.bak$i
            else
                echo "rename r8169.ko to r8169.bak"
                mv $TARGET_PATH/r8169.ko $TARGET_PATH/r8169.bak
            fi
        fi
    fi
    
    echo "Depending module. Please wait."
    depmod -a
    echo "load module $module"
    modprobe $module
    
    echo "Completed."
    exit 0
    
    • Javier Rivera
      Javier Rivera over 13 years
      If adding it to /etc/modules works, you should answer your own question.
    • Radu Maris
      Radu Maris over 13 years
      didn't work as expected, updated the question
    • papukaija
      papukaija over 13 years
      If you edit /etc/modules you need to run (as sudo) update-initramfs -u and then restart.
    • Radu Maris
      Radu Maris over 13 years
      @papukaija: man you'r a genius, tks :)
    • Ciro Santilli OurBigBook.com
      Ciro Santilli OurBigBook.com over 7 years