Kernel, Modules, Tunables & initrd (Initialisation RAM Disk)
Kernel
====================================================================================
What is athe Linux Kernel?
The Linux kernel is the core software that acts as an interface between the hardware and various software applications running on your system.
------------------------------------------------------------------------------------------------------------------------------------------------
Check kernel version
uname -r
After installing a new kernel version, a server reboot is required.
------------------------------------------------------------------------------------------------------------------------------------------------
Which file in /bootWhere is the kernel?Linux Kernel stored?
Typically, the kernel file itself (located within /boot) is prefaced with 'vmlinuz', for example:
vmlinuz-5.15.0-106-generic
Note; is the kernel is prefaced with vmlinuz - this means that the kernel is compressed and must be uncompressed on boot. If the kernel file is prefaced with vmlinux - then it isn't compressed.
Working on Linux systems, you may see systems with various kernels installed.
To check which kernel is currently being treated as the primary one (which will be loaded on boot), you can check the symlinks (in /boot), as below:
vmlinuz -> vmlinuz-5.15.0-107-generic
vmlinuz.old -> vmlinuz-5.15.0-106-generic
------------------------------------------------------------------------------------------------------------------------------------------------
Kernel Modules
What is a kernel module?
A kernel module is essentially a piece of code that can be loaded into the operating system's kernel on demand. Think of it like an extension for the kernel, providing additional functionality without requiring a complete system restart. In other systems, modules are known as drivers.
For clarification; Kernel modules are not the only method that the kernel can be altered. You can also directly edit GRUB to pass additional commands during boot, or alter the kernel manually.
Why do we need kernel modules?
The Linux Kernel is 'monolithic', this means that it's a single file containing every aspect of that particular kernel. In order to change this, we would have to alter and recompile the kernel manually - which is lots of work. Alternatively, we can use pre-built kernel modules to add additional functionality to the Linux Kernel.
About Kernel Modules
Kernel Modules are typically stored in /lib/modules.
Typically, this directory will contain various modules that come pre-installed with the OS, note that these won't all be active.
List active kernel modules:
lsmodActivate an installed kernel module
Firstly, identify the module file path (within /lib/modules). This will have a .ko file extension.
sudo insmod /lib/modules/path/to/ko/fileDisable an installed kernel module
sudo rmmod modulenameCheck for module dependencies
This is worth doing if you're adding a new kernel module to a system:
sudo modprobe -a modulename------------------------------------------------------------------------------------------------------------------------------------------------
Kernel Tunables
In Linux, a tunable refers to a specific type of configuration setting within the kernel. These tunables allow you to customize the behavior of the kernel while the system is running, offering more fine-grained control over how your system operates.
There are lots of tunables set for the Linux Kernel that dictate how the system will handle a variety of system aspects. As an example, there's a tunable for the maximum number of files that a Linux system can have open at any one time, called 'fs-file-max'
View all tunables:
sysctl -a
View specific tunable:
sysctl tunable-name
Change tunable value (doesn't persist reboot):
sysctl -w tunable-name=newvalue
Permanently change tunable value
Specifically where this can be done is OS dependent, a typical location is /etc/sysctl.d
Create a new file ie 00-custom-settings.conf
contents:
tunable-name=newvalue
====================================================================================
initrd
------------------------------------------------------------------------------------------------------------------------------------------------
What is initrd?
initrd (initialisation RAM disk) is essentially a set of instructions used to load the kernel. initrd is stored temporarily in system memory whilst the kernel is loaded.
-----------------------------------------------------------------------------------------------------------------------------------------------
Which file in /boot is initrd?
The initrd file will be prefaced with just that - initrd:
initrd.img-5.15.0-106-generic
To check which initrd file is currently being treated as the primary one (which will be loaded on boot), you can check the symlinks (in /boot), as below:
initrd.img -> initrd.img-5.15.0-107-generic
initrd.img.old -> initrd.img-5.15.0-106-generic
-----------------------------------------------------------------------------------------------------------------------------------------------