Summary

The Linux kernel is the beating heart of every Linux installation. We look at where it came from, what its purpose is and why, without the kernel, there would be no Linux.

The Story Behind the Linux Kernel

Angered by Unix adopting a commercial license, theGNU Projectstarted to write their own Unix lookalike operating system in 1983.

In 1987, theMINIX operating systemwas released. This was a bare-bones Unix-like operating system, used as a working example in a computer science textbook. MINIX was licensed for non-commercial use only.

Counting the lines of code in the Linux kernel repository.

By 1991, the GNU Project had created many of the command-line tools of a Unix-like operating system, but it hadn’t produced a kernel. The kernel is the central controller of an operating system. It sits between the hardware and all other software, managing resources and many other critical tasks.

Linus Torvalds was introduced to MINIX as a computer science student. Annoyed by the MINIX license model, and wanting to learn to program the 80386 CPU in his personal computer, he set about writing his own kernel.

Listing the files in the /bopot directory, showing that the vmlinuz file is a symbolic link to the actual kernel image file.

Development took place on MINIX, using the GNU C compiler. By September 1991, Torvalds' kernel, combined with the GNU core utilities, functioned as a working operating system.

The GNU Project and the Linux Kernel required each other to deliver something functionally meaningful, prompting suggestions that Linux should be referred to as GNU/Linux. Today, Linux distributions contain much more than the GNU tools and the Linux kernel and, whether fair or not, it’s the term “Linux” that has stuck.

Using the uname command with the -r option to see the kernel version.

Different Kernel Architectures

The Linux kernel is amonolithickernel. It’s mainly one large program, but it closely interacts with other, distinct, programs such as drivers and kernel modules. The kernel, drivers, and modules all run inkernel space, a dedicated and restricted region of memory that is strictly out-of-bounds to other, regular, processes, which run inuser space.

Another approach to kernel design, and one favored by the author of MINIX,Andrew S. Tanenbaum, is themicrokernelarchitecture. A microkernel is a very small kernel running in kernel space, with its supporting processes running in user space. Tannenbaum’s criticism of the design of the Linux kernel triggered the famousTannebaum-Torvalds debateof 1992.

Using cat with the /proc/version file to discover the kernel version.

As a size comparison, the MINIX 3 kernel hasabout 12,000 lines of codein it. The Linux kernel 6.12.1 has almost 40 million lines.

That’s a rough figure, because it includes everything in the repository, such as licenses, READMEs, and makefiles, not just source code.

Listing the loaded kernel modules with the lsmod command.

Ahybrid kernelcontains a cherry-picked combination of features from both the monolithic and microkernel architectures. The macOS kernel,XNU, is a hybrid kernel combining features and code from theMachandFreeBSDkernels.

The Linux Kernel Files

Typically, the kernel is a file called vmlinuz, located in the /boot directory.

The Unix kernel was called “unix.” Following suit, the Linux kernel was called “linux.” The “vm” was appended when support for virtual memory was added, and the “x” was replaced with a “z” when the kernel image wascompressed, or gzipped.

Using wc and lsmod to count the number of kernel modules.

Sometimes, the vmlinuz file is asymbolic linkto the actual kernel file. This can be useful, because the full filename often contains version and build identifiers that are lost when you rename it to vmlinuz.

You can also see the kernel version by using the uname command, with the -r (kernel release) option.

Using modinfo to examine the details of a single kernel module.

Or you may look at the contents of the /proc/version pseudo-file.

What Does the Linux Kernel Do?

The Linux kernel, like all kernels, manages system resources so that processes get a share of CPU time and RAM. It also handles system calls, and controls access to hardware, such as permanent storage devices, graphics cards, and the networking stack.

Resource Management

With finite reserves of RAM and CPU time, it’s impossible to service all the requests of all process for all users, all the time. The kernel has to manage the requests so that all processes have their requests serviced. To help with this, processes are given a priority, with higher priority tasks getting more CPU time than lower priority tasks. You can use the renice commandto alter the nice valueof a process.

The kernel also has routines to create and terminate processes and tasks, and switching execution between processes and threads.

Input and Output

The Linux kernel provides access to persistent and non-persistent storage. As well as avoiding conflicts and imposing security through permissions, the kernel hides the low-level implementation of the storage device and file systems from processes. The kernel provides a set of system calls that applications use to request actions and responses from the kernel.

System Calls

System calls are the requests processes make to the kernel for actions that only the kernel can conduct. Usually, a process makes a system call through a wrapper function in the language the process has been written in. The wrapper might be a function in a linked library or a runtime environment.

Device Management

The kernel allows programs to interface with a wide variety of devices that can be connected to, or fitted within, a computer. This includes devices such as hard drives, network interfaces, and graphics cards. Linux Kernel Modules (LKMs) are the most common method of implementing these interfaces.

Linux Kernel Modules

Linux kernel modules (LKMs, also called loadable kernel modules) are small programs that the kernel can load at runtime. They’re an ideal way to provide drivers for hardware, interfaces to file systems, and other system features such as security extensions.

To see the LKMs your kernel is using, use the lsmod command.

The kernel on this test computer is using 67 modules, which is fairly low. On another machine I checked, the figure was 138.

You can get a more detailed view of a single module by using the modinfo command and supplying the name of the module you’re interested in.

Why Does the Kernel Matter?

Without a kernel, an operating system simply cannot function. And without the kernel that was started as a student project in Helsinki, way back in 1991, we wouldn’t have Linux. And Linux is used the world over,in many surprising ways.