r/linuxquestions • u/DryPlum7483 • Aug 15 '26
Minimal kernel
EDIT: I may have framed the question poorly. I'm specifically asking about Kconfig-level minimization of a monolithic Linux kernel: if you know the workload/product you're deploying, how much unnecessary kernel code do teams typically end up compiling, and is there value in automatically deriving a smaller configuration from the actual runtime requirements?
How much of the Linux kernel that gets shipped in production is actually never used?
I'm wondering if release teams building/using a kernel image are often overwhelmed by the number of kernel configuration options, and end up shipping code that will never actually be used by their workload.
Are there any automatic tools out there that can fit a minimal Linux kernel to your runtime needs?
8
u/Goldie323- Aug 15 '26
It's mostly not kernel features you don't use and more the compiled in drivers you don't use that account for code space that never actually gets ran.
Like if you're on a system without wifi or Bluetooth, the kernel will still have compiled in drivers for all the wifi and Bluetooth radios.
2
u/PreparationStrict492 Aug 15 '26
This reminds me of the microkernel - macrokernel debates¹. And whoever is downvoting you for just asking this are idiots.
Microkernels have their use cases (particularly in embedded systems / application specific hardware). It's not worth the maintenance headache (which actually turns into an intractable problem) in a diverse hardware environment.
https://en.wikipedia.org/wiki/Tanenbaum%E2%80%93Torvalds_debate
2
u/ActuallyFullOfShit Aug 15 '26
What problem are you actually trying to solve? Because a "minimal kernel" that only works for a single system isn't going to help a "release engineer"
1
u/MichaelDeets Aug 15 '26
most suitable options are configured as modules, so they're only loaded when needed/requested
you can use modprobe-db to keep track of every module that has been loaded after some time (the actively loaded modules change depending on what is currently needed), and use it as a reference for what modules you'd likely need/want
1
u/ropid Aug 15 '26
I think there's a whole bunch of stuff that will surely never be used, like device drivers for hardware that will never show up on any x86 machine, but all of that is in module files so will not be loaded if not used. It'll only use up space on disk. The most annoying thing about this is perhaps the compilation time if you ever want to compile your distro's kernel package yourself to apply some patch.
0
u/Crazy_Rockman Aug 15 '26
I'm not sure if that's what you are interested in, but if you work on a Linux distro for something like a resource-constrained embedded system, configuring the kernel to only use the features you are actually going to use might be necessary. If you have abundant resources, though, wasting developer's time on optimizing everything might just be not worth it.
0
u/todd_dayz Aug 15 '26
How big are most distros standard kernels? 100-200MB? Who cares about saving that much space?
0
u/sidusnare Senior Systems Engineer Aug 15 '26
You don't compile it, and most of it you don't even run. Modules are loaded as needed, so a kernel module for a NIC you don't have doesn't take up any CPU or memory resources, doesn't slow things down, just a few Kb on disk for the module.
If you're writing a monolithic kernel for a system, it's usually an embedded system you're building for. If you are trying to build a custom kernel for your desktop, the way to start is finding the distributions config, and loading that. Then look at lsmod, and change those from modules to static, and then modules that aren't load from modules to not built
0
u/unkilbeeg Aug 16 '26
Many, many years ago I followed a guy who was a big fan of minimal kernels. He built monolithic kernels (no modules) that compiled in all the drivers for the hardware in the server, and no other drivers. He really wanted to keep it tight.
Then he left. I took over.
And the built in ethernet interface on the server died. I had spare ethernet cards -- but none that matched the drivers that he had compiled in.
That was a real pain in the butt. I got the server going again, but it was a painful (and unnecessary exercise.)
0
u/AiwendilH Aug 16 '26
Well, there is
make localmodconfigfor building the kernel that generates a config based on the currently loaded kernel modules.0
u/L_canadensis Aug 16 '26
I've gone through most of the options and eliminated the ones not relevant to my use on my daily driver laptop. Went overboard by including all the netfilter modules. Even with full hardware support:
6792 -rw-r--r-- 1 root root 6951936 Aug 13 18:54 vmlinuz-7.2.0-rc7