4

I have been working on a board with an embedded ARM processor. To get it to boot I have to add a bootloader, a linux kernel and a disk image containing the root file system. This disk image is available on the internet for the target board (ZedBoard).

After compiling the kernel with all necessary drivers activated, I have found out that many drivers are available in /lib/modules/kernel_number.

I am a little bit confused as to how this whole thing works. Are drivers loaded by the kernel ? if so why are they already a part of the rootfs ? or does the kernel overwrite them with the ones compiled in it ?

7

It's pretty straight forward, although we should distinguish between "driver" and "module". A driver may or may not be a module. If it is not, then it is built into the kernel loaded by the bootloader.

If it is a module, then it is in a filesystem hierarchy rooted at /lib/modules/[kernel-release].1 Note that it is possible to boot a kernel together with a small preliminary root filesystem (an "initramfs") which may contain such a repository as well. This is normal with generic kernels so they can decide what modular drivers they need to load in order to access the real filesystem, since if they can't do that, they can't access any modules there.

Are drivers loaded by the kernel ?

Yes.

if so why are they already a part of the rootfs ?

Where else should they be stored before they are loaded? The kernel doesn't contain the rootfs within itself (except WRT some forms of initramfs), it's just the gatekeeper.

does the kernel overwrite them with the ones compiled in it ?

No. If you compile a driver in, the kernel will not bother to check /lib/modules for it. I'm not sure what happens if you then ask it explicitly to load such a driver anyway, presumably it will just say no.


1. As Celada hints at with $(uname -r), this release string is not necessarily just the version number. You can have multiple kernels with the same version and different release strings therefore separate module stores. Likewise, you can have multiple kernels with the same release string, therefore the same module store.

4

In Linux, most drivers can be either built statically into the kernel, or built as modules. This is a choice you can make when the kernel is being configured for compilation. They will only appear in /lib/modules/$(uname -r) if they are built as loadable modules.

Typically, for general purpose systems, especially for pre-compiled kernels made available as part of Linux distributions, the strict minimum set of drivers will be built statically in, and as much as possible will be built as modules. This allows each user's system to load only the necessary modules, without knowing in advance what they are.

Kernels for embedded systems are often built with a lot more drivers built-in, because the kernel is being built for a system with a very specific set of unchanging hardware and the system integrator knows in advance what it is. Nevertheless, many drivers are often left to be loaded as modules, especially for "extra" hardware that may or may not be present like USB devices.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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