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

Dennis Ninj picture Dennis Ninj · Mar 23, 2012 · Viewed 79.8k times · Source

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 ?

Answer

basfest picture basfest · Dec 21, 2012

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