How can a linux kernel be so small?

Yes. If you strip them down (compile/make modules only things that you need), compress the kernel (optimize for size)... it'll result in such a small kernel. You can make an even smaller ones, for targeted system. Like I know my PC, I know my stuff. So I'll just compile what I need. Like my own SATA drivers, driver for USB, etc. Nothing else. No webcam, no old IDE drives, nothing.

Also: The bigger ones you encounter are the WHOLE kernel (which one never needs to use). Even the desktop ones contains (most of the times, as modules) a LOT OF unneeded stuff. But newbies expect that every kind of hardware they plug-in will just work.

(Note that, the modules won't get loaded until they are needed. There are 3 states:
[ ] - Won't get compiled, won't be part of your kernel.
[M] - Will be compiled as a module.
(You can modprobe it, or your system will auto-load it when it's needed.
Depends on the system, userland.)
[X] - It'll be compiled into the kernel AND will be present - always.

Distros with small kernel:

  • Tiny Core Linux, Micro Core Linux, 12MB Linux GUI Desktop, Live, Frugal, Extendable
  • Puppy Linux Community Home - Getting Started

Early Linux distributions such as Tom's Root-Boot, MuLinux, Diet-router, (the now defunct) LOAF and many others now departed, all fit a working Linux system on one or two 1.44 MB diskettes.

The Linux kernel has grown but it is modular: kernel modules are loaded as needed. Thus it is still possible to produce a Linux distribution with a very small footprint.

See: Kernel Size Tuning Guide - eLinux.org

If you read Linux_tiny.pdf you will see this

  • historic 0.99pl15 kernel: Slackware 1.1.2, 1994: 301K
  • Fedora Core 2: 1.2M
  • SuSE 9.1: 1.5M
  • 2.6.5-tiny1 test config: IDE, ext2, TCP, NIC: 363K

The default kernel configuration is configured to support as many hardware as possible. A non-stripped kernel with default configuration resulted in a size of 1897996 kB (including kernel + modules). When stripping many unnecessary drivers and options (why would I need a HP module if I own a Clevo notebook), it resulted in a size of 892892 kB which is a size reduction of 53% compared to the stock kernel.

When installing the kernel modules, append the INSTALL_MOD_STRIP=1 option. This will strip all debugging symbols and reduced the size by 92% for me (from 892892 kB to 69356 kB). Note this will only affects modules to be installed and not the kernel (vmlinuz) itself:

make INSTALL_MOD_STRIP=1 modules_install

From Documentation/kbuild/kbuild.txt:

INSTALL_MOD_STRIP
--------------------------------------------------
INSTALL_MOD_STRIP, if defined, will cause modules to be
stripped after they are installed.  If INSTALL_MOD_STRIP is '1', then
the default option --strip-debug will be used.  Otherwise,
INSTALL_MOD_STRIP value will be used as the options to the strip command.

Tags:

Linux

Kernel