2

How can I manually create a Linux kernel module dependency?

For example, at some point in time module vboxdrv gets loaded automatically. BUT, when this happends I also want to automatically load module vfat (just as example).

Thus, how can I create a dependecy, when module 1 gets loaded, it triggers automatic load of module 2 ?

I do not need module loading at boot time with initramfs, I just want - so to say - this dependency, when 1 gets loaded, 2 will get loaded as well. You know what I mean ;-)

Thank you

2 Answers 2

6

You can add a configuration file /etc/modprobe.d/vboxdrv-includes-vfat.conf with a "soft dependency" command:

softdep vboxdrv post: vfat

The man page modprobe.d(5) documents the syntax:

softdep modulename pre: modules... post: modules...

The softdep command allows you to specify soft, or optional, module dependencies. modulename can be used without these optional modules installed, but usually with some features missing. For example, a driver for a storage HBA might require another module be loaded in order to use management features.

pre-deps and post-deps modules are lists of names and/or aliases of other modules that modprobe will attempt to install (or remove) in order before and after the main module given in the modulename argument

Alternatively, if softdep doesn't work as expected (e.g. if modprobe is too old to understand soft dependencies), you could use an install command in a file in the same directory to script the module insertion:

install modulename command...

This command instructs modprobe to run your command instead of inserting the module in the kernel as normal. The command can be any shell command: this allows you to do any kind of complex processing you might wish. For example, if the module "fred" works better with the module "barney" already installed (but it doesn't depend on it, so modprobe won't automatically load it), you could say "install fred /sbin/modprobe barney; /sbin/modprobe --ignore-install fred", which would do what you wanted. Note the --ignore-install, which stops the second modprobe from running the same install command again. See also remove below.

The long term future of this command as a solution to the problem of providing additional module dependencies is not assured and it is intended to replace this command with a warning about its eventual removal or deprecation at some point in a future release

2
  • Thanks, this is indeed the simple solution :-) Apr 1, 2021 at 22:14
  • @flyingpenguin If my answer solved your problem, please accept the solution by clicking the checkmark on the left :-)
    – cg909
    Apr 13, 2021 at 15:15
1

You could append one line defining such a dependency to modules.dep

echo "${module1}: ${module2}" >> "/lib/modules/$(uname -r)/modules.dep"

(Note: running depmod later may destroy your change, and you'll have to reapply)

Reference:

https://linux.die.net/man/5/modules.dep

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .