See which modules are loaded linux

How to determine if a specific module is loaded in linux kernel

I am just curious is there any way to determine if a particular module is loaded/installed. $ lsmod lists all modules (device driver loaded). Is there any way to check or a command that returns true/false boolean output if a module name is polled. For eg. if keyboard.o exists return true else false. I need this tip to complete my driver auto refresh program. PS: tried modinfo. I am using busybox client in my test DUT so can you give some alternatives other than modinfo?

The question is a bit ambiguous. Are you trying to check if the driver is loaded into memory or installed on the system? modinfo would help with the latter but not the former.

10 Answers 10

The modinfo module method does not work well for me. I prefer this method that is similar to the alternative method proposed:

#!/bin/sh MODULE="$1" if lsmod | grep -wq "$MODULE"; then echo "$MODULE is loaded!" exit 0 else echo "$MODULE is not loaded!" exit 1 fi 

not sure if modinfo modname and checking $? will work for you, just a suggestion.

/tmp$ sudo modinfo e1000 /tmp$ echo $? 0 /tmp$ sudo modinfo keyboard ERROR: modinfo: could not find module keyboard /tmp$ echo $? 1 

alternatively you also grep /proc/modules

Just a note: the modinfo approach doesn’t seem to actually work for the loaded check (as in the question title). It shows info regardless of whether the module is loaded.

This is not a good solution. modinfo shows information of a kernel module installed on the rootfs, but it doesn’t check if the module is loaded into the kernel or not. So this solution should not be used to solve the issue.

The —first-time flag causes modprobe to fail if the module is already loaded. That in conjunction with the —dry-run (or the shorthand -n ) flag makes a nice test:

modprobe -n --first-time $MODULE && echo "Not loaded" || echo "Loaded" 

Edit 1: As @Nobody pointed out this also prints Loaded if the module does not exist. We can fix this by combining it with modinfo :

modinfo $MODULE >/dev/null 2>/dev/null && ! modprobe -n --first-time $MODULE 2>/dev/null && echo "Loaded" || echo "Not loaded" 

Edit 2: On some systems modprobe lives in /usr/sbin , which is not in the $PATH unless you are root. In that case you have to substitute modprobe for /usr/sbin/modprobe in the above.

Читайте также:  What is sda sdb in linux

Oh, sorry, I was only half-right (or maybe quarter-right. Shame on you comment-up-voters). On Debian, modprobe is not in $PATH for normal users, so just copy&pasting your command only works as root. But when calling modprobe with its full path, it’s executable for normal users and only the actual inserting operation fails, so your solution works in principle. I still think querying /proc/modules is more elegant, but that’s a matter of taste. Had I downvoted your answer, I would have removed the vote now (but I didn’t).

MODULE=snd_aloop # for example test -n "$(grep -e "^$MODULE " /proc/modules)" && echo "Loaded" || echo "Not loaded" 

It checks in /proc/modules . If the module is mentioned there, it’s assumed to be loaded, otherwise not.

The others seemed too long to me (the other short one requires root, this does not). Of course it’s just written out what was already mentioned as «alternatives».

Caution: modprobe accepts some variants of module names other than the primary listed in /proc/modules . For example loading snd-aloop works, but the module is named snd_aloop and is listed as such in /proc/modules and when using rmmod that’s also the only name that will work.

Источник

How to list all loadable kernel modules?

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 

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.

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.

Читайте также:  Sangoma linux 7 core

5 Answers 5

  • 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' 
find /lib/modules/$(uname -r) -type f -name '*.ko*' 

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*

@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*’

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

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?

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

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 .

Читайте также:  Linux policy password policy

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

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 lsmod is also available on Ubuntu, at least. However, I agree this does not solve OP’s problem.

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.

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.

According to man depmod option -a is not needed — it is enabled by default, if no file names are given in command line.

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 '')" -- "$1")) > 

So lsmod | awk '' should show you the list of modules

Источник

Оцените статью
Adblock
detector