RSS

How-To Geek

With over 13 million lines of code, the Linux kernel is one of the largest open source projects in the world, but what is a kernel and what is it used for?

So What is the Kernel?

A kernel is the lowest level of easily replaceable software that interfaces with the hardware in your computer. It is responsible for interfacing all of your applications that are running in “user mode” down to the physical hardware, and allowing processes, known as servers, to get information from each other using inter-process communication (IPC).

Different Types of Kernels

There are, of course, different ways to build a kernel and architectural considerations when building one from scratch. In general, most kernels fall into one of three types: monolithic, microkernel, and hybrid. Linux is a monolithic kernel while OS X (XNU) and Windows 7 use hybrid kernels. Let’s take a quick tour of the three categories so we can go into more detail later.

Microkernel
A microkernel takes the approach of only managing what it has to: CPU, memory, and IPC. Pretty much everything else in a computer can be seen as an accessory and can be handled in user mode. Microkernels have a advantage of portability because they don’t have to worry if you change your video card or even your operating system so long as the operating system still tries to access the hardware in the same way. Microkernels also have a very small footprint, for both memory and install space, and they tend to be more secure because only specific processes run in user mode which doesn’t have the high permissions as supervisor mode.

Pros

Portability

Small install footprint

Small memory footprint

Security

Cons

Hardware is more abstracted through drivers

Hardware may react slower because drivers are in user mode

Processes have to wait in a queue to get information

Processes can’t get access to other processes without waiting

Monolithic Kernel
Monolithic kernels are the opposite of microkernels because they encompass not only the CPU, memory, and IPC, but they also include things like device drivers, file system management, and system server calls. Monolithic kernels tend to be better at accessing hardware and multitasking because if a program needs to get information from memory or another process running it has a more direct line to access it and doesn’t have to wait in a queue to get things done. This however can cause problems because the more things that run in supervisor mode, the more things that can bring down your system if one doesn’t behave properly.

Pros

More direct access to hardware for programs

Easier for processes to communicate between eachother

If your device is supported, it should work with no additional installations

Hybrid Kernel
Hybrid kernels have the ability to pick and choose what they want to run in user mode and what they want to run in supervisor mode. Often times things like device drivers and filesystem I/O will be run in user mode while IPC and server calls will be kept in the supervisor mode. This give the best of both worlds but often will require more work of the hardware manufacturer because all of the driver responsibility is up to them. It also can have some of the latency problems that is inherent with microkernels.

Pros

Developer can pick and choose what runs in user mode and what runs in supervisor mode

Smaller install footprint than monolithic kernel

More flexible than other models

Cons

Can suffer from same process lag as microkernel

Device drivers need to be managed by user (typically)

Where Are the Linux Kernel Files?

The kernel file, in Ubuntu, is stored in your /boot folder and is called vmlinuz-version. The name vmlinuz comes from the unix world where they used to call their kernels simply “unix” back in the 60’s so Linux started calling their kernel “linux” when it was first developed in the 90’s.

When virtual memory was developed for easier multitasking abilities, “vm” was put at the front of the file to show that the kernel supports virtual memory. For a while the Linux kernel was called vmlinux, but the kernel grew too large to fit in the available boot memory so the kernel image was compressed and the ending x was changed to a z to show it was compressed with zlib compression. This same compression isn’t always used, often replaced with LZMA or BZIP2, and some kernels are simply called zImage.

The version numbering will be in the format A.B.C.D where A.B will probably be 2.6, C will be your version, and D indicates your patches or fixes.

In the /boot folder there will also be other very important files called initrd.img-version, system.map-version, and config-version. The initrd file is used as a small RAM disk that extracts and executes the actual kernel file. The system.map file is used for memory management before the kernel fully loads, and the config file tells the kernel what options and modules to load into the kernel image when the it is being compiled.

Linux Kernel Architecture

Because the Linux kernel is monolithic, it has the largest footprint and the most complexity over the other types of kernels. This was a design feature which was under quite a bit of debate in the early days of Linux and still carries some of the same design flaws that monolithic kernels are inherent to have.

One thing that the Linux kernel developers did to get around these flaws was to make kernel modules that could be loaded and unloaded at runtime, meaning you can add or remove features of your kernel on the fly. This can go beyond just adding hardware functionality to the kernel, by including modules that run server processes, like low level virtualization, but it can also allow the entire kernel to be replaced without needing to reboot your computer in some instances.

Imagine if you could upgrade to a Windows service pack without ever needing to reboot…

Kernel Modules

What if Windows had every driver available already installed and you just had to turn on the drivers you needed? That is essentially what kernel modules do for Linux. Kernel modules, also known as a loadable kernel module (LKM), are essential to keeping the kernel functioning with all of your hardware without consuming all of your available memory.

A module typically adds functionality to the base kernel for things like devices, file systems, and system calls. LKMs have the file extension .ko and are typically stored in the /lib/modules directory. Because of their modular nature you can easily customize your kernel by setting modules to load, or not load, during startup with the menuconfig command or by editing your /boot/config file, or you can load and unload modules on the fly with the modprobe command.

Third party and closed source modules are available in some distributions, like Ubuntu, and may not be installed by default because the source code for the modules is not available. The developer of the software (i.e. nVidia, ATI, among others) do not provide the source code but rather they build their own modules and compile the needed .ko files for distribution. While these modules are free as in beer, they are not free as in speech and thus are not included by some distributions because the maintainers feel it “taints” the kernel by providing non-free software.

A kernel isn’t magic, but it is completely essential to any computer running properly. The Linux kernel is different than OS X and Windows because it includes drivers at the kernel level and makes many things supported “out of the box”. Hopefully you will know a little bit more about how your software and hardware works together and what files you need to boot your computer.

It’s like,,,the beginning of the beginning, with nothing following. For a huge Kernel like Linux has, I was expecting some “fer instances” with explanations. So I am exactly the opposite of Jon above, I think you need to take this on and develop it. The Kernel is a complex topic, obviously, but it would be nice if you took it a few steps beyond the bare beginning. Thanks for the kernel “intro” tho.

Last week during an ubuntu upgrade, my Grub ‘stuff’ got messed up, and I wound up on the forums, dutifully plugging in commands from the Grub CLI. This article gives me a little better idea of what I was doing! Thanks, R

@Aethec: I would like to point out: when was the last time you went searching for a Windows driver because the video card wasn’t supported. Yes I know the Proprietary “blobs” for Linux video cards are not always “default” but it’s about 4 clicks away to enable.

This is well written. It has good logic flow and explained simple enough to follow. The first article should be well rounded and the simplest. The references, links and follow-up articles should be more detailed with great examples maintaining a logical flow. I encourage the Author to continue to write quality articles.

“Microkernels have a advantage of portability because they don’t have to worry if you change your video card or even your operating system so long as the operating system still tries to access the hardware in the same way”
i dont understand this as i thought kernel is a part of OS. sum1 pls explain

I enjoyed the article. I had an old computer that would work with Windows XP, but the wifi and sound didn’t work because I could not find the drivers. So I tried Ubuntu 10.10 and all the hardware worked fine. If you are having problems with Windows operating systems don’t be afraid to try Linux. I also like the idea of it always being free.

In my opinion, I think this is an awesome article for those of us that want to learn more about Linux. I tend to find most of the Linux documentation written as if I have an advance degree in computer science and have been using Linux from the get go. It is great to find a high profile overview on the Linux kernel to get us understanding the basics. Now that I got the basics I can move on to some more detailed documentation about the Linux Kernel. Keep these types of articles coming.

Recently, you have started to churn out articles that are truly unique!! Great going man. You managed to explain a complex thing like a kernel by using easy to follow, logical steps so that even beginners could get your drift. One word.. Professional..

@Neo Kernels are not always a part of the OS. Some Kernels (OS X and Windows) will ONLY work with the OS that was written for them. But in the Linux world, the same kernel can be used (with some modification) on a desktop/laptop and on a mobile phone/slate. They can even use the kernel on big main frame servers and then embed that same kernel into your TiVo. Hope that helps explain it a bit more.

I’m so computer stupid that some articles that I read here have me scratching my head and asking myself “What the hell did I just read??” HA!
I *have* read some really helpful things on this site that have helped me but reading through the article about kernels had me feeling like I was reading Greek. I can do a lot of stuff on the computer and I seem to know a lot more than my friends and they seem to always call me when they have a problem but then I come across stuff like this and……….. Well, I just wish I could understand all of this stuff better and not feel like such a dummy.

Agree with Barry Weiss & uttaradhaka, articles such as these encourage us to think we shall be able to participate in the free community. Linux is great, I have been using Ubuntu 8.04 for past 11/2 years and wish i could have found it earlier. After all why to violate IPR of Microsoft if one can get a better experience using something that is free.

Excellent article, liked it very much! :) Actually, I’m a Windows user and don’t have much experience with other OSs, but really your article is very informative. By the way, I liked this statement very much:
“Imagine if you could upgrade to a Windows service pack without ever needing to reboot…”

Very good article. Was clear and concise. Helps me understand something about operating systems about which I had little prior knowledge. Also gave me an intuitive understanding of why Linux appears fast on an older limited feature machiine that would bog down same machine running newer versions of windows.

This is the first time that I am using Ubuntu 11.4 it seems to be very strong at least much secure than the windows vista ultimate that I am using and I paid a fortune for it. However, I don’t yet how to email my pictures.Can somebody help me? Thanks

Like Paul, in the second comment, I liked the article. I am 60 years old and have been working with UNIX, Linux, VMS, Windows, etc. for 30 plus years. I have always been frustrated with people who attempt to put the simple technology just out of reach. It is refreshing to see simple clear cut articles that are easy to understand.