What Is the Linux Kernel?

CSS code on a screen

 Sai Kiran Anagani/Unsplash

To casual users and less-than-hardcore fans, Linux is an operating system. To purists, however, the title "Linux" is reserved for the kernel that powers the operating system. If you’re curious as to what the Linux kernel is, let’s answer that question with an eye to the new user.

Modes

Before we explain what a kernel is, it’s important to understand the terms “user mode” and “kernel mode”. User mode is when executing code has no ability to directly access hardware or reference memory. To gain access to hardware and memory, code running in user mode must delegate instructions to system Application Programming Interfaces (APIs). Kernel Mode is when executing code has unrestricted access to all hardware and is reserved for the most trusted functions of an operating system.

What Is a Kernel?

Every operating system has a kernel. Windows, macOS, iOS, Android, Chrome OS, and Linux each have a low-level system that's responsible for interfacing all applications with the physical hardware of the computer. Without the kernel, none of your applications would be able to make use of the physical computer; apps like Firefox, Chrome, LibreOffice, MS Office, or Outlook wouldn’t work. The kernel is also responsible for allowing processes to exchange information using what is called Inter-Process Communication (IPC).

There are (generally speaking) three types of kernels:

  • Monolithic kernels: these kernels encompass the CPU, memory, IPC, device drivers, file system management, and system server calls. It's also responsible for handing off free system memory to applications. These types of kernels are typically better at accessing hardware and multitasking.
  • Microkernels: Microkernels take a minimalist approach and only manage the CPU, memory, and IPC.
  • Hybrid kernels: Hybrid Kernels have the ability to decide what they want to run in either User or Kernel Mode. Although this provides the best of both worlds, it requires much more from the hardware manufacturers to create drivers that serve to interface between running code and hardware.

Linux uses an open source, Monolithic Kernel, whereas macOS and Windows both use Hybrid Kernels. The Linux kernel was conceived in 1991 by Linus Torvalds. To this day, Mr. Torvalds continues to be the lead developer on the Linux kernel, while developers from all over the world contribute to the Linux kernel. In fact, it's estimated that nearly 10,000 developers, from more than 1,000 companies, have contributed to the Linux kernel (since tracking began in 2005).

Where Is the Kernel?

If you open a terminal window and issue the command ls /boot, you’ll see a file called vmlinuz-VERSION (Where VERSION is the release name or number). The vmlinuz file is the actual bootable Linux kernel, and the “z” is to indicate the kernel is compressed; so instead of vmlinux we have vmlinuz.

The listing of the /boot directory.
The listing of the /boot directory.

Within that /boot directory are other important kernel files, such as initrd.img-VERSION, system.map-VERSION, and config-VERSION (Where VERSION is either a name or release number). These other files serve the following purposes:

  • initrd: used as a small RAMdisk that extracts and executes the actual kernel file.
  • system.map: used for memory management, prior to the kernel loading.
  • config: instructs the kernel on what options and modules to load.

Modules

Without modules, the kernel wouldn’t be much use. Modules effectively turn on the drivers necessary to communicate with hardware without consuming all of your system memory. Modules also add functionality to the kernel, such as communicating with peripherals, managing file systems, security, etc. It's possible to list, add, and remove modules to the kernel with the following commands:

  • lsmod will list all of the currently loaded kernel modules.
  • insmod will load a kernel module into the running kernel.
  • rmmod will unload a module from the running kernel.

So you see, with the help of some simple commands, the Linux kernel can be quite flexible.

The Current Kernel

As of this writing, the stable Linux kernel is 4.18.5, but not all Linux distributions will include the latest kernel. In fact, the updated Elementary OS desktop distribution runs kernel 4.15.0-30. What does that number mean? In the case of the latest kernel on Elementary OS, it means:

  • 4 is the Major version
  • 15 is the Minor version
  • 0-30 is the revision

It is also possible to download different versions of the Linux kernel from kernel.org and compile it yourself. The compilation of the Linux kernel is a task best left to those who really know what they're doing. An improperly compiled kernel can render a system unbootable. So, unless you're ready to dive into the challenging task of compiling code on this level, use the default kernel that ships and updates on your distribution of choice.