We have heard about the so called kernel before.
And in this lecture I want to try to do my best to demystify that the key function of the kernel are
process management.
That means that it's trying to schedule which process should get how much CPU power or how much memory,
and it also allows those processes to communicate with each other.
It's also handling the memory, so it's taking care of the memory in a physical way.
That would be the actual memory sticks in your computer and the virtual memory.
If those would not be enough, that then some can be written on your hard drive or SSD, for example.
So it takes care that those memory is being assigned to programs.
And then if those programs close that it's deallocated again.
So it's free for the the rest of the operating system.
Again, it's also managing a lot of file systems.
So for example, Ext4, that's the normal file system on a Linux machine and the kernel would have drivers
or has drivers.
So we can just say, hey, we would like to access that file and the kernel is taking care of that.
It also has quite a bit of a networking stack.
So it has implemented, for example, various networking protocols so we don't have to implement them
ourselves, for example, TCP IP or basic Ethernet functionality.
And it also allows that we can, for example, assign rules or that we can set up a firewall here.
The general idea of the kernel is that we have like a so called hardware abstraction layer in general.
So the idea is that we don't when we write a normal program that we don't have to deal with our the
hardware ourselves because that's different from all the systems, but that we have an abstraction layer.
And then the kernel manage manages to actually deal with the hardware.
Can we see or inspect the kernel at least a little bit?
The thing is we are constantly using the kernel all the time, but in order to see it we could just
try to see how big is the kernel.
Actually that would be the first thing we could try to find out.
So I open my computer and here in this boot directory we can find the kernel that will be loaded.
The kernel is this file here vmlinux Linux with a z at the end.
And we can see for example here it's just 15MB in size.
So this is literally just the kernel that handles the hardware abstraction for our operating system.
We can also see here, for example, that we do have older versions here as well.
Um, if we update that, usually those older versions, at least for quite a while, remain on our system
just in case the newer version would make any problems.
Um, the kernel, it's like one big software package, but luckily we can also have modules there and
those kernel modules are really nice features.
We can imagine a kernel module as a piece of code that can be loaded into the kernel on demand.
So it integrates into the core of our operating system.
And the advantage here is that it allows us to extend the functionality of the kernel.
But we can do this at runtime.
We can just be like, Hey, we now want to load this module.
Another advantage is that the kernel is being provided under an open source license and we could have
proprietary code being packed as a kernel module and we could load that into our kernel without having
any license issues there.
So this allows proprietary drivers to be loaded into our core of our operating system.
To give you a few examples, what are common use cases for kernel modules?
A lot of kernel modules are already shipped in your operating system, but sometimes you want to install
additional ones and additional ones could for example be device drivers, for example for Nvidia graphics
cards or for specific wireless or Wi-Fi network cards.
And for those, for example, we do have open source drivers.
But if we are willing to load a proprietary kernel module, this can enhance our performance there.
So we might want to add a third party kernel module there, or there's also virtual function IO that
would allow us, for example, to have a virtual machine that still has access to our host GPU.
So what we could do then, for example, could be that we have one machine with maybe four GPUs inside
and then we could run four virtual machines there and all of those virtual machines would have full
access to one of those GPUs.
And this could then, for example, be a gaming PC that streams games to for other clients, just as
an example or others would be, for example, the VirtualBox guest add ons that are they add a kernel
module to our kernel in order to improve the performance of our virtual machine.
Or another example would be the ZFS file system.
That would also be a kernel module that we could load.
Some of them are proprietary, some of them are third party, some of them might already be installed
as a kernel module on our system.
How can we list the existing kernel modules that are available on our system?
So just to list those, I could do sudo LS mod, that's the command to get the kernel modules and then
you could see for example which kernel modules are loaded right now.
Um, this is all hardware related stuff.
But for example, if we go down here, for example, you can see that the raid module is loaded or another
file system here is loaded.
So just be aware that there are modules that can be loaded into the kernel.
Why is this important for you?
Usually all of this should just work, but sometimes you need to add additional kernel modules to your
system.
So imagine, for example, you would be the server admin and you have a special card that's not supported
by the default kernel.
Then you would have to either compile the kernel yourself.
That's a topic, it's not part of that course or you would have to.
If it's like a third party, you might have to download specific modules that you will then have to
load into your kernel.
We will also not get into that in this course here, but I want to emphasize this, that you need to
be aware that you might have to redo this every time you install a kernel update and apt does this automatically
for you, even if APT would do that automatically for you.
If you have custom modules, you might have to, you might run into problems every time you try to upgrade
your kernel.
So the way to go would be that you try to avoid to load additional kernel modules, but sometimes,
especially with more unique hardware, you might not be able to get around that.
And then you really need to be careful with updates or upgrades of the kernel.
Um, and yeah, I want to emphasize this here.
If you would be the admin of a system like this, you could lock the kernel.
We will first have a look at this, how it works on ubuntu and then we will have a look at how this
works on centos.
The kernel is in at least on ubuntu.
It's installed in a package called Linux generic e and we can see here that there's a version behind
that's my current ubuntu version here and if I would want to hold that package.
So, so in a sense that it will not update anymore.
I can say I can use this package name and then I can go and I can say sudo apt mark and I can hold that
package and then paste that package name.
And now this one here will not be updated.
So apt get upgrade and stuff like this will not update that kernel.
Again, I would only do this if I had installed any custom modules because then I really don't want
the kernel to upgrade if I if I depend on those modules.
But here in my case I have not installed any custom modules, so I just cancel the hold again and I
can just use my kernel as normal.
Again, I see the point that this really only applies to specific kinds of systems, but I do want to
save you from a lot of trouble during those updates.
And yeah, those are really, really stressful situations that I want to avoid you from having.
By the way, the way the same would work on S.o.s would be a pseudo DNF version lock kernel.
And if I execute this, we can see here no such command, but we then see the real command that we need
to execute.
We need to install this first as a DNF command in order for this to be enabled.
So I need to do first a DNF install and then I want to install the command DNF minus command and then
the version lock command.
The reason that it's split like this is that DNF supports extensions or we can add plugins to it.
And this adds the version lock plugin to our DNF package manager.
So first I just need to install this plugin to my DNF and now I can do sudo DNF version lock kernel.
And if we now execute this we can see here we now have a version lock here on kernel and this kernel
will now no longer be updated or anything like this.
This now here has a version lock on it.
So this is how we can version lock the kernel.
And this can sometimes avoid potential problems, especially if certain tools or so called kernel modules
that extend the kernel are only compatible with a certain version of the kernel.
Especially in those cases, we might want to use this.
But another look at the kernel is that we also should have a look at how we communicate with the hardware.
So if we run on top of the hardware of the kernel, if we just have a normal application, how does
it actually communicate with the computer?
The reason why this is here in this course is more because sometimes you might hear about kernel space
or user space and terms like this.
So for example, if you work in a company, it's important that you can have this kind of conversations
with the other people around you.
So we have a quick overview about this communication, how that works.
So at the bottom we can imagine that we got the physical hardware, that's our processor, our memory,
our storage and our network.
Then on top we have the Linux kernel that manages that hardware.
So we have a layer of the Linux kernel to manage the hardware.
And the Linux kernel provides various so-called system calls.
Maybe you've heard that if you've coded a lot in C or C plus plus those would be, for example, read
open, write close, and it's actually way more.
I've just used a few commands where I was like, okay, those are the most well known ones.
Um, so the Linux kernel provides a set of functions that we can call from our programs.
And then the, um, the program flow enters the kernel mode and this functions, the function is being
executed by the kernel.
So in a sense, for example, the file is being opened and then the control goes back into our actual
program, our actual programs, they run in so-called user mode or user space.
So there we have the C standard library with advanced open functionalities, or we can allocate memory.
Um, that's the C standard library.
It then talks to the Linux kernel to enable a lot of this functionality.
And then on top of that we have system components like system D X X11 for the user interface or nowadays
more like Wayland.
And then on top of that we might have UI toolkits.
They are not here.
And then on top of that we have the actual user applications such as, for example, Firefox and all
of that stuff.
But all of this code here is being run in a so-called user mode.
That means it has not full control over the system.
And then if we open a file, we enter kernel mode, but we can then only open the file.
We can't really control this anymore from our code, so it's safe.
And then this enters kernel mode and then the kernel handles the read to actually read that file.
And then we go back into our program, into our user mode.
So when we just use, for example, Firefox, you can imagine this goes through the whole layer here
to then actually talk to our hardware and this is how it works that we can use the kernel.
So the kernel is not really visible in a sense because it's really just in the background making sure
that everything works and abstracting the hardware from our actual code so we can use the code on multiple
systems.
So those are the most important things in terms of kernel.
If you handle or if you work with Linux a lot, it's not that important that you learn this by heart.
It's enough if you have kind of like heard it and then you know, you have heard those terms and you
know what to Google or what you can look look for in the Internet.
So this is the basic structure of how the system works and how we can use the physical hardware.
Let's now have a look at the boot process, what happens after that.
So we have now looked at the boot loader.
We have looked at the kernel that that is being loaded.
But then our operating system needs to boot and needs to do something.
And how does that work?
And we will have a look at that in the next lecture.