sbell
sbell

Reputation: 465

Linux: load module based on another module

Is it possible to dynamically load (via MOD_ALIAS() maybe?) a module that requires another module to first be loaded?

Background: I have a USB->I2C bridge on my system, and attached to the i2c end is a touchscreen. The kernel module that brings up the i2c automatically loads/unloads whenever the USB cable is connected/disconnected. I'm looking for a way to also load/unload the touchscreen driver on the same events.

Upvotes: 0

Views: 3243

Answers (2)

TheCodeArtist
TheCodeArtist

Reputation: 22477

What you want is modprobe.d

Add a <module>.conf file where <module> is the name of your kernel module that is dynamically loaded.

Define the install and remove options within the above conf file to run the relevant commands instead of the modprobe (in the required order).

If you want to automatically load the module bob after loading the module alice,

# /etc/modprobe.d/alice.conf
install alice /sbin/modprobe --ignore-install alice;  /sbin/modprobe bob;

The --ignore-install, stops the modprobe from running the same install command again.

Similarly define the remove section within the same conf file.
For more details, checkout the man page of modprobe.d.

Upvotes: 1

carveone
carveone

Reputation: 909

You're talking about module dependencies, generated by depmod -A. The actual dependency information is stored in /lib/modules/version/modules.dep.

If /lib/modules/2.6.29/kernel/a.ko depends on b.ko (in the same directory) you could add the line:

/lib/modules/2.6.29/kernel/a.ko: /lib/modules/2.6.29/kernel/b.ko

To create the dependency.

Upvotes: 1

Related Questions