Linux – Are Linux drivers part of the kernel or the rootfs

driverslinux-kernelroot-filesystem

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 ?

Best Answer

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.

Related Question