You may have concluded from earlier discussions about Linux that the kernel is its central idea. Although we’ve discussed the other components of the operating system, we haven’t yet demonstrated how they all function together. Three levels of abstraction can be used to arrange the Linux operating system.
Hardware is the most fundamental level and contains things like our CPU, RAM, hard drives, networking interfaces, etc. the physical layer that does the computations for our computer. The kernel, which is the next level, manages processes and memory, handles device connection, makes system calls, configures our filesystem, etc. To ensure that the hardware performs as our processes require, the kernel must communicate with it. The level that you are most familiar with is user space, which comprises your operating system’s shell, any programs you execute, graphics, etc. We will go into great detail regarding the Linux kernel in this part.
Linux has three levels of abstraction. The issue that remains is why it is required or why they even exist. The user and kernel level operates at two different modes, respectively: user mode and kernel mode.
The kernel has access to all of the system’s hardware while it is in kernel mode. As a result, the kernel has the ability to manage networks and read and write data to hard drives. However, there is relatively little CPU memory available while operating in user mode. Let’s imagine that your system is attacked by a virus, which might happen if you are not careful enough when surfing the internet. You don’t want a virus to gain access to your hardware, such as your microphone or camera, or to all of your data. That’s why there are different abstraction layer that exists. It works as a protection ring for your system and data. These different modes are called privilege levels.
User space programs can ask the kernel to do a task on our behalf by using system calls (
syscall). The system called API is used by the kernel to make some services available. These services enable us to change our network settings, change memory use, read or write to a file, etc. There are a finite number of services, thus you cannot keep adding system calls. Your system already has a table of all of the system calls that are available, and each system call has its own unique ID.
You can install multiple kernels on your system and from the GRUB menu that we have discussed in the previous article you can select which kernel you want to boot. Run the command below the check the name and version of the kernel that you are using.
uname command gives the system information and the
-r flag is for to show the release information. You can install the kernel in various ways including downloading the source package or using the management tools or you can compile it from the source.
$sudo apt install linux-generic-lts-vivid
After running the command, you just reboot the system and boot into the kernel that you installed. Other packages may need to be installed as well. You may also specify the kernel version during installation, such as
5.10.0-46-generic. If you want to update the kernel, you can do it with the help of ‘
dist-upgrade’. Run the command below.
$sudo apt dist-upgrade
Location of the Kernel
As you know in linux everything is treated as a file. So, when you install a new kernel, it adds some extra files in the
/boot directory. You will see multiple files for different kernel versions.
- vmlinuz: this is the actual linux kernel.
- initrd: according to Tim Jones, The Linux initial RAM disk (
initrd) is a temporary root file system that is mounted during system boot to support the two-state boot process. The
initrdcontains various executables and drivers that permit the real root file system to be mounted, after which the
initrdRAM disk is unmounted and its memory freed. It is used before loading the kernel.
- system.map: symbolic lookup table.
- config: It comprises settings of kernel configuration. You can compile your own kernel by setting the modules to be loaded.
You can delete some of the older versions of the kernel, if necessary or your
/boot directory run out of space. But be careful when doing this. You may then accidentally delete the kernel that you are using.
Kernel modules allow users to extend the functionality of the kernel if necessary. You can add or delete specific kernel modules. Let’s say you want to add support for a new kind of keyboard. For this, you just some modules to the kernel. They can not add or remove the core code of the kernels. You can view the currently loaded modules by running the command below.
To load a module you can use ‘
modprobe’ which tries to load the module from
/lib/modules/(kernel version)/kernel/drives/ directory. Some modules may have dependencies. In that case,
modprobe also loads the dependencies.
$ sudo modprode bluetooth
To remove a module from the kernel you can run the command below.
$ sudo modprobe -r bluetooth