简体   繁体   English

Linux可加载和内置模块之间的区别

[英]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() 我在找到系统调用subsys_initcall()module_init()之间差异的答案时得到了这个问题

Linux kernel supports inserting of modules (aka device drivers) in two ways: Linux内核支持以两种方式插入模块(也称为设备驱动程序):

  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 可加载内核模块(LKM) - 内核未自动加载的驱动程序,用户可以在运行时通过insmod driver.komodprobe 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. 每次测试它并且需要对其进行更改时,您可以轻松卸载它( rmmod driver.komodprobe -r driver.ko ),然后在进行更改后,您可以将其重新插入。 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: 您可以通过编辑内核源根文件夹中的.config文件将模块配置为两者之一:

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. 注意: lsmod仅显示dynamically loaded modules而不显示built-in dynamically loaded modules

Read on: http://www.tldp.org/HOWTO/Module-HOWTO/x73.html 请继续阅读: http //www.tldp.org/HOWTO/Module-HOWTO/x73.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM