Any computing device be it a PC, smartphone, or tablet is made up of both hardware and software components. The software does not directly communicate with the hardware components. There needs to be a layer of software that lies in between the software level and hardware level for the communication between the two layers to happen. This is where the kernel comes in.
In this tutorial, we take a deep dive to understand the kernel and the role it plays in a Linux system.
What is kernel in Linux OS
The core of a Linux operating system is the kernel. It serves as the main gateway between a computer's hardware and its operations. System calls are made to the Linux kernel by various components of the operating system to instruct real hardware to do certain tasks.
To brief the history of the Linux kernel, Linus Torvalds developed the Linux Kernel in 1991. Since then, it has undergone continuous development; the most recent version is 6.0.6. In addition to many other devices, it is utilized in PCs, laptops, cell phones, and tablets.
Types of Kernel
There are five main kernel types used in Linux distributions.
- Monolithic Kernel - The simplest and most prevalent sort of kernel is called the monolithic kernel. It supports all connected devices and contains all of the essential operating system features. Here, the OS and kernel share memory space and are suitable for situations when security is not a major concern. Fast process execution. There is no user- or kernel-specific memory space.
- Microkernel - The monolithic kernel has been simplified into the microkernel. As monolithic kernels, they are uncommon. They just contain the components and tools necessary for the system to run. As a consequence, the kernel gets smaller, quicker, and consumes less memory. The implementation of the user and kernel services occurs in two distinct locations. The separate user space and kernel space reduce the size of the kernel and operating system.
- Hybrid Kernel - The hybrid kernel is the most common kind. Compared to monolithic kernels, they offer more services than microkernels. It is a combination of a monolithic kernel and a microkernel. It takes modularity from microkernels and speed from monolithic kernels.
- Nano Kernel - These are the smallest kinds of kernels. There isn't very much software running in the hardware's privileged mode. They are primarily utilized in resource-constrained embedded systems or gadgets.
- Exo Kernel - Exo kernel functionalities are limited. It can only do process management and resource handling. These are suitable for use for customizing software for certain applications. Exo kernels are made for usage on mobile devices.
Several significant architectural features are implemented in the Linux kernel. The kernel is divided into a variety of separate subsystems, both at a high level and at a low level. We can divide the kernel architecture mainly into two parts.
- User space
- Kernel space
User space is responsible for executing programs and applications. User Space is unable to have direct access to the hardware and memory. It uses kernel space to gain access to the hardware.
User-space processes and applications can only make system calls to specific portions of memory. Crashes that occur in user mode can be recovered because of full protection. The GNU C library offers a technique for moving applications from user space to kernel space.
Kernel space is the location where all the kernel programs are executed. Kernel space has direct access to all of the memory and communicates with RAM, hard drives, and other devices.
It is separated into many blocks and modules that control all kernel space activities and user space application processes. The system call interface, the Linux kernel, and device modules make up kernel space.
- System call interface - The layer between user space and kernel space is called the system call interface. An operating system interface is provided through a system call, which is a procedure. It is the process through which computer software asks the operating system's kernel for a service.
- Process management - The management of several concurrently running processes is handled by process management. The process is a type of "software in execution" that includes actions like opening and deleting files, accessing disk files, using external hardware devices, and others. Process management handles priorities and provides information about how a process is progressing.
- Memory management unit - The correct allocation of memory resources among the numerous processes running on the system is the responsibility of MMU. The MMU does more than just provide each of the processes with its own virtual address space. Virtual memory, which is the physical address space in RAM, is basically what memory management allocates in place of physical memory. The Memory Management Unit performs the physical address to virtual address conversion.
- Virtual file system - The software layer in the kernel that gives user-space applications access to the filesystem is called the Virtual File System. Additionally, it offers a kernel abstraction that enables the coexistence of many filesystem implementations. Linux file systems have mainly 3 sections. The root directory (/), a particular format for storing data (EXT3, EXT4, BTRFS, XFS, etc..), and a logical disk or partition with a certain file system.
- Device drivers - The device drivers that enable a specific piece of hardware to function make up the vast bulk of the source code in the Linux kernel. A drivers subdirectory is provided in the Linux source tree, and it is further separated into the many supported devices. Examples are Linux drivers, printer driver software, and scanner driver software.
- Architecture-dependent code - Most Linux operating systems are independent of the architecture on which they run, but the architecture must take certain factors into account in order to function normally and efficiently. The architecture-dependent part of the kernel source is defined in the./Linux/arch subfolder and is found in a variety of subdirectories that are particular to the architecture.
- Network stack - By design, the network stack adheres to a tiered architecture that is based on the protocols themselves. Remember that the transport protocol resides below the Internet Protocol (IP), which is the fundamental network layer protocol. The sockets layer, which serves as the networking subsystem's standard API, gives a number of networking protocols a user interface.
Where to Download kernel
You can download the latest kernel version from the kernel.org website. There you can find the mainline, stable, and longterm versions available to download.
Once downloaded you can easily install/upgrade the kernel using the package manager. An alternative method is to compile from the source.
Is kernel the OS?
No, the kernel is the fundamental building block of an operating system for a computer. All other components of the OS rely on the kernel to provide them with essential functions. So, the kernel and OS are separate units that work together to achieve meaningful work.
Is Ubuntu a kernel or an OS?
- Ubuntu is not a kernel. It's an operating system. Other operating systems also have kernels. The kernel is what makes hardware devices usable.
- Although the operating system itself is the system software, the kernel is a component of the operating system. Furthermore, all systems require an operating system to function, but not all operating systems require a kernel to run.
- In addition, the operating system acts as a conduit between the user and the hardware. The kernel acts as a bridge between software and hardware. It also offers security and protection as well.
Why may some call OS the kernel?
- Because one crucial component of an operating system is the kernel, Some believe that the kernel is the operating system. But it is worthless by itself and only works in conjunction with a full operating system.
- It is the primary interface between the hardware and the processes of a computer. The kernel connects these two to adjust resources as effectively as possible. It is named a kernel because it operates inside the OS, just like a seed with a tough shell.
Know Your Current Kernel Version
Use the uname command to know the current Linux kernel version.
The output indicates that your operating system is Linux kernel 5.15.0-48. The other three digits represent the major revision, minor revision, and bug fix. "Generic" means a distribution-specific string.
There are countless Linux distributions in use today, but the Linux kernel is the one thing that all of them must share. New kernel versions are released every few months. So you may notice many Linux Distributions still have old versions. But don't panic, Distros developers often make sure the current kernel is well maintained until its End of Life. The new Distribution release often comes with the latest kernel version. Make sure you are up2date with that.
Thanks for reading so far, please provide your suggestions and feedback in the comment section.