Determine If a Specific Module is Loaded in Linux Kernel
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" |
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 && |