5

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?

2
  • Seeing I can't tag stuff on this site yet, please add a "gentoo" tag, otherwise you'll keep getting debian answers. May 29, 2009 at 10:28
  • that comment you just made is why im considering a switch to *bsd Jun 15, 2009 at 11:34

9 Answers 9

3

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.

2

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:

amd74xx
emu10k1
emu10k1-gp
forcedeth
i2c-nforce2
ohci1394
sata_nv

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

2
  • I believe Gentoo is using portage, which is different from that of debian and debian variants. The command is "emerge"
    – setzamora
    May 29, 2009 at 10:22
  • Sadly, discover isn't in portage :( Feb 7, 2012 at 21:14
2

You can use "lsmod" to know the kernel modules

1
  • 2
    this only shows modules currently running, not really useful when trying to trim the fat Jun 15, 2009 at 11:33
2

Show drivers/modules in use:

lspci -v
1
  • 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. Feb 7, 2012 at 21:09
1

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 
1

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 ipv6.so!

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

1
  • 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 Feb 7, 2012 at 21:12
1

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.

1
  • In portage as sys-apps/hwinfo ; sys-apps/lshw performs similar Feb 7, 2012 at 21:13
0

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."

0

lspci should also help you.

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