Where to start First steps track · 15 stages
Linux Labs

The kernel

4 min Linux

What the Linux kernel is, what it does, and how to check its version and parameters.

Cheat sheet

7 commands Printable version
  • uname -r kernel version (e.g. 6.8.0-45-generic)
  • uname -a version + architecture + build date
  • cat /proc/version the same info, from /proc
  • cat /proc/cmdline parameters the kernel was booted with
  • dmesg | tail latest kernel messages
  • sysctl vm.swappiness current value of a kernel parameter
  • ls /boot kernel 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

3

Check the version and origin

bash
uname -r                           # version: 6.8.0-45-generic
uname -m                           # architecture (x86_64, aarch64)
lsb_release -a                     # distribution version running on top of it

Parameters the kernel booted with

bash
cat /proc/cmdline                  # what GRUB passed it (see boot-grub)
sysctl -a | less                   # current runtime parameters
sysctl vm.swappiness               # one specific parameter

Kernel messages at boot and at runtime

bash
dmesg -T | less                    # the message ring buffer (human-readable time)
journalctl -k -b                   # the same, via journald, current boot

Troubleshooting

4

uname -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

1

Removing 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.
Loading…