Linux可加载模块和内置模块之间的区别 [英] Difference between Linux Loadable and built-in modules
问题描述
可加载模块和内置(静态链接)模块之间有什么区别?
What's the difference between loadable modules and built-in (statically linked) modules?
我找到系统调用subsys_initcall()
和module_init()
推荐答案
Linux内核通过两种方式支持插入模块(即设备驱动程序):
Linux kernel supports inserting of modules (aka device drivers) in two ways:
- 内置内核模块-引导内核时,内核会自动将此驱动程序插入内核(更像是它已成为内核代码的一部分).
- 可加载内核模块(LKM)-内核未自动加载的驱动程序,用户可以在运行时通过
insmod driver.ko
或modprobe driver.ko
插入此模块.
- 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).
- 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
ormodprobe driver.ko
与内置模块相比,可加载模块的优势是您可以在运行时加载并卸载它们.如果您正在处理模块,并且需要对其进行测试,那么这很好.每次测试它并需要对其进行更改时,都可以轻松地将其卸载(rmmod driver.ko
或modprobe -r 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.
配置:
您可以通过在内核源代码的根文件夹中编辑.config
文件,将模块配置为两者之一:
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
注意:lsmod
仅显示dynamically loaded modules
,而不显示built-in
.
Note: lsmod
displays only the dynamically loaded modules
not the built-in
ones.
继续阅读: http://www. tldp.org/HOWTO/Module-HOWTO/x73.html
这篇关于Linux可加载模块和内置模块之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!