Your Linux distro or even the stock Linux kernel comes with all thinkable drivers for all those hardware that they supported. Most of them are preselected by default (base on hardware architecture) to cover a wide palette of hardware.
However, if you are going to compile a Linux kernel only for your system, you should select/include only those modules that have something to do with your system. By cutting down the default kernel configuration you will save time, memory and will make your system faster.
How could you find out what drivers are need it by your system? Well, finding which Linux module is needed for your hardware is not that hard.
If you have already a functional system or if you can boot a Live Linux CD then all you have to do is to look into the Linux system filesystem (sysfs) and to determine which device is using what driver.
For instance, to determine what driver is my network card using, first I need to know the network interface (eq. eth0, wlan0, etc) I want to find what where does the symlink /sys/class/net//device/driver/module point to.
In my case if I run the command ls against the path specified earlier I get the relative path to the driver module for my network card (where =wlan1):
user@rpi-gentoo ~ $ ls -l /sys/class/net//device/driver/module
/sys/class/net/wlan1/device/driver/module -> ../../../../module/ath5k
As you can see the driver needed by this device is called ath5k. To setup the kernel to include this driver all I have to do is to search a configuration parameter named CONFIG_%ATH5K% (where % means one or more characters).
You should not be surprised if you will find more than one parameter with the pattern shown above because there could hundreds devices from that vendor. For example, the following configuration parameters contain the pattern show earlier:
If you want to understand what means any of those drivers I suggest you to look them up on Linux Hardware Database (lhwdb.org). The query string for any kernel configuration parameter is:
Note: the CONFIG_ prefix in the example above is stripped, so if the kernel parameter is named CONFIG_parameter you should use only the parameter part in the lhwdb.org query (or just go to lhwdb.org and use the damn search box :o).
Ok, so you've found out what is the driver name for you network card, right? But there could be at least 10-20 different drivers and finally, just to determine the kernel configuration name you have to search the content of at least 1600 different kernel Makefiles. It could be done automatically, though:
find -type f -name Makefile|sort -u > $FLIST
for f in $(find /sys/ -type l -name driver 2>/dev/null) ; do
test -e $f/module "amp;"amp; basename `readlink $f/module`
done|sort -u >$TMP
for m in $(cat $TMP);do
echo -e "e[33;1;31m[$m]e[0m"
for f in $(cat $FLIST);do
grep -io "(CONFIG_.*$m.*)" $f
done|sed -e 's/^.*(//g;s/).*$//g'
rm -f $TMP $FLIST
The output of the code above run on my system looks like this (but it could look different on your system):
I searched on lhwdb.org and I've determined what represents each of these drivers and I've decided that those written with bold are the ones I need.
To include these and only these drivers on my Linux kernel, all I have to do is to step in each class of "Device drivers" (the lhwdb.org tells you even the kernel menus where to find these configuration parameters) and to select only those parameters that match with those shown by the output of the script above.
Final note: The method shown above it's just the tip of the iceberg since it covers the process of finding the core drivers for the system. In order to determine each tiny driver used by each tiny device you might have, I would recommend reading the "Linux kernel in a Nutshell" by Greg Kroah-Hartman, which presents more techniques regarding this topic.
Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.