TIP: Find out Linux kernel drivers/modules being used by hardware devices on your system
Most of the advanced Linux users like to custom compile their own kernels so that they can remove all the fat (non-essential stuff) that by default is compiled or built as modules into the stock kernel from Linux distribution vendor. For example, if you install Debian Lenny (5.0) which comes with 2.6.26 kernel, you will see that almost everything is compiled either into the kernel or built as modules thus unnecessary increasing the size of the kernel.
So suppose you decide to compile/build your own custom kernel by only including the device drivers that are required by your hardware device on your system/computer. Now the problem is that how do you know which drivers are being used by which devices, so that you can only include them in your custom kernel.
There are two ways to do this:
Method 1: lspci
“lspci” is a very powerful utility to get device information from your system. To install lspci do the following:
# apt-get update
# apt-get install pciutils
Now give the following command:
# lspci -k
Output:
00:00.0 RAM memory: nVidia Corporation MCP61 Memory Controller (rev a1)
00:01.0 ISA bridge: nVidia Corporation MCP61 LPC Bridge (rev a2)
00:01.1 SMBus: nVidia Corporation MCP61 SMBus (rev a2)
Kernel driver in use: nForce2_smbus
Kernel modules: i2c-nforce2
00:01.2 RAM memory: nVidia Corporation MCP61 Memory Controller (rev a2)
00:02.0 USB Controller: nVidia Corporation MCP61 USB Controller (rev a3)
Kernel driver in use: ohci_hcd
Kernel modules: ohci-hcd
00:02.1 USB Controller: nVidia Corporation MCP61 USB Controller (rev a3)
Kernel driver in use: ehci_hcd
Kernel modules: ehci-hcd
00:04.0 PCI bridge: nVidia Corporation MCP61 PCI bridge (rev a1)
00:05.0 Audio device: nVidia Corporation MCP61 High Definition Audio (rev a2)
Kernel driver in use: HDA Intel
Kernel modules: snd-hda-intel
00:06.0 IDE interface: nVidia Corporation MCP61 IDE (rev a2)
Kernel driver in use: AMD_IDE
Kernel modules: amd74xx, ide-pci-generic, ata_generic
00:07.0 Bridge: nVidia Corporation MCP61 Ethernet (rev a2)
Kernel driver in use: forcedeth
Kernel modules: forcedeth
00:08.0 IDE interface: nVidia Corporation MCP61 SATA Controller (rev a2)
Kernel driver in use: sata_nv
Kernel modules: ide-pci-generic, sata_nv, ata_generic
00:09.0 PCI bridge: nVidia Corporation MCP61 PCI Express bridge (rev a2)
Kernel driver in use: pcieport-driver
Kernel modules: shpchp
00:18.0 Host bridge: Advanced Micro Devices [AMD] K8 [Athlon64/Opteron] HyperTransport Technology Configuration
00:18.1 Host bridge: Advanced Micro Devices [AMD] K8 [Athlon64/Opteron] Address Map
00:18.2 Host bridge: Advanced Micro Devices [AMD] K8 [Athlon64/Opteron] DRAM Controller
00:18.3 Host bridge: Advanced Micro Devices [AMD] K8 [Athlon64/Opteron] Miscellaneous Control
Kernel driver in use: k8temp
Kernel modules: k8temp
02:00.0 VGA compatible controller: nVidia Corporation GeForce 8500 GT (rev a1)
Kernel modules: nvidiafb
Now the above output is very useful because it first shows you all the PCI devices attached to your system and then tells you what kernel modules (device drivers), shown in green color, are being used by them.
Method 2: lsmod
Give the command:
# lsmod
Output:
Module Size Used by
binfmt_misc 13580 1
nfsd 248360 13
lockd 68560 1 nfsd
nfs_acl 7552 1 nfsd
auth_rpcgss 47520 1 nfsd
sunrpc 197480 11 nfsd,lockd,nfs_acl,auth_rpcgss
exportfs 8704 1 nfsd
ppdev 11656 0
lp 14724 0
autofs4 24200 0
ipv6 288328 51
battery 16904 0
powernow_k8 17156 1
cpufreq_userspace 8452 0
cpufreq_conservative 11784 0
cpufreq_stats 9120 0
cpufreq_powersave 6400 0
cpufreq_ondemand 11792 1
freq_table 9344 3 powernow_k8,cpufreq_stats,cpufreq_ondemand
fuse 53184 1
it87 28952 0
hwmon_vid 7296 1 it87
loop 19468 0
snd_hda_intel 434904 0
snd_pcm_oss 41760 0
snd_mixer_oss 18816 1 snd_pcm_oss
snd_pcm 81672 2 snd_hda_intel,snd_pcm_oss
snd_seq_dummy 7428 0
snd_seq_oss 33152 0
snd_seq_midi 11072 0
snd_rawmidi 26784 1 snd_seq_midi
snd_seq_midi_event 11904 2 snd_seq_oss,snd_seq_midi
snd_seq 54304 6 snd_seq_dummy,snd_seq_oss,snd_seq_midi,snd_seq_midi_event
snd_timer 25744 2 snd_pcm,snd_seq
snd_seq_device 11668 5 snd_seq_dummy,snd_seq_oss,snd_seq_midi,snd_rawmidi,snd_seq
snd 63688 9 snd_hda_intel,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_seq_oss,snd_rawmidi,snd_seq,snd_timer,snd_seq_device
parport_pc 31016 1
parport 41776 3 ppdev,lp,parport_pc
soundcore 12064 1 snd
snd_page_alloc 13072 2 snd_hda_intel,snd_pcm
k8temp 9216 0
button 11680 0
i2c_nforce2 10752 0
i2c_core 27936 1 i2c_nforce2
evdev 14208 3
ext3 125072 3
jbd 51240 1 ext3
mbcache 12804 1 ext3
sg 36448 0
sr_mod 19652 0
sd_mod 29376 3
cdrom 37928 1 sr_mod
ide_disk 16512 3
usb_storage 94528 0
ata_generic 10116 0
sata_nv 27528 3
libata 165472 2 ata_generic,sata_nv
scsi_mod 160760 5 sg,sr_mod,sd_mod,usb_storage,libata
dock 14112 1 libata
floppy 61672 0
ide_pci_generic 9220 0 [permanent]
forcedeth 54032 0
amd74xx 13448 0 [permanent]
ide_core 128284 3 ide_disk,ide_pci_generic,amd74xx
ehci_hcd 36108 0
ohci_hcd 25092 0
thermal 22688 0
processor 42304 2 powernow_k8,thermal
fan 9352 0
thermal_sys 17728 3 thermal,processor,fan
The above command gives you a comprehensive list of all the Linux kernel modules (essential and optional) that are being currently used by your system.
Now you can easily search by the modules names (shown in green in Method1 or the ones listed in Method 2) when you do your make xconfig or make menuconfig to compile a custom Linux kernel.
To search in:
make xconfig - Edit->Find or Ctrl+F
make menuconfig - Press "/" key
That’s it. You can now simply decide to either include the above drivers into the kernel (Y) or you can include them as modules (M) and can produce a lean and mean kernel.
Note: Of course you will need to include some additional modules which are not listed as a part of lspci above like filesystem modules (like Ext3, Ext2, etc).If you don’t include a filesystem module then chances are your kernel will fail to boot. However Method 2 will list those (see ext3 in the Method 2 output) and you can include them in your kernel.
Happy compiling!

Free Email Subscription









Leave a Reply