• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Drivers and the Linux Kernel

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Titan386

Senior Member
Joined
Jun 8, 2002
Most people are familar with the concept of a driver: software which controls a hardware device and allows the system to interface with it. However, the way drivers work in Linux is quite different from some other operating systems, IMO warranting some additional explanation.

Linux is designed to be modular, and therefore, allows for pieces of code to be loaded and unloaded from the kernel while it is running. Those familar with some other OSes may recall the need for these OSes to reboot after making a change to the driver configuration, or after adding or removing a driver. Often in Linux, this is not necessary, thanks to this modular system.

These pieces of code are known as modules, and are loaded in the kernel with either the insmod or modprobe commands, and removed with the rmmod program. You might wonder why two commands exist to add modules. There is a notable difference between the two: insmod does not check for dependencies, simplying attempting to load a module, while modprobe does check for dependencies, and loads modules on which the module given by the user depend. modprobe can also do a lot more than insmod (including the removal of modules). To learn more, read the manual file on modprobe, which can be displayed by typing man modprobe at a terminal. Generally, it is best to use modprobe over insmod.

All three commands work very similarly: they load (or unload) the module given as a command line argument. For example:
insmod nvidia
modprobe nvidia

These would both load the NVidia kernel module (needed for 3D acceleration on NVidia GPUs) into the running kernel. To remove it, you would run:
rmmod nvidia

Because of the multiuser nature of a GNU/Linux system, and the importance of the kernel, modules can only be added or removed by the superuser (aka root). Therefore, insmod, modprobe, and rmmod reside in /sbin/.

When compiling a Linux kernel, one will notice that for each driver or kernel feature, there are three options: No (the feature will not be a part of the kernel), Yes (it will be compiled into the kernel, where it will always exist and cannot be removed), and Module (which will compile the feature as a module). Module is usually the best choice to use when you're unsure if you'll need the feature or not. This way, you can always load it when you need it, and if you never need it, it won't sit in the kernel taking up RAM.

There is a lot more to be said about modules, so I highly suggest reading this excellent guide:
http://tldp.org/HOWTO/Module-HOWTO/

This section is particularly useful, as it gives lots of info on individual modules:
http://tldp.org/HOWTO/Module-HOWTO/individual.html

Comments, suggestions, and questions are always welcome :)
 
Back