What's The Difference Between Insmod and Modprobe

What's the difference between insmod and modprobe?

modprobe is the intelligent version of insmod. insmod simply adds a module where modprobe looks for any dependency (if that particular module is dependent on any other module) and loads them.

Regarding --force option, here is the quote from the man page:

   Try to strip any versioning information from the module which might otherwise
stop it from loading: this is the same as using both --force-vermagic and
--force-modversion. Naturally, these checks are there for your protection,
so using this option is dangerous unless you know what you are doing.

Which indicates it's been used to skip the kernel module version checking. Shouldn't be any problem if you do your own kernel module or from any trusted party. But you should know what you are doing.

why modprobe is not secure compare to insmod?

A long time ago the way modprobe worked led to some security risks. Look here for more info. They have since been fixed, but the perception continues that modprobe needs to be avoided. Also in embedded world where software does not get updated as frequently there might be systems where this threat still holds.

Difference between Linux Loadable and built-in modules

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

How do I configure modprobe to find my module?

You can make a symbolic link of your module to the standard path, so depmod will see it and you'll be able load it as any other module.

sudo ln -s /path/to/module.ko /lib/modules/`uname -r`
sudo depmod -a
sudo modprobe module

If you add the module name to /etc/modules it will be loaded any time you boot.

Anyway I think that the proper configuration is to copy the module to the standard paths.

difference between using select() and checking in a loop

select ( and the more modern epoll ) is better than just looping in at least one way. Select is blocking or can be configured with a timeout - meaning a process can sleep until something happens - which makes the calling process much more efficient and have better performance. You couldn't have a loop to monitor a large number of file descriptors and just add a delay to not max out the cpu usage that would be very efficient.



Related Topics



Leave a reply



Submit