Search code examples
linuxmodulelinux-kernel

Difference between Linux Loadable and built-in modules


What's the difference between loadable modules and built-in (statically linked) modules?

I got this question while finding out an answer for difference between system calls subsys_initcall() and module_init()


Solution

  • Linux kernel supports inserting of modules (aka device drivers) in two ways:

    1. Built-in kernel modules - When the kernel is booted up, the kernel automatically inserts this driver in to the kernel (it's more like it is already part of the kernel code).
    2. Loadable kernel module (LKM) - A driver that is not automatically loaded by the kernel, the user can insert this module at run-time by insmod driver.ko or modprobe driver.ko

    The advantage the loadable modules have over the built-in modules is that you can load unload them on run-time. This is good if you are working on a module and you need to test it. Every time you test it and you need to make changes to it, you can easily unload it (rmmod driver.ko or modprobe -r driver.ko) and then after making changes, you can insert it back. But for the built-in modules if you need to make any changes in the module then you need to compile the whole kernel and then reboot the system with the new image of the kernel.

    Configuration:
    You can configure a module to be either of the two by editing the .config file in the root folder of your kernel source:

    DRIVER_1=y // y indicate a builtin module
    DRIVER_1=m //m inicates a loadable module
    

    Note: lsmod displays only the dynamically loaded modules not the built-in ones.

    Read on: http://www.tldp.org/HOWTO/Module-HOWTO/x73.html