You are not logged in.

#1 2011-06-12 15:24:47

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,600
Website

discover which kernel modules correspond to your specific hardware

Here is a bash script to probe your hardware, then come up with a list of kernel modules you may wish to compile into a custom kernel tailored for specific machine!

#/bin/bash
# Script by graysky based on some code found in http://www.kroah.com/lkn/ chapter 7
# Purpose: probe system for devices controlled by modules and list them via name
# Email: graysky <echo Z3JheXNreUBhcmNobGludXgudXMK | base64 -d>

##### edit this to point to the path containing your kernel source
kernelsource="/path/to/kernel/source"
#####
clear && echo "Probing... wait a sec"
[ -f /tmp/list ] && rm -f /tmp/list
for i in `find /sys/ -name modalias -exec cat {} \;`; do
 /sbin/modprobe --config /dev/null --show-depends $i 2>/dev/null >> /tmp/list ;
done 

# clean up list
rev /tmp/list | cut -f 1 -d '/' | rev | sort -u | sed -e ':a;N;$!ba;s/\n//g' -e 's/.ko.gz//g'  > /tmp/list2

[ -f /tmp/list3 ] && rm -f /tmp/list3
for i in $(cat /tmp/list2); do
 echo "---------------  $i  ---------------" >> /tmp/list3
 echo " " >> /tmp/list3
 find $kernelsource -type f -name Makefile | xargs grep $i | grep CONFIG_ | sed -re 's/^.+\$//' >> /tmp/list3
 echo " " >> /tmp/list3
 sed -i -re 's/(.+)=.+$/\1/' -i -e 's/[()+]//g' /tmp/list3
done

rm -f /tmp/list /tmp/list2

echo "Done!"
echo "To see a list of potential kernel config options for your specific hardware"
echo "less /tmp/list3"

Sample output:

---------------  ata_generic  ---------------
 
CONFIG_ATA_GENERIC      

---------------  crc-itu-t  ---------------
 
CONFIG_CRC_ITU_T        
 
---------------  drm_kms_helper  ---------------
 
CONFIG_DRM_KMS_HELPER 
 

---------------  ehci-hcd  ---------------
 
CONFIG_USB_EHCI_HCD     
 
---------------  evdev  ---------------
 
CONFIG_INPUT_EVDEV      

Last edited by graysky (2011-06-12 15:32:18)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2011-06-12 15:34:55

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: discover which kernel modules correspond to your specific hardware

You can refactor the initial probing and cleanup into a one liner:

find /sys/devices -name modalias -exec sort -zu {} + |  xargs -0 modprobe -aRS "${kernver:-$(uname -r)}" | sort -u

It should be noted that this only scans your system buses. This is not a comprehensive list, and modules to create your root FS are completely ignored here.

Offline

#3 2011-06-12 15:53:43

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,600
Website

Re: discover which kernel modules correspond to your specific hardware

Good points, FI.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#4 2011-06-12 20:42:14

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: discover which kernel modules correspond to your specific hardware

Took a stab at refactoring this, since it interests me... came up with:

#!/bin/bash
#
# uses information gathered from /sys and a kernel source directory to
# determine what kernel config options are needed
#

kernver=${1:-$(uname -r)}
kernelsource=/home/noclaf/build/kernel26-rampage/src/linux-2.6.39.1

if [[ ! -f $kernelsource/Kbuild ]]; then
  printf "error: \`%s' doesn't exist or isn't a valid kernel source directory\n" "$kernelsource"
  exit 1
fi

# scan system buses
IFS=$'\n' read -r -d '' -a mods < <(find /sys/devices -name modalias -exec sort -zu {} + |
  xargs -0 modprobe -aRS "${kernver:-$(uname -r)}" | sort -u)

# include root device filesystem
mods+=("$(findmnt / -uno fstype)")

# grab mdadm info if its available
if [[ -x $(type -P mdadm) ]]; then
  mods+=($(mdadm -Esv /dev/[hrsv]d* /dev/{ida,cciss,ataraid,mapper}/* |
    sed -n 's/.*level=\([^ ]\+\) .*/\1/p' |
    sed 's/\<raid[456]\>/raid456/g' | sort -u))
fi

# scrape the kernel source for CONFIG_ options
find "$kernelsource" -name Makefile -exec grep -ZFf <(printf '%s.o\n' "${mods[@]}") {} + |
  grep -Eoz 'CONFIG_[[:upper:][:digit:]_]+' | sort

Last edited by falconindy (2011-06-12 21:12:43)

Offline

#5 2011-06-12 21:07:23

Jelle
Member
From: Netherlands
Registered: 2011-01-30
Posts: 84

Re: discover which kernel modules correspond to your specific hardware

FI, this is what I get:

error: `2.6.39-ARCH' doesn't exist or isn't a valid kernel source directory

Chances are I'm overseeing something, it's been a long day...

Offline

#6 2011-06-12 21:11:09

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: discover which kernel modules correspond to your specific hardware

Modify the kernelsource path....

Offline

#7 2011-06-13 07:17:05

Jelle
Member
From: Netherlands
Registered: 2011-01-30
Posts: 84

Re: discover which kernel modules correspond to your specific hardware

Doh! Working...

Offline

#8 2011-06-13 15:13:38

rwd
Member
Registered: 2009-02-08
Posts: 664

Re: discover which kernel modules correspond to your specific hardware

What is the difference with your  modprobed_db ?

Last edited by rwd (2011-06-13 17:13:06)

Offline

#9 2011-06-13 19:33:16

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,600
Website

Re: discover which kernel modules correspond to your specific hardware

@rwd - that script keeps a log of what you have probed.  This script (and the one modded by falconindy) interrogates your hardware to see which modules should be loaded.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB