S.K.I.M. - SuSE Kernel Installed Modules - A lsmod replacement - Creates an Alphabetized Mod Listing

S.K.I.M. - SuSE Kernel Installed Modules; A bash script file intended to be a replacement for the terminal command lsmod. It provides an alphabetized kernel module listing which can also be saved as a text file into Documents folder, as selected at run time of the bash script. Here is what the text listing looks like using skim (the terminal command Less is used to display text):

http://thumbnails43.imagebam.com/14415/ec5972144149952.jpg](ImageBam)

In order to obtain S.K.I.M., please copy and paste the following text in the code field into your favorite text editor:

#!/bin/bash

#: Title       : skim
#: Date Created: Sun Aug 7 13:03:13 CDT 2011
#: Last Edit   : Mon Aug 8 18:35:13 CDT 2011
#: Author      : James D. McDaniel
#: Version     : 1.00
#: Description : Provides Kernel Module Information
#: Options     : skim -m -h -r --help]

TITLE="S.K.I.M. - SuSE Kernel Installed Modules"

declare -a arr
declare -a lin

#
# Where do you want to create your module text files?
#
mod_file_location=~/Documents

#
# skim creates a text file, do you want it removed on exit?
# remove_mod_text_file_on_exit=false <OR> remove_mod_text_file_on_exit=true
# the skim -r startup option can override this selection
#
remove_mod_text_file_on_exit=true

#
# Written for the openSUSE forums on Monday August 8, 2011
#

#
# Copy and Paste the text of this script into a text editor and save 
# it as the file skim in your home area bin folder (~/bin/skim).
# This script must be marked executable to be used.  Please run 
# the following Terminal command: chmod +x ~/bin/skim
# To use skim, open a terminal session and type: skim or skim -h for help
#

# S.K.I.M. function Blocks ****************************************************

#
# This is the standard GPL Statement, leave at the top of the script.
# Just use the command show_gpl after this function for it to be shown.
#
function show_gpl {
echo ""
echo "S.K.I.M. is a bash script file written to be used with openSUSE."
echo "Copyright (C) 2011 by James D. McDaniel, jmcdaniel3@austin.rr.com"
echo ""
echo "This program is free software; you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation; either version 2 of the License, or"
echo "(at your option) any later version."
echo ""
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo ""
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
echo ""
}

#
# S.K.I.M. Help Display Function
#
function help {
tput clear
    cat << EOFHELP
                  $TITLE

S.K.I.M. requires no Startup Options, But if you use them, your choices are:

skim         ; Shows Listed Modules
skim -r        ; Shows Listed Modules & Saves Text Report
skim -m         ; Shows Skim Menu
skim -m -r      ; Shows Skim Menu & Saves Text Report
skim -h         ; Shows this help
skim --help     ; Shows this help 

EOFHELP
echo -n "         Press <enter> to read the GPL Statement for S.K.I.M."
read CHOICE
tput clear
show_gpl
exit 0
}

#
# Locate next Substring by space seperator in a long string  
# Start looking at character position $1 in string $2
# Return location of next space, between sub-strings
#
function sub_string {
  counter=$1
  start=$2
  num2=${#start}
  while  $(( counter )) -lt $(( num2 + 1 )) ] ; do
  temp="${start:$(($counter)):1}"
  if  $temp != " " ]] ; then
    let counter=counter+1
  else
    return ${counter}
  fi
  done
  return ${counter}
}

#
# Common S.K.I.M. Exit Tasks
#
function exit_skim {
tput clear
echo $TITLE " - Total of $a Modules Found"
show_gpl
if $remove_mod_text_file_on_exit ; then
  rm $mod_file_name
else
  echo "Your Kernel Module Info was saved in: "
  echo
  echo $mod_file_name
fi
  echo
}

# S.K.I.M. Error & Help *******************************************************

#
# Determine if the folder mod_file_location exists
#
if  ! -d "$mod_file_location" ]] ; then
  echo "The Document Folder: $mod_file_location, does not exist!"
  echo "Please create or change this folder name and start $(basename $0) again."
  echo
  exit 1
fi

#
# Display S.K.I.M. Help if requested.
#
menu=false
case "$1" in
    -h|--help) help ;;
    -m|-M) menu=true ;;
    -r|-R) remove_mod_text_file_on_exit=false ;; 
esac
case "$2" in
    -r|-R) remove_mod_text_file_on_exit=false ;; 
    -m|-M) menu=true ;;
esac

# S.K.I.M. Create Module Text File ********************************************

#
# Sets the name of the text file where your module info is saved
#
ext=$(date +%m%d%y.%H%M%S)
mod_file_name=$mod_file_location"/"Kernel_Module_Listing"."$ext".txt"
#
# This reads in the module list, then sorts it by to your text file as named above
#
a=0
sort /proc/modules -o $mod_file_name
while read line; do a=$(($a+1)); arr$a]=$a") "$line; done < $mod_file_name
#
# We now create a header for the modul listing text file
#
echo $TITLE " - Total of $a Modules Loaded" > $mod_file_name
echo >> $mod_file_name
echo "Name     = Shows the internal name of the kernel module installed." >> $mod_file_name
echo "Size     = Refers to the total memory size used by the module, in bytes." >> $mod_file_name
echo "Ins      = Lists how many instances of the module are currently loaded. '0' means unloaded." >> $mod_file_name
echo "Requires = Lists required module(s) that must be present in order to function properly." >> $mod_file_name
echo >> $mod_file_name
echo "Num   Name                    Size     Ins  Requires" >> $mod_file_name

#
# We serach through each line of text for an installed module, 
# finding the space in order to space out like items into columns
#
pointer=0
while  $pointer -lt $((a+1)) ]] ; do
  pos=0
  ind=0
  while  $pos -lt 8 ]] ; do
    sub_string $((ind)) "${arr$pointer]}"
    nxt=$?
    lin$pos]=${arr$pointer]:$((ind)):$((nxt-ind))}
    let pos=pos+1
    let ind=nxt+1
  done
#
# This sets the width for each column set
#
  pos=0
# This is the default Tab width for module dependancies
  area=80
  while  $pos -lt 5 ]] ; do
# The Module Number
    if  $pos -eq 0 ]] ; then
      area=5
    fi
# The module name
    if  $pos -eq 1 ]] ; then
      area=23
    fi
# The module memory size
    if  $pos -eq 2 ]] ; then
      area=9
    fi
# The module instance
    if  $pos -eq 3 ]] ; then
      area=3
    fi
# Output the item within the selected field
    let spc=${#lin$pos]}
    let tot=area-spc
    echo -n ${lin$pos]} >> $mod_file_name
# Pad with spaces less item length per field width
    cnt=0
    while  $cnt -lt $((tot+1)) ]] ; do
      echo -n " " >> $mod_file_name
      let cnt=cnt+1
    done
    let pos=pos+1
  done
# Terminate the finished modulde text line when complete
  echo >> $mod_file_name
  let pointer=pointer+1
done

#
# S.K.I.M. Main Menu when a menu is requested. ********************************
#
while $menu ; do
  tput clear
  echo $TITLE " - Total of $a Modules Loaded" 
  echo
  echo "1) View Your Module Listing with Viewer Less - Enter a Q to quit"
  echo "2) Get Info On a Module (View Module Listing First for a Number)"
  echo "Q) Quit $TITLE"
  echo
  echo -n "Please Make Your Selection: "
  read -n1 CHOICE
#
# View Your Module Listing using Less
#
  if  $CHOICE == "1" ]] ; then
    less $mod_file_name
  fi
#
# Menu to request module name modinfo to be used
#
  if  $CHOICE == "2" ]] ; then  
    tput clear 
    echo $TITLE " - Total of $a Modules Loaded" 
    echo
    echo -n "Enter Module Number for Information and press <enter> [1-$a]: "
    read CHOICE
#
# Check the number entered as valid between 1 and maximum modules loaded
#
    if  $CHOICE =~ ^[0-9]+$ ]] ; then
      if  $CHOICE -le $a ]] &&  $CHOICE -gt 0 ]]; then
    sub_string "0" "${arr$CHOICE]}"
        loc1=$?
    sub_string "$((loc1+1))" "${arr$CHOICE]}"
        loc2=$?
        cmd=${arr$CHOICE]:$((loc1+1)):$((loc2-loc1))}
        echo
        echo ${arr$CHOICE]}
        echo          
    /sbin/modinfo $cmd
        echo 
        echo -n "Press Any Key to Continue: "
        read something
      fi
    fi    
  fi

#
# Exit S.K.I.M. program & output the GPL statement
#
  if  $CHOICE == [Qq] ]] ; then
    exit_skim
    exit 0
  fi    
done

#
# S.K.I.M. -m option was selected to be here **********************************
#
less $mod_file_name
exit_skim

exit 0

# End Of Script

Save the above script as the text file called skim into your ~/bin folder (/home/yourname/bin/skim). In order to use skim it must be marked executable. Open up a terminal session and run the following command:

chmod +x ~/bin/skim

To use skim, open up a terminal session and use one of the following startup options:

              S.K.I.M. - SuSE Kernel Installed Modules

S.K.I.M. requires no Startup Options, But if you use them, your choices are (as shown by using skim -h):

skim ; Shows Listed Modules
skim -r ; Shows Listed Modules & Saves Text Report
skim -m ; Shows Skim Menu
skim -m -r ; Shows Skim Menu & Saves Text Report
skim -h ; Shows this help
skim --help ; Shows this help

The skim -m option starts a menu that allows you to view the module listing and to request modinfo for any installed module. Here is such an example:

S.K.I.M. - SuSE Kernel Installed Modules  - Total of 85 Modules Loaded

Enter Module Number for Information and press <enter> [1-85]: 7

7) coretemp 6542 0 - Live 0xffffffffa00b8000

filename:       /lib/modules/3.0.1-0.5-desktop/kernel/drivers/hwmon/coretemp.ko
license:        GPL
description:    Intel Core temperature monitor
author:         Rudolf Marek <r.marek@assembler.cz>
srcversion:     C4C170496F5A24372E34F70
depends:        
vermagic:       3.0.1-0.5-desktop SMP preempt mod_unload modversions 

Press Any Key to Continue:

When you elect to save the module listing ( skim -r <OR> skim -m -r ) the text file it is saved in the ~/Documents folder in the format: Module_Listing.080711.201729.txt and can be viewed at a later time if required. As always I want to hear any comments you may have about the usage of skim. When you read through this message thread, always look to the end for newer versions of skim, should they exist. Remember you can name skim anything you like should the cleverness of S.K.I.M. escape you.

Thank You,

James,

How do you like this single awk command?

sort /proc/modules | awk 'BEGIN {printf "%-7s%-25s%-11s%-5s%s

", "Num", "Nam", "Size", "Ins", "Requires"} ; { I=NR")" ; printf "%-7s%-25s%-12s%-5s%s
", I, $1, $2, $3, $4 }'

On 08/10/2011 05:26 AM, please try again wrote:
>
> sort /proc/modules | awk 'BEGIN {printf "%-7s%-25s%-11s%-5s%s

“, “Num”, “Nam”, “Size”, “Ins”, “Requires”} ; { I=NR”)" ; printf "%-7s%-25s%-12s%-5s%s
", I, $1, $2, $3, $4 }’

very cool, but you forgot to add at the end:


| less

:slight_smile:


DD
openSUSE®, the “German Engineered Automobiles” of operating systems!

Yes, that is very nice. I must say I would still put it into a script, add the ability to save the report and to use modinfo. And, I don’t really like single line commands. There is no doubt that awk seems to do a lot more with a lot less. I did place the whole thing into a array so you could call up any kernel module with modinfo. I will see how I might use this on the weekend. Thanks for the help guys.

Thank You,

One array would be tricky (because of the 4 values), but you could easily create 4 arrays with an awk command:

eval $(sort /proc/modules | awk '{ I=NR-1 ; printf "mnam[%s]=\"%s\" ; msiz[%s]=\"%s\" ; mins[%s]=\"%s\" ; mreq[%s]=\"%s\" ; ", I, $1, I, $2, I, $3, I, $4 }')

Then you can do what you want with the arrays mnam, msiz, mins and mreq (which of course are just examples here).


i=0 ;
while [ $i -lt ${#mnam[li]} ] ; do
[/li]	I=$i
	[ $i -lt 10 ] && I=" $i"
	I="$I)"
	printf "%-7s%-25s%-12s%-5s%s
" $I ${mnam[$i]} ${msiz[$i]} ${mins[$i]} ${mreq[$i]}
	let i++
done

The 3 lines in grey are actually only needed to justify the module names.
Notice that printf used here is the printf command and not the awk printf instruction, as in my first post.

OK, in response to the super suggestions from please_try_again, I have incorporated the usage of awk in the skim bash script file. This does reduce its over all size and speeds up its execution. I am pleased to post version 1.10 of S.K.I.M. for your using pleasure:

S.K.I.M. - SuSE Kernel Installed Modules; A bash script file intended to be a replacement for the terminal command lsmod. It provides an alphabetized kernel module listing which can also be saved as a text file into Documents folder, as selected at run time of the bash script. Here is what the text listing looks like using skim (the terminal command Less is used to display text):

In order to obtain S.K.I.M., please copy and paste the following text in the code field into your favorite text editor:

#!/bin/bash

#: Title       : skim
#: Date Created: Sun Aug 7  13:03:13 CDT 2011
#: Last Edit   : Sat Aug 13 08:52:00 CDT 2011
#: Author      : James D. McDaniel
#: Version     : 1.10
#: Description : Provides Kernel Module Information
#: Options     : skim [-m -h -r --help]

TITLE="S.K.I.M. - SuSE Kernel Installed Modules V1.10"

declare -a mnam
declare -a msiz
declare -a mins
declare -a mreq

#
# Where do you want to create your module text files?
#
mod_file_location=~/Documents

#
# skim creates a text file, do you want it removed on exit?
# remove_mod_text_file_on_exit=false <OR> remove_mod_text_file_on_exit=true
# the skim -r startup option can override this selection
#
remove_mod_text_file_on_exit=true

#
# Written for the openSUSE forums on Saturday August 13, 2011
#

#
# Copy and Paste the text of this script into a text editor and save 
# it as the file skim in your home area bin folder (~/bin/skim).
# This script must be marked executable to be used.  Please run 
# the following Terminal command: chmod +x ~/bin/skim
# To use skim, open a terminal session and type: skim or skim -h for help
#

# S.K.I.M. function Blocks ****************************************************

#
# This is the standard GPL Statement, leave at the top of the script.
# Just use the command show_gpl after this function for it to be shown.
#
function show_gpl {
echo ""
echo "S.K.I.M. is a bash script file written to be used with openSUSE."
echo "Copyright (C) 2011 by James D. McDaniel, jmcdaniel3@austin.rr.com"
echo ""
echo "This program is free software; you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation; either version 2 of the License, or"
echo "(at your option) any later version."
echo ""
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo ""
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
echo ""
}

#
# We now create a header for the module listing text file
#
function log_header {
echo $TITLE " - Total of $a Modules Loaded" > $mod_file_name
echo >> $mod_file_name
echo "Name     = Shows the internal name of the kernel module installed." >> $mod_file_name
echo "Size     = Refers to the total memory size used by the module, in bytes." >> $mod_file_name
echo "Ins      = Lists how many instances of the module are currently loaded. '0' means unloaded." >> $mod_file_name
echo "Requires = Lists required module(s) that must be present in order to function properly." >> $mod_file_name
echo >> $mod_file_name
}

#
# Log file footer for text file listing
#
function log_footer {
echo >> $mod_file_name
echo "End Of Kernel Module Listing - Report Done on $rdate" >> $mod_file_name
echo >> $mod_file_name
}

#
# S.K.I.M. Help Display Function
#
function help {
tput clear
    cat << EOFHELP
            $TITLE

S.K.I.M. requires no Startup Options, But if you use them, your choices are:

skim         ; Shows Listed Modules
skim -r        ; Shows Listed Modules & Saves Text Report
skim -m         ; Shows Skim Menu
skim -m -r      ; Shows Skim Menu & Saves Text Report
skim -h         ; Shows this help
skim --help     ; Shows this help 

EOFHELP
echo -n "         Press <enter> to read the GPL Statement for S.K.I.M."
read CHOICE
tput clear
show_gpl
exit 0
}

#
# Common S.K.I.M. Exit Tasks
#
function exit_skim {
tput clear
echo $TITLE " - Total of $a Modules Found"
show_gpl
if $remove_mod_text_file_on_exit ; then
  rm $mod_file_name
else
  echo "Your Kernel Module Info was saved in: "
  echo
  echo $mod_file_name
fi
  echo
}

# S.K.I.M. Error & Help *******************************************************

#
# Determine if the folder mod_file_location exists
#
if [[ ! -d "$mod_file_location" ]] ; then
  echo "The Document Folder: $mod_file_location, does not exist!"
  echo "Please create or change this folder name and start $(basename $0) again."
  echo
  exit 1
fi

#
# S.K.I.M. startup options are checked here
#
menu=false
case "$1" in
    -h|--help) help ;;
    -m|-M) menu=true ;;
    -r|-R) remove_mod_text_file_on_exit=false ;; 
esac
case "$2" in
    -r|-R) remove_mod_text_file_on_exit=false ;; 
    -m|-M) menu=true ;;
esac

# S.K.I.M. Create Module Text File ********************************************

#
# Sets the name of the text file where your module info is saved
#
rdate=$(date +%m/%d/%y-%H:%M:%S)
ext=$(date +%m%d%y.%H%M%S)
mod_file_name=$mod_file_location"/"Kernel_Module_Listing"."$ext".txt"

#
# This reads in the module list, then sorts it by to your text file as named above
#
log_header
sort /proc/modules | awk 'BEGIN {printf "%-7s%-25s%-11s%-5s%s

", "Num", "Name", "Size", "Ins", "Requires"} ; { I=NR")" ; printf "%-7s%-25s%-12s%-5s%s
", I, $1, $2, $3, $4 }' >> $mod_file_name
log_footer

#
# Load the kernel Modules into arrays
#
eval $(sort /proc/modules | awk '{ I=NR-1 ; printf "mnam[%s]=\"%s\" ; msiz[%s]=\"%s\" ; mins[%s]=\"%s\" ; mreq[%s]=\"%s\" ; ", I, $1, I, $2, I, $3, I, $4 }')

# Set a=Total number of modules loaded into the array
a=${#mnam
[li]}[/li]
#
# S.K.I.M. Main Menu when a menu is requested. ********************************
#
while $menu ; do
  tput clear
  echo $TITLE " - Total of $a Modules Loaded" 
  echo
  echo "1) View Your Module Listing with Viewer Less - Enter a Q to quit"
  echo "2) Get Info On a Module (View Module Listing First for a Number)"
  echo "Q) Quit $TITLE"
  echo
  echo -n "Please Make Your Selection: "
  read -n1 CHOICE

#
# View Your Module Listing using Less
#
  if [[ $CHOICE == "1" ]] ; then
    less $mod_file_name
  fi

#
# Menu to request module name modinfo to be used
#
  if [[ $CHOICE == "2" ]] ; then  
    tput clear 
    echo $TITLE " - Total of $a Modules Loaded" 
    echo
    echo -n "Enter Module Number for Information and press <enter> [1-$a]: "
    read CHOICE

#
# Check the number entered as valid between 1 and maximum modules loaded
#
    if [[ $CHOICE =~ ^[0-9]+$ ]] ; then
      if [[ $CHOICE -le $a ]] && [[ $CHOICE -gt 0 ]]; then
        let array=CHOICE-1
        cmd=${mnam[$array]}
        echo
        echo -n "$CHOICE) Name=${mnam[$array]}, Size=${msiz[$array]}, Instance=${mins[$array]}, "
    if [[ "${mreq[$array]}" == "-" ]] ; then
      echo "Requires=none"
    else
      echo "Requires=${mreq[$array]}"
    fi
        echo          
    /sbin/modinfo $cmd
        echo 
        echo -n "Press Any Key to Continue: "
        read something
      fi
    fi    
  fi

#
# Exit S.K.I.M. program & output the GPL statement
#
  if [[ $CHOICE == [Qq] ]] ; then
    exit_skim
    exit 0
  fi    
done

#
# S.K.I.M. the menu option was not selected to be here ************************
#
less $mod_file_name
exit_skim

exit 0

# End Of Script


Save the above script as the text file called skim into your ~/bin folder (/home/yourname/bin/skim). In order to use skim it must be marked executable. Open up a terminal session and run the following command:


chmod +x ~/bin/skim 


To use skim, open up a terminal session and use one of the following startup options:

S.K.I.M. - SuSE Kernel Installed Modules

S.K.I.M. requires no Startup Options, But if you use them, your choices are (as shown by using skim -h):

skim ; Shows Listed Modules
skim -r ; Shows Listed Modules & Saves Text Report
skim -m ; Shows Skim Menu
skim -m -r ; Shows Skim Menu & Saves Text Report
skim -h ; Shows this help
skim --help ; Shows this help

The skim -m option starts a menu that allows you to view the module listing and to request modinfo for any installed module. Here is such an example:

S.K.I.M. - SuSE Kernel Installed Modules V1.10 - Total of 85 Modules Loaded

Enter Module Number for Information and press <enter> [1-85]: 7

  1. Name=coretemp, Size=6542, Instance=0, Requires=none

filename: /lib/modules/3.0.1-0.5-desktop/kernel/drivers/hwmon/coretemp.ko
license: GPL
description: Intel Core temperature monitor
author: Rudolf Marek <r.marek@assembler.cz>
srcversion: C4C170496F5A24372E34F70
depends:
vermagic: 3.0.1-0.5-desktop SMP preempt mod_unload modversions

Press Any Key to Continue:

When you elect to save the module listing ( skim -r <OR> skim -m -r ) the text file it is saved in the ~/Documents folder in the format: Module_Listing.080711.201729.txt and can be viewed at a later time if required. As always I want to hear any comments you may have about the usage of skim. When you read through this message thread, always look to the end for newer versions of skim, should they exist. Remember you can name skim anything you like should the cleverness of S.K.I.M. escape you.

Thank You,

Already found one issue with the previous code. I needed to load the array first so that the module listing knows the number of modules that exist. So, I have reversed these items in version 1.11 shown below:

#!/bin/bash

#: Title       : skim
#: Date Created: Sun Aug 7  13:03:13 CDT 2011
#: Last Edit   : Sat Aug 13 11:55:00 CDT 2011
#: Author      : James D. McDaniel
#: Version     : 1.11
#: Description : Provides Kernel Module Information
#: Options     : skim [-m -h -r --help]

TITLE="S.K.I.M. - SuSE Kernel Installed Modules V1.11"

declare -a mnam
declare -a msiz
declare -a mins
declare -a mreq

#
# Where do you want to create your module text files?
#
mod_file_location=~/Documents

#
# skim creates a text file, do you want it removed on exit?
# remove_mod_text_file_on_exit=false <OR> remove_mod_text_file_on_exit=true
# the skim -r startup option can override this selection
#
remove_mod_text_file_on_exit=true

#
# Written for the openSUSE forums on Saturday August 13, 2011
#

#
# Copy and Paste the text of this script into a text editor and save 
# it as the file skim in your home area bin folder (~/bin/skim).
# This script must be marked executable to be used.  Please run 
# the following Terminal command: chmod +x ~/bin/skim
# To use skim, open a terminal session and type: skim or skim -h for help
#

# S.K.I.M. function Blocks ****************************************************

#
# This is the standard GPL Statement, leave at the top of the script.
# Just use the command show_gpl after this function for it to be shown.
#
function show_gpl {
echo ""
echo "S.K.I.M. is a bash script file written to be used with openSUSE."
echo "Copyright (C) 2011 by James D. McDaniel, jmcdaniel3@austin.rr.com"
echo ""
echo "This program is free software; you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation; either version 2 of the License, or"
echo "(at your option) any later version."
echo ""
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo ""
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
echo ""
}

#
# We now create a header for the module listing text file
#
function log_header {
echo $TITLE " - Total of $a Modules Loaded" > $mod_file_name
echo >> $mod_file_name
echo "Name     = Shows the internal name of the kernel module installed." >> $mod_file_name
echo "Size     = Refers to the total memory size used by the module, in bytes." >> $mod_file_name
echo "Ins      = Lists how many instances of the module are currently loaded. '0' means unloaded." >> $mod_file_name
echo "Requires = Lists required module(s) that must be present in order to function properly." >> $mod_file_name
echo >> $mod_file_name
}

#
# Log file footer for text file listing
#
function log_footer {
echo >> $mod_file_name
echo "End Of Kernel Module Listing - Report Done on $rdate" >> $mod_file_name
echo >> $mod_file_name
}

#
# S.K.I.M. Help Display Function
#
function help {
tput clear
    cat << EOFHELP
            $TITLE

S.K.I.M. requires no Startup Options, But if you use them, your choices are:

skim         ; Shows Listed Modules
skim -r        ; Shows Listed Modules & Saves Text Report
skim -m         ; Shows Skim Menu
skim -m -r      ; Shows Skim Menu & Saves Text Report
skim -h         ; Shows this help
skim --help     ; Shows this help 

EOFHELP
echo -n "         Press <enter> to read the GPL Statement for S.K.I.M."
read CHOICE
tput clear
show_gpl
exit 0
}

#
# Common S.K.I.M. Exit Tasks
#
function exit_skim {
tput clear
echo $TITLE " - Total of $a Modules Found"
show_gpl
if $remove_mod_text_file_on_exit ; then
  rm $mod_file_name
else
  echo "Your Kernel Module Info was saved in: "
  echo
  echo $mod_file_name
fi
  echo
}

# S.K.I.M. Error & Help *******************************************************

#
# Determine if the folder mod_file_location exists
#
if [[ ! -d "$mod_file_location" ]] ; then
  echo "The Document Folder: $mod_file_location, does not exist!"
  echo "Please create or change this folder name and start $(basename $0) again."
  echo
  exit 1
fi

#
# S.K.I.M. startup options are checked here
#
menu=false
case "$1" in
    -h|--help) help ;;
    -m|-M) menu=true ;;
    -r|-R) remove_mod_text_file_on_exit=false ;; 
esac
case "$2" in
    -r|-R) remove_mod_text_file_on_exit=false ;; 
    -m|-M) menu=true ;;
esac

# S.K.I.M. Create Module Text File ********************************************

#
# Sets the name of the text file where your module info is saved
#
rdate=$(date +%m/%d/%y-%H:%M:%S)
ext=$(date +%m%d%y.%H%M%S)
mod_file_name=$mod_file_location"/"Kernel_Module_Listing"."$ext".txt"

#
# Load the kernel Modules into arrays
#
eval $(sort /proc/modules | awk '{ I=NR-1 ; printf "mnam[%s]=\"%s\" ; msiz[%s]=\"%s\" ; mins[%s]=\"%s\" ; mreq[%s]=\"%s\" ; ", I, $1, I, $2, I, $3, I, $4 }')

# Set a=Total number of modules loaded into the array
a=${#mnam
[li]}[/li]
#
# This reads in the module list, then sorts it by to your text file as named above
#
log_header
sort /proc/modules | awk 'BEGIN {printf "%-7s%-25s%-11s%-5s%s

", "Num", "Name", "Size", "Ins", "Requires"} ; { I=NR")" ; printf "%-7s%-25s%-12s%-5s%s
", I, $1, $2, $3, $4 }' >> $mod_file_name
log_footer

#
# Load the kernel Modules into arrays
#
eval $(sort /proc/modules | awk '{ I=NR-1 ; printf "mnam[%s]=\"%s\" ; msiz[%s]=\"%s\" ; mins[%s]=\"%s\" ; mreq[%s]=\"%s\" ; ", I, $1, I, $2, I, $3, I, $4 }')

# Set a=Total number of modules loaded into the array
a=${#mnam
[li]}[/li]
#
# S.K.I.M. Main Menu when a menu is requested. ********************************
#
while $menu ; do
  tput clear
  echo $TITLE " - Total of $a Modules Loaded" 
  echo
  echo "1) View Your Module Listing with Viewer Less - Enter a Q to quit"
  echo "2) Get Info On a Module (View Module Listing First for a Number)"
  echo "Q) Quit $TITLE"
  echo
  echo -n "Please Make Your Selection: "
  read -n1 CHOICE

#
# View Your Module Listing using Less
#
  if [[ $CHOICE == "1" ]] ; then
    less $mod_file_name
  fi

#
# Menu to request module name modinfo to be used
#
  if [[ $CHOICE == "2" ]] ; then  
    tput clear 
    echo $TITLE " - Total of $a Modules Loaded" 
    echo
    echo -n "Enter Module Number for Information and press <enter> [1-$a]: "
    read CHOICE

#
# Check the number entered as valid between 1 and maximum modules loaded
#
    if [[ $CHOICE =~ ^[0-9]+$ ]] ; then
      if [[ $CHOICE -le $a ]] && [[ $CHOICE -gt 0 ]]; then
        let array=CHOICE-1
        cmd=${mnam[$array]}
        echo
        echo -n "$CHOICE) Name=${mnam[$array]}, Size=${msiz[$array]}, Instance=${mins[$array]}, "
    if [[ "${mreq[$array]}" == "-" ]] ; then
      echo "Requires=none"
    else
      echo "Requires=${mreq[$array]}"
    fi
        echo          
    /sbin/modinfo $cmd
        echo 
        echo -n "Press Any Key to Continue: "
        read something
      fi
    fi    
  fi

#
# Exit S.K.I.M. program & output the GPL statement
#
  if [[ $CHOICE == [Qq] ]] ; then
    exit_skim
    exit 0
  fi    
done

#
# S.K.I.M. the menu option was not selected to be here ************************
#
less $mod_file_name
exit_skim

exit 0

# End Of Script 

Save the above script as the text file called skim into your ~/bin folder (/home/yourname/bin/skim). In order to use skim it must be marked executable. Open up a terminal session and run the following command:

chmod +x ~/bin/skim 

When you elect to save the module listing ( skim -r <OR> skim -m -r ) the text file it is saved in the ~/Documents folder in the format: Module_Listing.080711.201729.txt and can be viewed at a later time if required. As always I want to hear any comments you may have about the usage of skim. When you read through this message thread, always look to the end for newer versions of skim, should they exist.

Thank You,

# Load the kernel Modules into arrays
#
eval $(sort /proc/modules | awk '{ I=NR-1 ; printf "mnam[%s]=\"%s\" ; msiz[%s]=\"%s\" ; mins[%s]=\"%s\" ; mreq[%s]=\"%s\" ; ", I, $1, I, $2, I, $3, I, $4 }')

# Set a=Total number of modules loaded into the array
a=${#mnam[li]}
[/li]
#
# This reads in the module list, then sorts it by to your text file as named above
#
log_header
sort /proc/modules | awk 'BEGIN {printf "%-7s%-25s%-11s%-5s%s

", "Num", "Name", "Size", "Ins", "Requires"} ; { I=NR")" ; printf "%-7s%-25s%-12s%-5s%s
", I, $1, $2, $3, $4 }' >> $mod_file_name
log_footer

#
# Load the kernel Modules into arrays
#
eval $(sort /proc/modules | awk '{ I=NR-1 ; printf "mnam[%s]=\"%s\" ; msiz[%s]=\"%s\" ; mins[%s]=\"%s\" ; mreq[%s]=\"%s\" ; ", I, $1, I, $2, I, $3, I, $4 }')

# Set a=Total number of modules loaded into the array
a=${#mnam[li]}[/li]```


Why are you running this piece of code (in red) twice?


Also if you want to replace "-" by  "none", you can do it in awk already, so instead of doing that later: 


if [[ “${mreq[$array]}” == “-” ]] ; then
echo “Requires=none”
else
echo “Requires=${mreq[$array]}”
fi



just add this in the awk command(s): 

eval $(sort /proc/modules | awk ‘{ I=NR-1 ; sub(/^-$/,“none”, $4) ; printf “mnam[%s]=”%s" ; msiz[%s]="%s" ; mins[%s]="%s" ; mreq[%s]="%s" ; ", I, $1, I, $2, I, $3, I, $4 }’)



You'll save an if statement.

Ah, the duplicate code was due to a copy after I determined that I needed to run the array load first in order to know the number of installed modules and failed to remove the duplicate code. As for “none” and “-” I thing the dash looks better in the module listing, but using none looked better when using modinfo I think. As always, thanks for your help please_try_again. Here is version 1.12 of S.K.I.M.:

S.K.I.M. - SuSE Kernel Installed Modules, is a bash script file you can copy and paste as a text file named skim into your local ~/bin folder. S.K.I.M. allows you to look at all modules you have loaded into your Linux kernel. You can optionally request information on any installed kernel module and finally, you can save a copy of your module listing into your documents folder. Here is the basic look of that kernel module listing:

You can request info on any loaded module from S.K.I.M. when using the menu mode (skim -m) as show in this example:

S.K.I.M. will display a full command line help listing by entering the help command (skim -h) as this help screen shows:

To use S.K.I.M., just copy the text in the following code block into your favorite text editor (such as kwrite in kde):

#!/bin/bash

#: Title       : skim
#: Date Created: Sun Aug 7  13:03:13 CDT 2011
#: Last Edit   : Sat Aug 13 12:48:00 CDT 2011
#: Author      : James D. McDaniel
#: Version     : 1.12
#: Description : Provides Kernel Module Information
#: Options     : skim [-m -h -r --help]

TITLE="S.K.I.M. - SuSE Kernel Installed Modules V1.12"

declare -a mnam
declare -a msiz
declare -a mins
declare -a mreq

#
# Where do you want to create your module text files?
#
mod_file_location=~/Documents

#
# skim creates a text file, do you want it removed on exit?
# remove_mod_text_file_on_exit=false <OR> remove_mod_text_file_on_exit=true
# the skim -r startup option can override this selection
#
remove_mod_text_file_on_exit=true

#
# Written for the openSUSE forums on Saturday August 13, 2011
#

#
# Copy and Paste the text of this script into a text editor and save 
# it as the file skim in your home area bin folder (~/bin/skim).
# This script must be marked executable to be used.  Please run 
# the following Terminal command: chmod +x ~/bin/skim
# To use skim, open a terminal session and type: skim or skim -h for help
#

# S.K.I.M. function Blocks ****************************************************

#
# This is the standard GPL Statement, leave at the top of the script.
# Just use the command show_gpl after this function for it to be shown.
#
function show_gpl {
echo ""
echo "S.K.I.M. is a bash script file written to be used with openSUSE."
echo "Copyright (C) 2011 by James D. McDaniel, jmcdaniel3@austin.rr.com"
echo ""
echo "This program is free software; you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation; either version 2 of the License, or"
echo "(at your option) any later version."
echo ""
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo ""
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
echo ""
}

#
# We now create a header for the module listing text file
#
function log_header {
echo $TITLE " - Total of $a Modules Loaded" > $mod_file_name
echo >> $mod_file_name
echo "Name     = Shows the internal name of the kernel module installed." >> $mod_file_name
echo "Size     = Refers to the total memory size used by the module, in bytes." >> $mod_file_name
echo "Ins      = Lists how many instances of the module are currently loaded. '0' means unloaded." >> $mod_file_name
echo "Requires = Lists required module(s) that must be present in order to function properly." >> $mod_file_name
echo >> $mod_file_name
}

#
# Log file footer for text file listing
#
function log_footer {
echo >> $mod_file_name
echo "End Of Kernel Module Listing - Report Done on $rdate" >> $mod_file_name
echo >> $mod_file_name
}

#
# S.K.I.M. Help Display Function
#
function help {
tput clear
    cat << EOFHELP
            $TITLE

S.K.I.M. requires no Startup Options, But if you use them, your choices are:

skim         ; Shows Listed Modules
skim -r        ; Shows Listed Modules & Saves Text Report
skim -m         ; Shows Skim Menu
skim -m -r      ; Shows Skim Menu & Saves Text Report
skim -h         ; Shows this help
skim --help     ; Shows this help 

EOFHELP
echo -n "         Press <enter> to read the GPL Statement for S.K.I.M."
read CHOICE
tput clear
show_gpl
exit 0
}

#
# Common S.K.I.M. Exit Tasks
#
function exit_skim {
tput clear
echo $TITLE " - Total of $a Modules Found"
show_gpl
if $remove_mod_text_file_on_exit ; then
  rm $mod_file_name
else
  echo "Your Kernel Module Info was saved in: "
  echo
  echo $mod_file_name
fi
  echo
}

# S.K.I.M. Error & Help *******************************************************

#
# Determine if the folder mod_file_location exists
#
if [[ ! -d "$mod_file_location" ]] ; then
  echo "The Document Folder: $mod_file_location, does not exist!"
  echo "Please create or change this folder name and start $(basename $0) again."
  echo
  exit 1
fi

#
# S.K.I.M. startup options are checked here
#
menu=false
case "$1" in
    -h|--help) help ;;
    -m|-M) menu=true ;;
    -r|-R) remove_mod_text_file_on_exit=false ;; 
esac
case "$2" in
    -r|-R) remove_mod_text_file_on_exit=false ;; 
    -m|-M) menu=true ;;
esac

# S.K.I.M. Create Module Text File ********************************************

#
# Sets the name of the text file where your module info is saved
#
rdate=$(date +%m/%d/%y-%H:%M:%S)
ext=$(date +%m%d%y.%H%M%S)
mod_file_name=$mod_file_location"/"Kernel_Module_Listing"."$ext".txt"

#
# Load the kernel Modules into arrays
#
eval $(sort /proc/modules | awk '{ I=NR-1 ; printf "mnam[%s]=\"%s\" ; msiz[%s]=\"%s\" ; mins[%s]=\"%s\" ; mreq[%s]=\"%s\" ; ", I, $1, I, $2, I, $3, I, $4 }')

# Set a=Total number of modules loaded into the array
a=${#mnam
[li]}[/li]
#
# This reads in the module list, then sorts it by to your text file as named above
#
log_header
sort /proc/modules | awk 'BEGIN {printf "%-7s%-25s%-11s%-5s%s

", "Num", "Name", "Size", "Ins", "Requires"} ; { I=NR")" ; printf "%-7s%-25s%-12s%-5s%s
", I, $1, $2, $3, $4 }' >> $mod_file_name
log_footer

#
# S.K.I.M. Main Menu when a menu is requested. ********************************
#
while $menu ; do
  tput clear
  echo $TITLE " - Total of $a Modules Loaded" 
  echo
  echo "1) View Your Module Listing with Viewer Less - Enter a Q to quit"
  echo "2) Get Info On a Module (View Module Listing First for a Number)"
  echo "Q) Quit $TITLE"
  echo
  echo -n "Please Make Your Selection: "
  read -n1 CHOICE

#
# View Your Module Listing using Less
#
  if [[ $CHOICE == "1" ]] ; then
    less $mod_file_name
  fi

#
# Menu to request module name modinfo to be used
#
  if [[ $CHOICE == "2" ]] ; then  
    tput clear 
    echo $TITLE " - Total of $a Modules Loaded" 
    echo
    echo -n "Enter Module Number for Information and press <enter> [1-$a]: "
    read CHOICE

#
# Check the number entered as valid between 1 and maximum modules loaded
#
    if [[ $CHOICE =~ ^[0-9]+$ ]] ; then
      if [[ $CHOICE -le $a ]] && [[ $CHOICE -gt 0 ]]; then
        let array=CHOICE-1
        cmd=${mnam[$array]}
        echo
        echo -n "$CHOICE) Name=${mnam[$array]}, Size=${msiz[$array]}, Instance=${mins[$array]}, "
    if [[ "${mreq[$array]}" == "-" ]] ; then
      echo "Requires=none"
    else
      echo "Requires=${mreq[$array]}"
    fi
        echo          
    /sbin/modinfo $cmd
        echo 
        echo -n "Press Any Key to Continue: "
        read something
      fi
    fi    
  fi

#
# Exit S.K.I.M. program & output the GPL statement
#
  if [[ $CHOICE == [Qq] ]] ; then
    exit_skim
    exit 0
  fi    
done

#
# S.K.I.M. the menu option was not selected to be here ************************
#
less $mod_file_name
exit_skim

exit 0

# End Of Script

Then, save this text into your home area bin folder as the text file skim (/home/your_name_here/bin/skim). Next, once saved, S.K.I.M. must be marked as executable. Open up a terminal session and run the following terminal command:


chmod +x ~/bin/skim 


To use S.K.I.M., open up a terminal session and just type in skim <OR> skim -h for more startup help details. Please let me know if you have any more questions on using skim.

Thank You,

That’s fine. Then you can use substitute (sub) only in the first awk command, where you define the arrays and not in the second one, where you list the modules. It will do exactly what you want.

I wonder if the many aliases in some modules provide a really useful information.
I could not even post modinfo’s output for the ATI module (fglrx) because it was over 15000 characters. It includes many lines similar to these ones:

alias:          pci:v00001002d000095CFsv*sd*bc*sc*i*
alias:          pci:v00001002d000095CEsv*sd*bc*sc*i*
alias:          pci:v00001002d000095CDsv*sd*bc*sc*i*
alias:          pci:v00001002d000068F2sv*sd*bc*sc*i*
alias:          pci:v00001002d00009446sv*sd*bc*sc*i*
....

Maybe you could simply remove them from the output by using:

/sbin/modinfo $cmd | sed '/alias:/d'

Otherwise, if you care about this info, you’ll have to use more (or less). The output can be very long.

/sbin/modinfo $cmd | more

I do like the following command and it makes sense changing it to me.

/sbin/modinfo $cmd | sed '/alias:/d'

This is line 229 in the skim bash script where the line that said “/sbin/modinfo $cmd” has the following command " | sed ‘/alias:/d’" being added at the end and it removes the modinfo text lines with the /alias:/d included. I made the change to my copy of skim, but not sure if everyone wants to filter this out or not. Thanks so much for the help. I just knew you would have lots of suggestions which is why I decided I wanted to wait till the weekend for you to finish all of your suggestions. The bottom line, without regard to what you might call this script file, you can open up a terminal session, type in skim (or whatever you called it) and get a better kernel module listing that makes it easier to find the module you are looking for and with optional info about that module. If you want a permanent copy, you can request that too. Scripts cost nothing and take up little space, but can help make your life much easier when using Linux.

Thank You,

I’m always glad to help, James, and you know that you do help me a lot too by testing findgrub. :wink:
Here are a couple more awk inlines …

[ul]
[li]displaying currently used modules in red… although I’m afraid you won’t like this one because it uses 2 escape sequences: [/li]

sort /proc/modules | awk 'BEGIN {printf "%-7s%-25s%-11s%-5s%s

", "Num", "Name", "Size", "Ins", "Requires"} ; \
{ I=NR")" ; if ( $3 > 0 ) printf "[b]^[[/b][31;1m" ; printf "%-7s%-25s%-12s%-5s%s[b]^[[/b][37;0m
", I, $1, $2, $3, $4 }' 
  • I replaced the escape character with a carret and a bracket - which is how it looks like - but of course in order for this code to work, you’ll have tho replace it with the escape (that I don’t know how to insert with your editor - with vi, it is CTRL-V followed by Esc in insert mode)

[li]showing only modules which are not currently used:[/li]

sort /proc/modules | awk 'BEGIN { i=0 ; printf "%-7s%-25s%-11s%-5s%s

", "Num", "Name", "Size", "Ins", "Requires"} ; \
{ if ( $3 == 0 ) { i++ ; I=i")" ; printf "%-7s%-25s%-12s%-5s%s
", I, $1, $2, $3, $4 }}'

[li]showing only used modules:[/li]

sort /proc/modules | awk 'BEGIN { i=0 ; printf "%-7s%-25s%-11s%-5s%s

", "Num", "Name", "Size", "Ins", "Requires"} ; \
{ if ( $3 > 0 ) { i++ ; I=i")" ; printf "%-7s%-25s%-12s%-5s%s
", I, $1, $2, $3, $4 }}'

[li]sort modules by usage: [/li]

cat /proc/modules | awk '{ print $3, $1, $2, $4 }' | sort -n \
| awk 'BEGIN {printf "%-7s%-25s%-11s%-5s%s

", "Num", "Name", "Size", "Ins", "Requires"} ; \
{ I=NR")" ;  printf "%-7s%-25s%-12s%-5s%s
", I, $2, $3, $1, $4 }' 

[/ul]

These are all great ideas. Color does not translate well to the document file without a lot more work. I do think that anyone reading this can use your suggestions to further improve and customize their copy if the want to. One item I would like to clarify is what does it really mean when the module in reading a zero instances? Here is one explanation that I found.

4.2.21. /proc/modules

4.2.21. /proc/modules
This file displays a list of all modules loaded into the kernel. Its contents vary based on the configuration and use of your system, but it should be organized in a similar manner to this sample /proc/modules file output:
Note
This example has been reformatted into a readable format. Most of this information can also be viewed via the /sbin/lsmod command.

nfs 170109 0 - Live 0x129b0000
lockd 51593 1 nfs, Live 0x128b0000
nls_utf8 1729 0 - Live 0x12830000
vfat 12097 0 - Live 0x12823000
fat 38881 1 vfat, Live 0x1287b000
autofs4 20293 2 - Live 0x1284f000
sunrpc 140453 3 nfs,lockd, Live 0x12954000
3c59x 33257 0 - Live 0x12871000
uhci_hcd 28377 0 - Live 0x12869000
md5 3777 1 - Live 0x1282c000
ipv6 211845 16 - Live 0x128de000
ext3 92585 2 - Live 0x12886000
jbd 65625 1 ext3, Live 0x12857000
dm_mod 46677 3 - Live 0x12833000

The first column contains the name of the module.
The second column refers to the memory size of the module, in bytes.
The third column lists how many instances of the module are currently loaded. A value of zero represents an unloaded module.
The fourth column states if the module depends upon another module to be present in order to function, and lists those other modules.
The fifth column lists what load state the module is in: Live, Loading, or Unloading are the only possible values.
The sixth column lists the current kernel memory offset for the loaded module. This information can be useful for debugging purposes, or for profiling tools such as oprofile.

I don’t really find the explanation satisfactory for the instance number when it is zero. In fact, I feel that modules that read zero are being used. Perhaps this number goes back and forth in milliseconds from 0 and 1 and then back to 0. And when a module is “unloaded”, where does it reside? When the kernel is loaded, does it just set the modules in a folder and load them when needed? And if so, where is the module list? Is that what we are printing out here? What I would like, is a real explanation for the modules you can read at the top of the list and this one item seems lacking to me. Feel free to expand with your great knowledge on the subject. lol! And before you take offense to that statement, be aware that what I know on the subject would read in the sub-zero -25 area.

Thank You,

No they are not (normally). You can apply this test to any module with 0 instances ($module being the name of the module in the code below) :

modprobe -n -r $module 2> /dev/null && echo "module is not used"

If the module is used, it ouputs a FATAL error (which is redirected to /dev/null in the example above) . But try that (an you’ll see a FATAL error):

modprobe -n -r nvidia

No longer in memory. But whether you can unload modules depends on your kernel configuration.

# grep CONFIG_MODULE /boot/config-2.6.37.6-0.7-desktop
CONFIG_MODULES=y
CONFIG_MODULE_FORCE_LOAD=y
CONFIG_MODULE_UNLOAD=y
CONFIG_MODULE_FORCE_UNLOAD=y
CONFIG_MODULE_SRCVERSION_ALL=y

They are already in folders in the filesystem:

find /lib/modules/$(uname -r)

They get loaded when they are needed.

Yes.

There are many. Just google for “Loadable kernel modules” (LKM).

I guess you do compile Linux (modular) kernels more often than I do. :wink:

So the command “find /lib/modules/$(uname -r)” lists all modules that could be loaded for your present kernel, not just the ones that are loaded, depending on hardware and such. Now the modules I would wonder about are as follows:

1)     acpi_cpufreq             10462       0    -
7)     coretemp                 6542        0    -
8)     cpufreq_conservative     5743        0    -
9)     cpufreq_powersave        1338        0    -
10)    cpufreq_userspace        3618        0    -

Even as I run programs thought to use these, they say 0. This is a confusing items for which I speak. I can change CPU speeds, such as using the cfu script, or look at my cpu temps, which required coretemp, but alas, these all still say 0. I do not understand how that is possible?

Thank You,

Maybe this from the Linux Kernel Module Programming Guide might provide some answers: Linux Kernel Module Programming Guide - Character Device Drivers

If the count is 0, you can unload the module. If you unload the cpufreq*, the options conservative, powersave and userspace will be missing in the cfu script. You’ll have to load the modules manually - or write a function in your script which loads the modules.

You can also load some modules (like network drivers) even if they are used, because the count says 0 too. Of course if you do, you’ll lose the connection to the device.

Maybe this from the Linux Kernel Module Programming Guide might provide some answers: Linux Kernel Module Programming Guide - Character Device Drivers

If the count is 0, you can unload the module. If you unload the cpufreq*, the options conservative, powersave and userspace will be missing in the cfu script. You’ll have to load the modules manually - or write a function in your script which loads the modules.

You can also load some modules (like network drivers) even if they are used, because the count says 0 too. Of course if you do, you’ll lose the connection to the device.

Well, this just says that a module might read zero, but is still being used and may rest unused more than used. Perhaps if a module included a last access time, it might help make more sense and perhaps more system overhead too. I guess I have got as close to understanding this as I will get. Besides adding in color, are there any other useful things we should try to add with this utility? We could add in modprobe for instance to allow the removal or the addition of a module. The only times I have done this is with wireless modules and not so common for me otherwise.

Thank You,