Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Kernel Module File listing script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
BlueSteel
n00b
n00b


Joined: 25 Jul 2006
Posts: 4

PostPosted: Mon Jul 31, 2006 7:31 pm    Post subject: Kernel Module File listing script Reply with quote

Hello.

I made today a little helper script (it is at the very end of this message) that list all the damn kernel modules that I have in my system and to help me to find correct drivers to my hardware.
It creates a module list file of format kernel-`uname -r` into your /etc/modules.autoload.d directory

And no, you don't have to use *just* /etc/modules.autoload.d/kernel-2.6 file everytime you upgrade your kernel.
For example, in my case the file /etc/modules.autoload.d/kernel-2.6.16-gentoo-r13 (my currently running kernel) will work just fine!

Heres what I have in /etc/modules.autoload.d/

drwxr-xr-x 2 root root 312 Jul 31 21:23 ./
drwxr-xr-x 60 root root 4.0K Jul 31 19:02 ../
-rw-r--r-- 1 root root 0 Jul 28 03:59 2
-rwx------ 1 root root 2.4K Jul 31 21:07 gen-module-list*
-rw-r--r-- 1 root root 451 Feb 14 10:08 kernel-2.4
-rw-r--r-- 1 root root 941K Jul 31 21:07 kernel-2.6.16-gentoo-r13

Now, when I upgrade my kernel to next version I will do the usual "make menuconfig (or make oldconfig) && make && make modules_install && make install" stuff.
However, I also add one final step: /etc/modules.autoload.d/gen-module-list

If I don't give any parameters to it it will just recreate the module list for my currently running kernel version (2.6.16-gentoo-r13).
If the file allready exist then it will NOT recreate the file before you have removed your old kernel module list away.

Enough talk.

Let's grap the latest Gentoo Linux sources (emerge gentoo-sources) and do the usual stuff (make menuconfig / oldconfig && make && make modules_install && make install)

Now that the new kernel (2.6.17-r4) has been compiled and all its modules put to /lib/modules/2.6.17-gentoo-r4
don't reboot your computer just yet.

It is time to run gen-module-list :

/etc/modules.autoload.d/gen-module-list 2.6.17-gentoo-r4

(Notice that the Kernel version we give to gen-module-list as a parameter must be exactly the same as the new kernel name found from /lib/modules/ )

It will spit the following:

Kernel module list file: /etc/modules.autoload.d/kernel-2.6.17-gentoo-r4
Kernel module directory: /lib/modules/2.6.17-gentoo-r4

Generating module list file ... please wait.
Done.

Now we have a nice little kernel-2.6.17-gentoo-r4 file that our new and soon to be started kernel will be using (notice that the old kernel-2.6.16-gentoo-r13 can still peacefully co-exist with the new kernel because the boot process will match the WHOLE kernel name, that witch the "uname -r" command gives to you, not just 2.6.
So if you screwed you new kernel configuration but keeped the old one and its kernel module list file safe then you can still boot normally)

The format of the kernel module file is something like this (it is allready sorted):

#
# 3c359
#
#
# filename: /lib/modules/2.6.16-gentoo-r13/kernel/drivers/net/tokenring/3c359.ko
# author: Mike Phillips <mikep@linuxtr.net>
# description: 3Com 3C359 Velocity XL Token Ring Adapter Driver
#
# license: GPL
# vermagic: 2.6.16-gentoo-r13 SMP PENTIUMM 4KSTACKS gcc-3.4
# depends:
# alias: pci:v000010B7d00003590sv*sd*bc*sc*i*
# srcversion: 435B88C0D6E03681F27FABE
# parm: message_level:3c359: Level of reported messages
# (array of int)
# parm: pkt_buf_sz:3c359: Initial buffer size (array of int)
# parm: ringspeed:3c359: Ringspeed selection - 4,16 or 0 (array of int)
#
#
# 3c501
#
#
# filename: /lib/modules/2.6.16-gentoo-r13/kernel/drivers/net/3c501.ko
# author: Donald Becker, Alan Cox
# description: Support for the ancient 3Com 3c501 ethernet card
# license: GPL
# vermagic: 2.6.16-gentoo-r13 SMP PENTIUMM 4KSTACKS gcc-3.4
# depends:
# srcversion: 8CD3F81D09E5728FC6CF8AB
# parm: irq:EtherLink IRQ number (int)
# parm: io:EtherLink I/O base address (int)
#
#

etc .....
and so on ....

All there is left to do is to read the whole file and uncomment those modules witch description section matches your hardware (some module authors have given very little or no description at all !!!)

So for example, if you KNOW that you have NE2000 compatible PCMCIA ethernet adapter but do NOT know which of dozens of modules gives you the right driver then scanning throught this list might give you something like this:

# pcnet_cs
#
#
# filename: /lib/modules/2.6.16-gentoo-r13/kernel/drivers/net/pcmcia/pcnet_cs.ko
# author: David Hinds <dahinds@users.sourceforge.net>
# description: NE2000 compatible PCMCIA ethernet driver
# license: GPL
# vermagic: 2.6.16-gentoo-r13 SMP PENTIUMM 4KSTACKS gcc-3.4
# depends: pcmcia,8390
#

Just uncomment the pcnet_cs and it will load (with some luck and correct parameters) the correct driver for your card the next time you reboot.

The script is provided as is. You can butcher it as much as you like.
I just hope you will find this script usefull

: )

(And if you are still wondering about what arguments to give just type /etc/modules.autoload.d/gen-module-list --help)
Remember:
executing gen-module-list creates module list file for your *currently running* kernel.
executing gen-module-list with some other kernel version name tries to find the corresponding kernel modules from your /lib/modules directory and create a matching kernel-"new kernel version" file.


Sorry about any possible typos. English is not my native language : )

Heres the gen-module-list script:
(SCRIPT BEGINS. CUT FROM THE LINE BELOW)
#!/bin/sh

################################################
# Simple Kernel Module List Generator #
# #
# Version: 1.0 #
# Original author: Stefan Fröberg #
# Lisence: Public domain #
# #
###############################################

# Few more or less usefull variables

MODULE_SUFFIX=".ko"

PATH_BASENAME="/bin"
PATH_ECHO="/bin"
PATH_FIND="/usr/bin"
PATH_MODINFO="/sbin"
PATH_SED="/bin"
PATH_SORT="/bin"

# PROGRAM_BASENAME="${PATH_BASENAME}/basename"
# PROGRAM_ECHO="${PATH_ECHO}/echo"
# PROGRAM_FIND="${PATH_FIND}/find"
# PROGRAM_MODINFO="${PATH_MODINFO}/modinfo"
# PROGRAM_SED="${PATH_SED}/sed"
# PROGRAM_SORT="${PATH_SORT}/sort"

# First I tought to just hardcode the paths of the various programs that this script uses but then I
# decided to just let 'whereis' command to do the searching job.
# Ofcourse, if these programs are found from your path then you can just simply put the appropriate
# name to its place : )

PROGRAM_BASENAME=`whereis -b basename | cut --delimiter=' ' -f2`
PROGRAM_ECHO=`whereis -b echo | cut --delimiter=' ' -f2`
PROGRAM_FIND=`whereis -b find | cut --delimiter=' ' -f2`
PROGRAM_MODINFO=`whereis -b modinfo | cut --delimiter=' ' -f2`
PROGRAM_SED=`whereis -b sed | cut --delimiter=' ' -f2`
PROGRAM_SORT=`whereis -b sort | cut --delimiter=' ' -f2`

# Few helper functions ... to make code look cleaner
usage() {
echo -e "Usage: $0 [--version | --help | KERNEL_VERSION]\n"
}

version() {
echo -e "Simple Kernel Module List Generator\nVersion: 1.0\nMade by Stefan Fröberg\n"
}

error_file_allready_exist() {
echo "ERROR: File ${OUTPUT_FILE} allready exist !!!"
}

# Very rude argument validation

case "$#" in
# Default values
0) OUTPUT_FILE="/etc/modules.autoload.d/kernel-`uname -r`"
KERNEL_MODULE_DIR="/lib/modules/`uname -r`"
if `test -f ${OUTPUT_FILE}`;then
error_file_allready_exist
exit 1
fi
;;
1) if `test ${1} == "--version"`; then
version
exit 0
elif `test ${1} == "--help"`;then
usage
exit 0
elif `test -d /lib/modules/${1}`; then
OUTPUT_FILE="/etc/modules.autoload.d/kernel-${1}"
KERNEL_MODULE_DIR="/lib/modules/${1}"
if `test -f /etc/modules.autoload.d/kernel-${1}`;then
error_file_allready_exist
exit 1
fi
else
usage
exit 1
fi;;
*) usage
exit 1;;
esac

# If everything went Ok we can finally start working ...

echo -e "\nKernel module list file:\t${OUTPUT_FILE}\nKernel module directory:\t${KERNEL_MODULE_DIR}\n\nGenerating module list file ... please wait.";
for i in `${PROGRAM_FIND} ${KERNEL_MODULE_DIR} -xdev -name "*${MODULE_SUFFIX}" -exec ${PROGRAM_BASENAME} '{}' ${MODULE_SUFFIX} ';'|${PROGRAM_SORT}`
do ${PROGRAM_ECHO} -e "\n\n ${i}\n\n" >> ${OUTPUT_FILE} && ${PROGRAM_MODINFO} ${i} >> ${OUTPUT_FILE}
done && ${PROGRAM_SED} -i s/^.*/\#\ \&/ ${OUTPUT_FILE} && echo -e "Done.\n"

##################################################################################
(SCRIPT ENDS)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum