Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 480
Dennis Ninj Avatar asked Mar 23 '12 20:03

Dennis Ninj


People also ask

How do I know if a kernel module is loaded?

To list all currently loaded modules in Linux, we can use the lsmod (list modules) command which reads the contents of /proc/modules like this.

Which command is used to check the loaded modules in kernel?

The lsmod command shows a list of the currently loaded kernel modules.

Where are kernel modules loaded?

Modules are stored in /usr/lib/modules/kernel_release . You can use the command uname -r to get your current kernel release version.


2 Answers

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 "$MODULE" &> /dev/null ; then   echo "$MODULE is loaded!"   exit 0 else   echo "$MODULE is not loaded!"   exit 1 fi 
like image 124
basfest Avatar answered Sep 25 '22 14:09

basfest


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

like image 36
johnshen64 Avatar answered Sep 26 '22 14:09

johnshen64