The Linux Kernel: Modules

Discussion in 'Linux Kernel' started by DevynCJohnson, Dec 29, 2013.

  1. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,158
    Likes Received:
    983
    Trophy Points:
    113
    Series Index - http://www.linux.org/threads/linux-kernel-reading-guide.5384/

    Aloha! Now that we have our new kernel installed, we may have a module we wish to manipulate. Modules allow users to get extra hardware support without making a new kernel. For example, if a kernel is made without HFS support, a user can still use the HFS filesystem without making a new kernel.

    Just in case you do not fully understand modules, Window's equivalent to Linux's modules are called drivers. As an analogy - Linux is to Windows as module is to driver. However, many people still call modules "drivers". That is fine, people and search engines know what you mean. Sometimes, modules are referred to as Loadable Kernel Modules (LKMs) because they can be loaded without changing the kernel.

    Modules are stored under /lib/modules/ this directory has a directory for each installed kernel. The module files themselves end in ".ko" which stands for "Kernel Object".

    NOTE: Not all “.ko” files are modules. Linux also uses “.ko” for Linux's analogy of Window's “.dll” files.

    To access the module directory (via command-line) of the currently active kernel, type this command - /lib/modules/$(uname -r)/. The "$(uname -r)" will be replaced by the output of "uname -r", so the user does not need to know or memorize the name/version of the active kernel. This folder is well organized. In ./kernel/, these are the following directories.

    modules_01.png

    arch - Architecture specific modules

    crypto - Cryptography modules

    drivers - Many modules are stored here and are sorted by hardware type. For example, ATA modules are under the "ata" folder.

    modules_02.png

    fs - Filesystem modules are kept here. For instance, the module file for the Minix filesystem is /lib/modules/$(uname -r)/kernel/fs/minix/minix.ko

    lib - The library routines are stored under this directory

    mm - Modules for managing memory and debugging the kernel are stored here

    net - Network modules are stored here


    sound - This is an obvious one

    Some other folders may exist. For instance, I have a "ubuntu" directory which contains modules specific to Ubuntu or were added by the Ubuntu developers.

    When managing modules, Root privileges must be used. So, use "sudo" or login as Root.

    To load a module, use this command (when logged in as Root. Otherwise, remember sudo.)

    Code:
    modprobe <MODULE>
    For illustration, to use the HFS+ filesystem, load its module.

    Code:
    modprobe hfsplus
    Include the "-v" parameter for verbose messaging and "-s" sends error messages to the syslog. To see what modules the desired module requires, use "--show-depends" as a parameter. To remove a module, use "-r".

    To get information about a module, use the "modinfo <MODULE>" command. You may notice information about aliases. Some modules have an alias which can be used to reference the module. The real name and alias each work well. Use which ever you remember better.

    modules_04.png

    The "lsmod" command lists the currently load modules. This is helpful when users need to ensure a module is loaded.

    Some modules can be given special parameters before they are loaded. To view these parameters (and aliases) for a specific module, use this command

    Code:
    modprobe -c | grep <MODULE>
    To set a parameter for a module at runtime (the module is already running/loaded), use this command

    Code:
    insmod MODULE PARAM_NAME=VALUE
    If you wish to load a module and also set the parameter at the same time, use this command

    Code:
    modprobe MODULE PARAM_NAME=VALUE
    Alternately, parameters can be set at runtime be changing files in /sys/module/. For illustration, to change a parameter for a bluetooth module, use something like this

    Code:
    sudo echo -n "VALUE" > /sys/module/bluetooth/parameters/FILENAME
    If a module has issues loading, like an "unknown symbol error", the module may still be able to be loaded by using the "-f" parameter. Use this parameter with caution.

    Code:
    modprobe -f <MODULE>
    To load modules from different kernel versions, use the same command above after you copy the module to the active kernel's module path. Or, try

    Code:
    insmod /PATH/TO/MODULE.ko
    Now, you can enjoy your kernel even more with module manipulation.

    Attached Files:

    Last edited: May 11, 2014
    Haider92 likes this.
  2. cenyebin

    cenyebin New Member

    Messages:
    24
    Likes Received:
    2
    Trophy Points:
    3
    Good . I understood much afer reading this .thanks.

Share This Page