Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say, I have a default Gentoo install with all the modules (e.g. device drivers) compiled. From this point, is there an easy way to exclude the unused modules the next time I recompile the kernel?

share|improve this question
Seeing I can't tag stuff on this site yet, please add a "gentoo" tag, otherwise you'll keep getting debian answers. – Kent Fredric May 29 '09 at 10:28
that comment you just made is why im considering a switch to *bsd – theman_on_osx Jun 15 '09 at 11:34

You can use "lsmod" to know the kernel modules

share|improve this answer
this only shows modules currently running, not really useful when trying to trim the fat – theman_on_osx Jun 15 '09 at 11:33

Show drivers/modules in use:

lspci -v
share|improve this answer
lspci -k, will show you all of your pci hardware, and which modules are being used for that hardware. emerge sys-apps/pciutils for lcpci. – James Broadhead Feb 7 '12 at 21:09

make localmodconfig and make localyesconfig (introduced in 2.6.32, which was released in December 3, 2009) will select the modules needed to load the modules in use.

More info.

Note that this does not take into account modules that were loaded once, but are currently unloaded. ArchLinux has a modprobed_db thing that workarounds this, I don't know whether Gentoo has one as well.

share|improve this answer

if we were going to get into technicalities, i would say you could just unload those modules, and then you would not need to recompile. However, I think you meant "to include only drivers to my specific hardware". In that case, I would suggest:

dmesg | less

look through that and see what hardware details you can extrapolate. Then, when you go to compile the kernel, look through all the components and see if it makes a mention to your hardware. After rebooting, check to make sure all the hardware works.

In archlinux, there is a bash script called [hwd][1], i assume it would work on gentoo (perhaps a bit of hacking required), but it will tell you about what you got under the hood. This is my work computer:

[theman@work]# hwd -s
HARDWARE DETECT ver 5.5 (simple mode)
Kernel     : 2.6.29-ARCH
CPU & Cache: Processor 0: Intel(R) Pentium(R) Dual  CPU  E2200  @ 2.20GHz 2194MHz, 1024 KB Cache
Processor 1: Intel(R) Pentium(R) Dual  CPU  E2200  @ 2.20GHz 2194MHz, 1024 KB Cache

Sound(a)   : 82801G ICH7 Family High Definition Audio Controller module: snd-hda-intel 
Video      : GeForce 8400 GS server: Xorg (vesa)  
Driver     : xf86-video-vesa   module: - 
Monitor    : Generic Monitor  H: 28.0-96.0kHz V: 50.0-75.0Hz
Mouse      : Logitech, Inc. Marble Mouse (4-button)  xtype: IMPS2 device: /dev/input/mice
HDD        : 82801GB/GR/GH ICH7 Family SATA IDE Controller module: ata_piix 
USB        : 82801G ICH7 Family USB UHCI Controller #4 module: uhci_hcd 
USB2       : 82801G ICH7 Family USB2 EHCI Controller module: ehci_hcd 

Ethernet   : RTL8139/8139C/8139C+ module: 8139too 
Network    : No wireless card

Menu       : Main menu: hwd
All        : Detect all hardwares: hwd -e
X sample   : Generate X sample: hwd -x
share|improve this answer

One some distributions there's also a nice nifty tool called hwinfo, which gives you lots of useful information about your hardware.

To get more to know about the kernel modules, lspci and lsmod always have done a good job for me.

share|improve this answer
In portage as sys-apps/hwinfo ; sys-apps/lshw performs similar – James Broadhead Feb 7 '12 at 21:13

I use the discover package in debian to figure out what kernel modules I could possibly load. Specifically:

apt-get install discover
discover --data-path=linux/module/name|sort|uniq

For my amd dual core desktop with an nvidia chipset I get:


Here's a short essay on hardware detection in linux, including some text on using discover.

share|improve this answer
I believe Gentoo is using portage, which is different from that of debian and debian variants. The command is "emerge" – eradicus May 29 '09 at 10:22
Sadly, discover isn't in portage :( – James Broadhead Feb 7 '12 at 21:14

If you are recompiling the kernel. The best thing to do is to know your hardware well using the method presented by theman_on_osx. List all your components. You just have to uncheck / exclude the modules (that aren't needed) from the menu (i.e. if you are recompiling it via make menuconfig / make xconfig).

You can also unload modules that are loadable on the fly using "rmmod."

share|improve this answer

lspci should also help you.

share|improve this answer

There is a shellscript in "Linux Kernel in a nutshell" by GKH, which does this by approximation. The script is freely downloadable from the books website and hasn't got a copyright message, so I assume I can post it here.

for i in `find /sys/ -name modalias -exec cat {} \;`; do
        /sbin/modprobe --config /dev/null --show-depends $i ;
done | rev | cut -f 1 -d '/' | rev | sort -u

The scripts output is a list of module your hardware needs to function. It does not list modules that are needed to make certain software work, like!

@Greg: if you don't want this posted like this, I'll remove it ;-)

share|improve this answer
This assumes that modules for the hardware are already available, which makes it of limited use for kernel configuration. Still, that caveat about software kernel requirements is golden – James Broadhead Feb 7 '12 at 21:12

protected by MadHatter Mar 22 '13 at 8:14

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.