r/linuxquestions • u/[deleted] • Dec 05 '21
Does the Linux Kernel have all the devices drivers by default on it?
I was messing around with an Xbox360 USB controller on Fedora and decided to try and play some games with it, I plugged it in and it just worked fine with no problems, then I tried a more "obscure" controller, a Logitech f710 and it also worked so I started wondering, does the Kernel already have the drivers for every single supported device/printer/scanner etc etc etc? Isn't that kind of bloated? Why would I want to have the drivers to 10000000 different things I will never use? Is there any way to make it more modular?
55
u/rbmichael Dec 05 '21
Coming from a windows or macos world it might sound bloated, yeah, since in the old days you might remember installing windows driver disks that could be dozens or hundreds of MB. But on Linux nay of that extra bloat or marketing crap (or .Net framework, etc.)isnt needed. So the drivers might just be a few dozen kB at most for a controller to work right.
41
u/EddyBot Dec 05 '21 edited Dec 05 '21
it also worked so I started wondering, does the Kernel already have the drivers for every single supported device/printer/scanner etc etc etc?
linux is a monolithic kernel, this is what they do
Isn't that kind of bloated?
in it's compiled state a recent stable kernel is at around ~130 MB file size
also very old driver get removed if nobody actually uses them
also the comment from /u/bcrochet is spot on here, the kernel devs really try their hardest to make the linux kernel as clean and abstract (in a programming sense) as possible
Why would I want to have the drivers to 10000000 different things I will never use?
so you don't need to hunt down every abstruse driver and everything will work out of the box
the kernel modules also aren't loaded unless you actually need them
Is there any way to make it more modular?
by compiling it yourself, which I would not recommend to anyone who needs to ask these questions
I do this myself with help of modprobed-db and get to 22 MB file size down but I need to compile it again if I ever want to add a new kernel module back
my main benefit here is that this way I cut down the compiling time to 10 minutes instead of over 40 minutes
9
u/LJAkaar67 Dec 05 '21
can you help me understand what a monolithic kernel is, especially in the context of loadable kernel modules?
27
Dec 05 '21 edited Dec 11 '21
Monolithic kernels generally run drivers at the kernel level of access. They tend to include many things including drivers and network stack. Micro kernels move that stuff into user space. That way if they crash it’s easier to recover. The price you pay is that you tend to have to use slower communications mechanisms between kernel and drivers running as user land processes
-7
u/404galore Dec 05 '21
This is a simple question to google
3
u/JaesopPop Dec 05 '21 edited Oct 02 '25
Open small curious evening friends then the then answers bright bright!
-2
u/404galore Dec 05 '21
Or he could google it
3
u/JaesopPop Dec 05 '21 edited Sep 23 '25
Books yesterday learning minecraftoffline science across food music family about?
-1
u/404galore Dec 05 '21
I’m not crying I’m just saying it would be faster to google it
3
u/JaesopPop Dec 05 '21 edited Sep 20 '25
Community gather quiet quick calm family science bright near wanders weekend.
0
0
Dec 05 '21
[deleted]
34
u/MasterPatricko Dec 05 '21
They aren't open source and are not part of Linus's kernel tree.
Any time anything changes only nvidia can update the code so it works. With drivers that are open source and part of the upstream kernel, anyone can fix issues.
17
u/RAMChYLD Dec 05 '21
Yep, same with the Broadcom drivers.
Anytime something changes (ie kernel API), the driver breaks. I've witnessed this happen firsthand.
5
9
2
1
Dec 05 '21
Because NVIDIA are proprietary, and the Linux kernel is GPLv2 - which requires that any changes or modifications be GPLv2 the NVIDIA drivers cannot be included into the kernel. Instead what can be included is a shim that allows the proprietary drivers to load. - usually this shim isn't included unless the driver is needed, so it's bundled with the proprietary drivers instead, and must be patched into the kernel.
This has the unfortunate effect that when compiling your own kernel, and if you need NVIDIA, you have to patch the kernel with the shim, so it can load the driver - most Distros already have this patch installed, so the driver can just be installed directly.
9
u/ForbiddenRoot Dec 05 '21
Why would I want to have the drivers to 10000000 different things I will never use?
"Have the drivers" in this case only means the distros include the kernel modules and in some cases additional proprietary drivers. Both take up negligible disk space, and it's worth bundling them all so that you can install a distro on a variety of hardware (and also so that things like live USBs work pretty much on any computer).
This is not any different from Windows btw, which too comes with a wide range of drivers as part of the installation image. The installation image for Windows is much larger in fact than most Linux distros and it does not even include all the user space software (office suites, graphics editing programs, development tools etc) like Linux distros do.
Is there any way to make it more modular?
It already is a modular approach. Most drivers are compiled as kernel modules. The distros may come with a large number of modules but not all of them get loaded unless you have the hardware which requires that driver module.
5
u/TiagoTiagoT Dec 05 '21
To add to what others have said; while there are a lot of drivers included, there are also many types of hardware that have standardized protocols, different models, from different manufacturers, all talking the same "language" (there are often exceptions though, even within a given category).
That's particularly common with the more common categories, specially with stuff that use USB
4
u/alexforencich Dec 05 '21 edited Dec 05 '21
I was just going to post pretty much this same thing myself. There are a LOT of standard interfaces that devices can implement. Common things like mice, keyboards, flash drives, NVMe devices, and even USB and SATA controllers don't require manufacturer-specific drivers as there are standard interfaces for these devices. This makes things a lot easier for everybody - the manufacturer does not need to write and maintain drivers for their devices, operating system vendors just have to implement a handful of standard interfaces, and end users don't need to go browsing shady websites looking for drivers. The flip side is that using standard interfaces is restrictive, so for certain classes of devices (for example, GPUs) just about everything is totally custom and device - specific.
Some specific examples: XHCI, NVMe, USB device classes (CDC, HID, PTP, MTP, MSC, UMS, UVC, etc.)
A huge amount of stuff that you plug in to your computer simply does not require a manufacturer-specific driver.
6
Dec 05 '21
Is it bloated to have heat in your car? It uses a bit of gas, sure, but it’s way more comfortable. Same with drivers. The storage space is negligble.
4
u/AffectionateLettuce1 Dec 05 '21
Ackchyually.......
It's your AC that eats a drip or two of your gas (extra friction added to the belt to drive the compressor). Heat just hooks into the main coolant loop, hence why it takes a bit in the dead of winter.
2
3
u/grem75 Dec 05 '21
Is there any way to make it more modular?
It is modular, most desktop distros just ship with all of the common modules you'll need. Modules aren't loaded until you need them. They are small and only take hard drive space if you're not using them.
Also, most driver modules cover multiple devices, sometimes hundreds or thousands of similar things. Something like that Logitech pad probably supports standard HID protocols, so it is less obscure than the Xbox one that is proprietary.
3
Dec 05 '21
Ok, for a start, many of the drivers are generic drivers that support a whole class of hardware - usually with those, a single line can be all it takes for a new piece of hardware - this makes size negligible.
Drivers are split into modules called kernel modules, these modules can be loaded /unloaded on the fly, so therefore even if all the drivers are included, they aren't all loaded at runtime - the kernel only loads what is needed to use the hardware you want - to look at what kernel modules you can type lsmod into a terminal and hit enter - you might notice some that you recognise, and many more that you won't, but rest assured these are probably most likely generics such as usbhid or uvcvideo either that or they just have weird names - you can look up any module names on the web to see what they do. The benifit of loading kernel modules on the fly is obviously to save resources, among other things
I don't reccomend that you worry about stripping unneeded modules out of the kernel, unless you are running Linux on an old device where memory/storage or both are at a premium, as someone else said, the kernel is only a hundred and fifty or so megabytes, and while you can strip it to approximately 20MB - it's not really worth the effort, unless you're running off of a sub-gigabyte sized boot drive.
6
u/Awh153 Dec 05 '21
I mean sure but hard drive space is mostly irrelevant now. Also windows is like 3x as big as linux.
-3
u/RAMChYLD Dec 05 '21
False. NVMe SSDs are still deathly expensive and prices are getting worse due to those chia miners.
0
Dec 05 '21
[deleted]
4
u/darkgreyocean Dec 05 '21
Any source for the info?
2
Dec 05 '21
Download the git repo (with --depth=1) of linux, systemd, gnome, sudo and gnu coreutils and you have the codebase of a minimal fedora (without third party apps, aka bloat). For windows, i can send you this: https://www.reddit.com/r/programming/comments/bcg58u/windows_10_source_code_over_05_tb_source_code/
1
1
1
u/makhno Dec 06 '21
Separate but related question: What's the minimum disk space required to install Linux vs Windows?
1
Dec 06 '21
Here we can take 2 approaches:
Minimal linux system (either alpine, barebones LFS or barebones Gentoo), as those are just a functional linux system (kernel + bootloader + almost no userland) VS regular windows install
Regular fedora install VS regular windows install
In the first option the linux installation could be less than 1 or 2 GBs depending on the OS you choosed. In the later likely linux would be less than 10-15GB. Windows afaik is around 20-30GB
0
2
u/pikecat Dec 05 '21
It depends on your distribution of Linux. The kernel can have all of the drivers in it, or not. Drivers can also be included as modules that are loaded as needed. You may find that drivers for the most common hardware is included and that obscure ones are not. Which are decided by your distro.
Unused drivers just take up space.
2
Dec 05 '21
It’s not bloated because almost all of them are modules and only loaded if hardware is present. Also disk space is almost free these days. Also no distribution has every driver. It works well overall and better than windows
2
u/peppeok12 Dec 05 '21
This Is not bloat. I love Linux even because its compatible with EVERYTHING and It doesnt lose support for hardware with the time as It happens on Windows
2
u/PCChipsM922U Dec 05 '21 edited Dec 05 '21
Not all, but most commonly used ones, yes.
And this varies on a distro-to-distro basis. One distro might have some drivers included in the kernel (or as extra kernel modules), another distro might not.
Printers are super easy to set up nowadays on Linux, even simpler than Windows :).
The drivers are mostly generic, meaning they work on a bunch of devices. Making the kernel more modular just means that it'll have to pull updates from the main repo to make your device work on your rig. This has to be automated, like in Windows, but some people prefer to update/upgrade their repos and their libraries/drivers WHEN they choose, not have the OS do it automatically every time a new driver is needed (most Linux users are power users, so yeah... they like having control over their rigs, not the other way around). Making the kernel more modular (having a small kernel with less modules/drivers) also makes it incompatible with hardware during install. Yes, it can download the required modules from the repo during install, but not everyone has internet access during install, or even after install. Some people just want a particular Linux install to do a job and just not have internet access, that's it. Linux is an OS that was primarily used as a server OS back in the day and people loved the way that they can configure everything, leave it as it is and have it working 3, 5, 6 years from the day they launched it into production and still having it working without a hitch. That was the main selling point for Linux back in the day, and that kinda stuck afterwards as well. Times might have changed and more and more people (regular users) are using Linux nowadays, but the power user aspect of Linux and the point of the user having control over the hardware and software has always stayed the same, so basically, having more in the kernel nowadays is not such a problem. It used to be a problem 10, 20 years ago when storage was expensive, but it's really cheap nowadays, so there's no point in having thousands of different modules available in the repo/repos and having a small kernel with only basic SATA/IDE, USB and graphics drivers. Some distros have this approach, but most of them, no.
2
u/idl3mind Dec 05 '21
The drivers are usually compiled as modules, so they are loaded when needed. If you have a system you know what will need a specific driver all the time (RAID controller for example), you can compile the driver into the kernel instead of as a module. The advantage of compiling modularly is that it allows you to have a smaller memory footprint and it makes the kernel more universal across differing systems.
1
u/ArtyIF Dec 05 '21
almost. most linux drivers are already integrated into the kernel, but something like nvidia or hp printer ones aren't
1
u/lealxe Dec 05 '21
Well, if you are compiling the kernel for yourself (needing some non-default options, such as 16-bit applications under Wine or whatever), you can build only those modules you need. But in general you'll have all the drivers installed, yes. Except for some proprietary or out of tree ones.
1
Dec 05 '21
When you plug-in kernel sees a generic device plugged into an IO port (like a keyboard). A device node will be created for it and it’s the user space that does meaningful IO on that device node. So from kernel’s perspective it doesn’t need a whole new driver for that.
1
Dec 05 '21
In most distributions, most of the drivers are modules which are loaded on demand when devices are detected. Only essential and commonly used components are built into the kernel and always in memory. This is a choice people make when building the kernel from source.
One reason why it's good for drivers to be part of the kernel source code is that changes in the kernel can require changes in drivers. Those drivers which are part of the kernel get changed as the kernel changes, while other drivers need their maintainers to notice this and perform the needed changes.
There are plenty of drivers which aren't part of the kernel. Some are released as separate packages, like Nvidia's proprietary drivers. When drivers relate to a specific computer system, often a fork of the kernel source is created for that device, and the drivers are only present in that fork, causing that device to require a special kernel built from that source. Many drivers for smartphones and other Android devices are like this.
0
u/tomkatt Dec 05 '21
Going by the nightmare I went through last week installing an Edimax USB wifi adapter... No. No it doesn't.
16
Dec 05 '21
[removed] — view removed comment
4
u/AffectionateLettuce1 Dec 05 '21
A monolithic kernel, though faster than a microkernel, has the disadvantage of lack of modularity and extensibility. On modern monolithic kernels, this has been solved by using kernel modules. A kernel module (or loadable kernel mode) is an object file that contains code that can extend the kernel functionality at runtime (it is loaded as needed); When a kernel module is no longer needed, it can be unloaded. Most of the device drivers are used in the form of kernel modules.
See: https://wiki.archlinux.org/title/Kernel_module
& https://linux-kernel-labs.github.io/refs/heads/master/labs/kernel_modules.html
106
u/bcrochet Dec 05 '21
One point not yet made... A lot of the driver code in the kernel has been well abstracted so to add another device might only mean adding a few lines of code.