5

I just read about the way Linux deals with hardware drivers. Apparently most of the hardware drivers come pre-compiled into the Linux Kernel. I have some of questions about that...

If the Linux kernel contains hardware drivers for almost every hardware device out there, And if a laptop that runs on Linux has only a certain number of hardware devices, Then what about all the redundant hardware drivers that the Linux Kernel has? Is it not a waste of resources to keep all these drivers in the kernel and to keep it up and running in the system even while we are not using them?

  • 2
    Not all drivers are run at boot, but only those that have related hardware. – Pilot6 Dec 22 '16 at 15:24
  • 2
    device drivers are compiled into modules which are only loaded into the kernel if the relevant hardware is present. – solsTiCe Dec 22 '16 at 15:30
  • 1
    To those that put the question on hold, it was neither over broad nor are there many good answers. I understood the question quite well. Please remove the hold. – Kurt Fitzner Dec 25 '16 at 22:01
  • 1
    Uday Kumar: Your post has two parts. I suggest removing #2, about power efficiency--it's is a separate question. You could post it separately (but please search first--even if you don't find an answer, you might narrow it down into something more specific). Part #1, however, seems like a perfectly well-scoped, on-topic question to me. @MarkKirby How are you counting six? Are you reading "what about all the redundant hardware drivers that the Linux Kernel has ?" and "Is it not a waste of resources[...]" as separate questions? That paragraph looks like a single well-phrased question to me. – Eliah Kagan Dec 29 '16 at 15:37
  • 1
    @MarkKirby I really don't think the first three numbered questions in the original post were separate questions. They constituted exposition and clarification of question #1. That they were all answered like a single question, without a need to address them separately, reinforces my belief that they're asking narrowly about one thing. (In contrast, the last question is separately addressed in that answer, and not in depth, and I think it's best removed from this post.) Uday Kumar: I still think we can reopen this if (what's now numbered as) #2 is edited out. – Eliah Kagan Dec 30 '16 at 11:52
9

First some history. In the earlier days of Linux, device drivers were indeed compiled directly into the kernel. In fact, it's possible still to compile drivers directly in and many kernels may still have some very common drivers included this way. The way it worked was the generic kernel shipped with the early distributions like SLS or Slackware had virtually every driver the kernel supported compiled directly into it so it would work on the widest possible variety of hardware possible. Even then, it wasn't possible to put them all in because some of them are mutually incompatible. Then, after you got your system installed, you would build your own kernel, carefully going through the configuration to make sure you included the correct drivers for everything your computer had. Sometimes you had to manually edit header files in the driver to include support for oddball hardware - an Ethernet card that used a particular chipset used that chipset's drivers, but sometimes there were funny ways it was implemented. Then you'd compile, install, and hopefully after a reboot you then had a custom kernel built for just your computer. Lean and optimized. In reality, you generally repeated this process several times including things you missed, adding support for a filesystem you forgot, or tweaking the settings in some way. Rinse and repeat.

Those days are, thankfully, long past. The kernel has, for a very long time, supported loadable modules. These are kernel drivers compiled so as to become a type of shared library that can be loaded or unloaded on demand. Now the way a kernel boots is you have the kernel file itself and a small compressed filesystem (look at initramfs on Wikipedia) that has in it all the kernel modules that kernel supports. The kernel loads, it finds its initial filesystem and then it can start loading all the drivers it needs.

That little bit of history is skipping a lot of work and sweat along the way. In between using all compiled-in drivers in one huge monolithic kernel and having a fully automated driver loading system we have today were all the steps along that path where we had modules that had to be explicitly loaded, semi-automatic loading for some, etc etc.

So, since modern kernels demand load the vast majority of the drivers they need, there are no significant amount of redundant hardware drivers taking up resources in the kernel of any modern Linux distribution.

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.