Understanding Different Kernel Types And Initial RAM Disk
In our previous article on the Linux kernel, we showed you how you could access documentation pertaining to the kernel and aspects related to the kernel like the /proc file system. In this article, we will talk about the types of kernel and initial RAM disk file system. Basic Understanding Different Kernel Types.
Understanding Different Kernel Types
Kernel architecture, all the basic system services like the process and memory management, interrupt handling etc were packaged into a single module in kernel space. This approach resulted in the kernel being of large size and poor maintainability of the kernel which meant bug fixing or addition of new features resulted in recompilation of the whole kernel which would take a lot of time. In a modern-day approach to the monolithic kernel architecture, the kernel consists of different modules which can be dynamically loaded and unloaded. With this approach, maintainability of kernel became very easy as only the concerned module needs to be loaded and unloaded every time there is a change or bug fix in a particular module. So, there is no need to bring down and recompile the whole kernel for the smallest bit of change.
Also, stripping of the kernel for various platforms (lightweight embedded applications like NAS appliances or raspberry pis) became very easy as we can easily unload the module that we do not want.
The Linux kernel follows this The Linux kernel follows this monolithic modular approach. The /proc/devices file contains a mapping of the device major numbers and device types broadly classified as character and block devices. The kernel gains access to these devices through the corresponding module provided that it has been loaded correctly.
The micro-kernel architecture aims to solve the problem of the growing size of kernel code which was cited as a major drawback in the non-modular monolithic approach. This architecture allows some basic services like device driver management, protocol stack, file system etc to run in user space. This reduces the kernel code size and also increases the security and stability of OS as we have the bare minimum code running in the kernel. So, if a service like a network service crashes due to the buffer overflow, then only the networking service’s memory would be corrupted, leaving the rest of the system still functional.
In addition to the monolithic and micro-kernel architectures we discussed earlier, there is a third kernel architecture referred to as hybrid kernel architecture. A hybrid kernel is an operating system kernel architecture that attempts to combine aspects and benefits of micro-kernel and monolithic kernel architectures used in computer operating systems. The Microsoft Windows and Apple MacOS are prominent examples of operating systems using the hybrid kernel architecture.
The kernel file
We can find the kernel within the /boot directory which is generally mounted as a separate partition. The kernel name would start with vmlinux or vmlinuz followed by a version number. If the kernel file name has vmlinux in it then that indicates a very old version of the kernel without compression. The vmlinuz kernel file name indicates that the kernel file has been compressed with the zlib library (later versions use bzip for higher compression) and the zImage file also indicates virtual memory support.
On a centos 7 system, if we retrieve the kernel file header metadata, we observe the following information:
[root@arkit-centos7 boot]# file /boot/vmlinuz-3.10.0-514.el7.x86_64 /boot/vmlinuz-3.10.0-514.el7.x86_64: Linux kernel x86 boot executable bzImage, version 3.10.0-514.el7.x86_64 (email@example.com) #1 SMP , RO-rootFS, swap_dev 0x5, Normal VGA
Initial RAM disks
When the operating system boots, the kernel needs access to the root file system in order to bring the system to a functional state. In order for the root file system to be accessible, the required drivers for host bus adapters, physical block devices etc must be loaded. But these drivers reside inside the root file system resulting in a chicken and egg situation. The initial RAM disk is responsible for loading a temporary root file system during the Linux boot process. This allows the real root file system to be checked and drivers to access the root file system be loaded.
There are two types on initial RAM disks:
- This was used prior to kernel version 2.6.13
- Compressed file system image mounted through /dev/ram
- The file-system module used in initrd must be compiled into the kernel itself, often ext2 but some use cramfs
- This has been used since kernel version 2.6.13
- This is a CPIO archive
- Unpacked by the kernel to tmpfs which becomes the initial root file system
- This being an archive file does not require file system or block device drivers to be compiled into the kernel
On a centos 7 system, if we retrieve the initramfs file header metadata, we observe the following information
[root@arkit-centos7 ~]# file /boot/initramfs-3.10.0-514.el7.x86_64.img /boot/initramfs-3.10.0-514.el7.x86_64.img: ASCII cpio archive (SVR4 with no CRC)
We’ll now show you how to extract the initramfs-3.10.0-514.el7.x86_64.img initial RAM disk and view its contents
First copy the file to /tmp directory for safe side of protection
[root@arkit-centos7 ~]#cp /boot/initramfs-3.10.0-514.el7.x86_64.img /tmp
Now we’ll extract the file using the /usr/lib/dracut/skipcpio command as shown below.
[root@arkit-centos7 ~]# cd /tmp/init/ [root@arkit-centos7 init]# /usr/lib/dracut/skipcpio /tmp/initramfs-3.10.0-514.el7.x86_64.img | zcat | cpio -ivd [root@arkit-centos7 init]# ls bin dev etc init lib lib64 proc root run sbin shutdown sys sysroot tmp usr var
As you can see from the above output, that is the mini operating system that gets mounted through the tmpfs and provides the kernel with all the necessary drivers it needs to mount and access the complete root file system. Understanding different Kernel types
In this article, we discussed Understanding different Kernel types of operating systems and the category in which Linux kernel falls in and why. We also showed you how to dissect the initial RAM disk file and view its contents. We hope you found this article to be interesting and insightful and look forward towards your feedback.
Thanks for your wonderful Support and Encouragement
Stay Connected With Us. Learn More and Earn More