110

I'm looking for a few kernel modules to load i2c-dev and i2c-bcm2708. But the modprobe command returns:

sudo modprobe i2c-dev
modprobe: module i2c-dev not found in modules.dep

How do I list all the available modules in the system? In which directory are they located?

2
  • 1
    The kernel didnt compile this i2c-dev. You didnt find this module.The kernel modules located /lib/modules/'kernel-version'/drivers. When you are looking for linux drivers.
    – supriady
    Jan 18, 2017 at 8:26
  • 1
    You can check on /boot/config-'kernel-version' and read this config file.You should know which linux modules are loaded or modulars or during compiling kernel didnt enable i2c-dev module.
    – supriady
    Jan 18, 2017 at 8:33

5 Answers 5

127
  • By default modprobe loads modules from kernel subdirectories located in the /lib/modules/$(uname -r) directory. Usually all files have extension .ko, so you can list them with

    find /lib/modules/$(uname -r) -type f -name '*.ko'
    

    or, taking into account compressed files:

    find /lib/modules/$(uname -r) -type f -name '*.ko*'
    
  • Each module can be also loaded by referring to its aliases, stored in the /lib/modules/$(uname -r)/modules.alias (and modules.alias.bin).

  • However, to load a modules successfully modprobe needs their dependencies listed in the file /lib/modules/$(uname -r)/modules.dep (and a corresponding binary version modules.dep.bin). If some module is present on the system, but is not on the list, then you should run a command depmod which will generate such dependencies and automatically include your module to modules.dep and modules.dep.bin.

  • Additionally, if the module is successfully loaded it will be listed in the file /proc/modules (also accessed via command lsmod).

3
  • 3
    Redhat 7 modules files are compressed in .xz (not sure if it is because of kernel version or OS version.. if someone can clarify it to me?) so I think you might not find them with jimmij's find command. Use instead find /lib/modules/$(uname -r) -type f -name *.ko*
    – Pozinux
    Oct 5, 2017 at 13:14
  • 1
    @Pozinux Discovered the same thing here on Arch linux at 4.13.10, which have the ending .gz
    – Johann
    Nov 3, 2017 at 17:12
  • 1
    @posinux: beware : the shell may expand your *.ko* if you happen to have in your current dir some file matching it. better to escape it between single quotes: find /lib/modules/$(uname -r) -type f -name '*.ko*' Nov 21, 2017 at 17:01
12

Type modprobe and press tab, the autocomplete list should contain all the loadable modules

4
  • 28
    it doesn't work for some systems
    – avtomaton
    Feb 17, 2016 at 22:19
  • 4
    Requires necessary completion scripts in order to work
    – smac89
    Nov 22, 2020 at 3:56
  • Also its double tab, and you may get prompted that there is a specific large number of entries to list, then press y to list them. Also this answer does not provide the second part to OP's question which directory are they located?
    – Dave
    Jun 15, 2022 at 13:58
  • takes very long even on newer systems and doesn't give a really good way to look at ll the entries... just paging into one direction of 30k possibilities is probably not very much enlightening
    – Henning
    Jun 19, 2022 at 15:12
10

There is lsmod command of kmod package in Arch Linux what lists and shows the status of Linux kernel modules that contains other useful commands such as modinfo, rmmod modprobe too.

To list all binaries provided by the package you can type:

pacman -Ql kmod | grep /bin/ --color=always

, and you can also check for the owner package of a binary with pacman -Qo lsmod.


Q switch is to query locally installed packages (unlike S to synchronize, ie. to check remotely).

3
  • 5
    Where it's important to highlight that lsmod only shows already loaded modules. The Author of this thread had the problem to load a module that wasn't in the map of the loadable kernel modules. Besides, this solution only applies to archlinux. Which might be not the distribution of the Author and might not solve the problem for others.
    – Akendo
    Feb 6, 2018 at 13:52
  • @Akendo lsmod is also available on Ubuntu, at least. However, I agree this does not solve OP’s problem.
    – Melebius
    Oct 2, 2019 at 7:50
  • 1
    There is absolutely no point in talking about Arch specifically, and lsmod is a universally available command. Furthermore, the whole point of the question is to list loadable/available modules, whereas lsmod only prints listed modules. This answer should be moderated.
    – Atralb
    Aug 16, 2020 at 18:41
7

I prefer to use depmod. With the command: depmod -av|grep MOD_NAME, your system will generate the modules.dep/map files and grep through it. The -v parameter is important for verbosity and -a to ensure that all possible modules from /lib/modules/ are used for the modules.dep file.

This way it's possible to ensure, that a requested kernel module is mapped to the kernel as loadable. When the desire kernel module is not listed in the output, you know that the kernel won't find it.

2
  • 2
    According to man depmod option -a is not needed -- it is enabled by default, if no file names are given in command line.
    – whtyger
    Sep 22, 2021 at 8:51
  • I don't see the -v parameter on the version of depmod included in BusyBox that I'm using, but -n may work.
    – mmortal03
    Aug 7 at 2:44
5

You can check how autocompletion does it:

$ complete -p modprobe
complete -F _modprobe modprobe
declare -f _modprobe
_modprobe () 
{ 
...

In that function there's an internal _installed_modules

$ declare -f _installed_modules
_installed_modules () 
{ 
    COMPREPLY=($(compgen -W "$(PATH="$PATH:/sbin" lsmod |
        awk '{if (NR != 1) print $1}')" -- "$1"))
}

So lsmod | awk '{if (NR != 1) print $1}' should show you the list of modules

You must log in to answer this question.

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