- In this video, I'll tell you about kernel modules.
A kernel module is an object file containing code
that extends the Linux kernel.
An object file is what you get when you compile a file
that is written in the C programming language.
And for every single piece of hardware,
you need a kernel module in order to use it.
Kernel modules are obtained from the initramfs,
which is created upon system installation
to match all hardware that is found
while your system was installed.
There is systemd-udevd,
which is used as a plug-and-play manager
to load kernel files dynamically when needed.
And alternatively,
kernel files can be loaded manually, as well.
So how do we manage kernel modules?
Well, there's a couple of commands involved
like lsmod, which shows all modules currently loaded.
And modprobe, which is used to manually load a kernel file,
including its dependencies.
There is modprobe -r,
which is used to manually unload a kernel file.
And modinfo,
which provides information about kernel modules.
And then there is depmod, which generates the modules.dep
kernel module dependency file.
Kernel module parameters are listed by modinfo.
And they can be specified in include files
in /etc/modprobe.d/,
which allows you to change default kernel module parameters.
All right. So let me demonstrate
how you can manage kernel modules.
I composed a small demo.
Most important steps are on the slides.
Feel free to post the video and try for yourself.
And then, you can watch what I've been doing.
So let's go for it.
So first, lsmod.
The lsmod command to show when all the kernel modules
that are currently loaded.
I wanna know if we have cdrom available.
And there we can see that right now,
we do have cdrom, which is loaded.
So I want to unload modprobe -r cdrom.
And uh oh. What do we get?
We get module cdrom is in use.
Before continuing, it's a good idea
to verify that you have nothing mounted.
The findmnt command is a convenient way to figure out
if anything related to your cdrom is currently mounted.
Look at the second column and look for either sr0 or cdrom.
And if you can find it in here,
you mount it before continuing.
If you don't find it, as is the case right here,
we need to make sure that we get rid of
this module cdrom is in use.
Now, why do we get this?
Well, we get it because we have isofs.
Isofs is currently using the cdrom module.
And that means that we can't unload it at this moment.
You may see, depending who your current configuration,
other modules, as well, like sr_mod.
And if you see them, well,
you need to unload these dependencies.
So modprobe -r isofs.
And then, we can try the modprobe -r cdrom again.
And as you can see, now it is working.
Now, I would like to show you
modprobe on isofs, at this moment.
Because what is modprobe isofs doing?
Well, this module has a dependency.
And as a result, right now,
we can see that cdrom is available again.
We just unloaded it.
We did not load it again, but we loaded isofs.
And because we loaded isofs,
isofs has triggered the dependency,
and for that reason, cdrom is now here.
And that brings us back to our starting point
modprobe -r cdrom.
It's not going to work, but at least you know why.
And this concludes the small demo
about managing kernel modules.