SEARCH

How-To Geek

What is the Linux Kernel and What Does It Do?

image
Image by ingridtaylar

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.


Image by uptown popcorn

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
  • Processes react faster because there isn’t a queue for processor time

Cons

  • Large install footprint
  • Large memory footprint
  • Less secure because everything runs in supervisor mode


Image via schoschie on Flickr

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?

image

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

image

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.

Kernel.org

Justin is a Linux and HTPC enthusiast who loves to try new projects. He isn't scared of bricking a cell phone in the name of freedom.

  • Published 10/26/10

Comments (37)

  1. Jon

    Very informative but overkill. Most readers don’t even use Linux let alone comprehend it. Trying to tell them what a kernel is, is just a bit much. Thanks for the details though!

  2. Paul

    I’m a 14 year old and use Ubuntu. I liked the details.

  3. jimc52

    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.

  4. dave

    Very well detailed information! Thanks for posting!

  5. Maoku

    Thanks,very good for beginners and I love Linux.

  6. Vaisakh

    Very informative…. Thanks for the article..

  7. Addin

    very good explanation…..

  8. Aethec

    Interesting, but I think the end is too biased.
    You say Linux supports nearly everything out-of-the-box and Windows doesn’t, which is wrong.

  9. Rich

    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

  10. Harrison

    @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.

    Also great article!

  11. Shree Mulay

    AWESOME PRIMER! I LEARNED ENOUGH TO START POKING AND PRODDING AROUND NOW! THANKS!!!

  12. Tim

    Wow, lots of article critics out today. I knew the basic jobs of a kernel, but the terms Microkernel, Monolithic and Hybrid are new to me. Thanks…

  13. Larry

    Linux is a hybrid as well. (FUSE and UIO)

  14. Ralph O.

    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.

    Look forward to more articles!

  15. Michael Bæk

    @Aethec:

    No it isn’t. Windows needs driver to be “added to” the kernel for hardware to work. Linux doesn’t – they are a part of the kernel. Kinda.

    Read the article again.

  16. Thomas

    Thanks a lot ! I’ve learned something new today…

  17. Neo

    “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

  18. Mike

    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.

  19. Kevin

    This is a very good article. I don’t quite understand it, but it will be an interesting thing to study.

  20. Barry Weiss

    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.

  21. Camilo Martin

    I would like a longer article or more articles on certain subjects like how people use the Linux kernel. Do people build their OSs right from the kernel?

  22. uttaradhaka

    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..

    Keep ‘em coming

  23. peter

    This is the best explanation of linux kernerl ive ever read. Its easier to understand and is not too long.
    good work+++

  24. Justin Garrison

    @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.

  25. Tara

    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.

    Thanks for all the great articles that *have* helped me though!! :o)

  26. Richard D Kneller FCA

    Most interesting and informative. It is just a pity that the English is so poor.

  27. anand warik

    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.

    Keep going, Articles like these which makes complex thinks (otherwise hard to comprehend) easy are certainly required.

    Did i Forget to say?

    Thanks

  28. Mohammad Elsheimy

    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…”

    Best wishes! :)

  29. devesh

    nice information for linux users…linux is thats y sometimes called kernal insted of OS

  30. zotin

    nice article , i was looking for something like this,not very technical and yet informative ..i would love to buy you a beer
    thanks

  31. Deleted

    What are footprints you talk about in the article?

  32. Elton

    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.

  33. Moon Raja

    Moon raja

    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

  34. S Paul

    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.

    I applaud you for your article.

    Thanks

  35. Marvin

    How can i load linux kernel to my computer through the internet??????

  36. ankur

    i love this way u explained the linux kernel it helped me in my assignment

  37. Vrushali

    It’s Good & informative.

Enter Your Email Here to Get Access for Free:

Go check your email!