The kernel
What the Linux kernel is, what it does, and how to check its version and parameters.
Cheat sheet
7 commands Printable version-
uname -rkernel version (e.g. 6.8.0-45-generic) -
uname -aversion + architecture + build date -
cat /proc/versionthe same info, from /proc -
cat /proc/cmdlineparameters the kernel was booted with -
dmesg | taillatest kernel messages -
sysctl vm.swappinesscurrent value of a kernel parameter -
ls /bootkernel files (vmlinuz) and initramfs
Overview
The kernel is the core of the operating system: the one program that
directly controls the CPU, memory, devices, and filesystems. Every other
program (including the shell and systemd) reaches it through system
calls — a strictly defined interface, never the hardware directly.
Three things the kernel is responsible for:
- processes — who gets CPU time and when (the scheduler);
- memory — allocation, isolation between processes, swapping (see memory-swap);
- devices and filesystems — drivers (many of them loadable separately, as kernel-modules) and disk access through filesystems.
The kernel isn't the whole operating system: a distribution (Ubuntu, Debian) is the kernel plus system programs, a package manager, and configuration on top of it.
This article is about the kernel as a concept: what it does and how to look
at it. Loading modules, dmesg driver diagnostics, and blacklisting are a
separate article, kernel-modules. Runtime parameters (sysctl) are in
sysctl. The boot stages leading up to starting the kernel are in
boot-grub.
Recipes
3Parameters the kernel booted with
Kernel messages at boot and at runtime
Troubleshooting
4uname -r still shows the old version after apt upgrade
Upgrading the kernel installs new files, but the running kernel is still
the old one until a reboot happens. uname -r shows the new version only
after that reboot.
What's the difference between the kernel and the distribution?
The kernel is one process and a set of drivers; a distribution is the kernel plus system utilities, a package manager, and configuration (see uname for the command, or the glossary's "distribution" entry for the concept).
A driver I need doesn't load
That's almost always about a kernel module, not the kernel as a whole —
see kernel-modules: lsmod, modprobe, dmesg | grep.
I want to change kernel behavior without rebooting
Some parameters change on the fly through sysctl (see sysctl), but not
all of them: some only take effect at boot time (parameters in the cmdline).
Danger zone
1Removing the running kernel
apt remove linux-image-$(uname -r) (or the package that's currently
loaded) can leave the system without a bootable kernel on the next reboot.
Keep at least one previous kernel version around until you've confirmed the
new one is stable (a few days/reboots) — GRUB lists older versions in its
menu precisely so you can fall back (see boot-grub).
Terms
1- distribution
- A maintained collection of a kernel, system programs, packages, and settings, such as Ubuntu. Also appears in: uname, Service, systemd
See also
- kernel-modules — Loading kernel modules, viewing kernel messages, parameters.
- boot-grub — Boot stages, GRUB, systemd targets, emergency recovery mode.
- sysctl — Runtime kernel parameters — reading, changing, making them permanent.
Found an inaccuracy? Report an error in the article