KC7MM Wiki

Amateur Radio with KC7MM

User Tools

Site Tools


linuxusernet:inside_linux:kernel_layer

A Look Inside Linux series

A series of short topics on how Linux works and how to make it work the way you want it to, which I present during the weekly sessions of the Linux User Net. The target audience is Hams who are new to Linux and want to know more about it, as well as experienced Linux users who can learn more about their chosen operating system. These are my notes for the presentations. (Russ, KC7MM)

8. The Linux Kernel

Layer 1 of the Linux system – its core.

Introduction

Linux is amazingly popular. It runs on probably billions of computers, both real and virtual. The Internet is built on Linux. Cloud computing is built on Linux. Every form of computer, from tiny embedded systems to the most powerful supercomputers, can run Linux. How is that possible?

It all comes down to the heart of the system, the Linux kernel – how it's designed and how it's developed. Let's look at those.

Design

  • The kernel design is modular. It's comprised of many individual components that work together to perform the many and varied kernel functions. That makes it easy to customize for varied use cases.
  • It's structured so that, when the source code is compiled into a working program to run on specific hardware, only the components appropriate for that hardware are included. The resulting executable is thereby optimized to meet the exact needs of the system it is to run on – no more, no less.
  • By way of example, the kernel for a small embedded system, such as a sensor array, would be very compact. A desktop distribution – such as Linux Mint – would have much larger kernel, built to accommodate the wide variety of hardware devices that users might employ.
  • By way of contrast, the MS Windows kernel is inseparable from the rest of the operating system. You have no possibility of modifying it in any way, or using it for any purpose not provided by Microsoft.

Development

  • The Linux kernel is developed under the GNU General Public License (GPL), version 2. That makes it available for anyone to use, for free. All of its source code can be downloaded from the kernel.org Web site and used for whatever purpose you desire.
  • The kernel is developed independently by the Linux Kernel Organization, under the control of Linus Torvalds. It is not beholden to any commercial or government entity, and thus is free to be developed as a general-purpose tool that is extremely flexible.
  • The software that runs on top of the kernel – applications, user interfaces – is created by others. The kernel itself doesn't constitute a working computer system. Instead, it is specifically designed to provide a sound base upon which any type of system can be built.
  • Anyone can contribute code to the kernel project, which then undergoes a thorough vetting process to determine whether it will be included in a future release. This enables Linux users who have a need for some particular kernel capability to get it; these contributions constitute one of the primary drivers of kernel development.

In short, the kernel is flexible, free, and open.

What it does

The kernel is the heart of any operating system. It is a translation layer, which interacts directly with the hardware on one side, and application software on the other. It makes the system's hardware available to for use by applications, by means of a uniform interface.

In Linux, that is implemented by treating every system resource as a file that can be read from and written to. (More on the Linux file system at a future date.)

How it does it

It uses interfaces

The kernel runs directly on the computer's hardware. That is, it connects directly to the interfaces created by hardware components' embedded firmware.

Its purpose is to provide programs with a uniform interface that they can use to interact with computer hardware. This gives them access to system resources without having to know anything specific about them, such as their memory address or how they operate – or even where they're located. “Interact with” means moving data to and from them.

The Linux kernel creates a single virtual file system, and all hardware is mounted as a file in that system. Programs perform read and write operations on those files in order to communicate with the hardware.

It runs device drivers

Device drivers run as part of the kernel. A device driver is a bit of software that provides the common Linux read/write interface for specific hardware.

Writers of device drivers for Linux tend to target chip sets that are commonly used in hardware, rather than specific brands and models. That way, a single driver can be used for any hardware that uses it, regardless of manufacturer. Also, kernels for Linux distributions often come with drivers for commonly-used devices already installed. That's why, for example, when you plug in a new USB device, it so often “just works” without having to download and install a device driver specifically for it.

It runs programs

The kernel knows how to run programs. The basic operations are:

  • Read the object code from some form of memory, usually a file on storage media.
  • Send the operating instructions it contains, along with associated data, to the CPU for execution.
  • Route data coming from the CPU after commands have been executed.
  • Handle Input/Output operations for data transfer.

It manages memory

A major aspect of running programs is allocating system memory to them. The kernel has to:

  • Give programs the memory they require to run properly.
  • Prevent interference between programs. That is, make sure one program doesn't use memory that's in use by another.

What we need to know

We've seen what the kernel does. Now we'll look at what we users should know about it in order to configure and maintain our systems. This is just a quick list – more detailed coverage will come later.

  • Kernel maintenance. Linux distros stay current by issuing updated versions that include bug fixes at a minimum, and possibly additional capabilities. Unless you have a specific reason not to, I recommend that you upgrade your system's kernel whenever a new version is proffered. After upgrading, a reboot is required in order to load the new kernel – one of the rare occasions that rebooting is necessary.
  • Device drivers. Should you find yourself needing to load a device driver for some new piece of hardware, there are a few things to keep in mind.
    • Linux device drivers are kernel modules. That means they can be installed or removed at runtime without necessitating a reboot. The modprobe command is used for this.
    • As I mentioned, device drivers commonly are built-in, that is, loaded at compile time.
      • If you install some new hardware and it doesn't have a device driver installed for it, it's possible that the kernel your distro uses was compiled before your hardware was available. You might be able to get a built-in driver by installing a newer version of the kernel.
  • Processes. Be aware that programs run in processes.
    • Every program runs in one or more process. As system administrator, you can control processes with command line utilities:
    • Processes can be identified with the ps command, and monitored with top.
    • Misbehaving processes can be terminated with the kill command. This is handy when a GUI program locks up – just drop to a shell and kill its process.

Summing up

The Linux kernel is the heart of any Linux system. It makes it possible for a Linux-based operating system to run on any given computer hardware.

It is, in fact, the one part of the system that is clearly “Linux”. Almost all the software that runs on top of the kernel is developed independently by others. (Android is an extreme example.)

You generally will use a kernel provided by someone else – usually a distribution – but you have the option of compiling your own.

Keep your system's kernel up to date.

You have the option of installing other versions of the kernel in order to get functionality not provided by the one currently in use.

Return to series index

linuxusernet/inside_linux/kernel_layer.txt · Last modified: 2022/03/01 16:19 by KC7MM