lsmodinfo - a script to show info about all loaded modules

Miscellaneous tools
Post Reply
Message
Author
gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

lsmodinfo - a script to show info about all loaded modules

#1 Post by gyro »

This script combines some of 'lsmod' with some of 'modinfo'.
It lists all the currently loaded kernel modules, providing the 'description:' and 'file:' information from 'modinfo'.

Here is output for the first 2 modules from running it on my Tahrpup 6.0.2:

Code: Select all

# ./lsmodinfo
joydev
  Joystick device interfaces
  /lib/modules/3.14.20/kernel/drivers/input/joydev.ko
snd_hda_codec_hdmi
  HDMI HD-audio codec
  /lib/modules/3.14.20/kernel/sound/pci/hda/snd-hda-codec-hdmi.ko
Note: Some modules don't have a 'description:' so there is only a 'file:' line for such a module:

Code: Select all

parport
  /lib/modules/3.14.20/kernel/drivers/parport/parport.ko
This script is meant to be a tool to assist in identifying any modules that support the keyboard. Since if there are, then most likely the keyboard won't work during the 'init' script in 'initrd.gz', when asking for the number for multiple savefiles/savefolders, or entering a password for encrypted savefiles. (Kernel modules are not available to the 'init'script.)

To use:
Dwonload the '.gz' file and move it to the directory you want to contain the utility.
Then gunzip the downloaded file.

gyro
Attachments
lsmodinfo.gz
gunzip to produce the script file
(258 Bytes) Downloaded 187 times

stemsee

#2 Post by stemsee »

I was going to write a script for stripping out unused modules, to slim down the kernel package. Your script with the 'file' line only is a solid step towards that goal! How to output only file lines to a file?

edit: ok did it.

Code: Select all

#!/bin/bash
touch /tmp/modlist
IFS_BAK=$IFS
IFS=$'\n'
for MOD in `lsmod`; do
	MODNM="${MOD%% *}"
	[ "$MODNM" = "Module" ] && continue
	MODFN="`modinfo \"$MODNM\" | grep -m1 'filename:' | tr -s ' ' | cut -f 2-20 -d ' '`"
	MODDES="`modinfo \"$MODNM\" | grep -m1 'description:' | tr -s ' ' | cut -f 2-20 -d ' '`"
	echo "$MODNM"
	[ "$MODDES" ] && echo "  $MODDES"
	[ "$MODFN" ] && echo "  $MODFN" >> /tmp/modlist
done
IFS=$IFS_BAK
IFS_BAK=
geany /tmp/modlist
exit

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

#3 Post by gyro »

stemsee wrote:I was going to write a script for stripping out unused modules, to slim down the kernel package. Your script with the 'file' line only is a solid step towards that goal! How to output only file lines to a file?

edit: ok did it.
I was just about to suggest the following:

Code: Select all

#!/bin/bash
IFS_BAK=$IFS
IFS=$'\n'
for MOD in `lsmod`; do
	MODNM="${MOD%% *}"
	[ "$MODNM" = "Module" ] && continue
	echo "`modinfo "$MODNM" | grep -m1 'filename:' | tr -s ' ' | cut -f 2-20 -d ' '`"
done
IFS=$IFS_BAK
IFS_BAK=
exit
then to get it into a file just:

Code: Select all

./lsmodfiles > /tmp/module-files
But glad you worked it out yourself.
gyro

Post Reply