Loadable kernel modules are a dynamic way to add functionality to a running kernel. In this video, learn about the value of loadable kernel modules.
- [Narrator] Since we are going to study the workings of Linux device drivers. Let's see how using loadable kernel modules helps immensely with drivers. To talk about loadable kernel modules we need to compare them to statically linked modules, and talk about how loadable kernel modules help us avoid rebooting, and how they lead to faster development cycles. But we need to cover also, when a module can be a loadable kernel module. Static module means that module code is linked into the kernel image itself. For example, in the vmlinuz file that you might find in your /boot directory. Code that's statically linked in the kernel image is by definition loaded as part of the kernel at boot time, and that means it's available at boot time without having to get it from a file system that's mounted later. To change a module that statically linked means, well, you might need to reconfigure your kernel, but you have to at least rebuild your kernel and then reboot to be able to take advantage of the new kernel, quite a lengthy process. Dynamic modules are also known as loadable kernel modules, and by convention, they have the suffix.KO for kernel object. So, dynamically loadable kernel modules are files in the file system and they can be loaded into the kernel, we can dynamically add additional code to the kernel at runtime. That means these loadable kernel modules are designed to be loaded after the kernel has already booted. So, they don't have to be there in the beginning and we need to load only those modules that we need, that's a great big benefit right there. We don't have to build our kernel at all kinds of drivers just in case, no, we can have our drivers that we need added later. That also means that if we want to change a module like during development, then we can just recompile the module, remove the old one, and load the new one. We do not have to reboot. So, this is an important development issue. That means when modules are dynamically loadable, the cycle you go through during development is you can make a change and rebuild the module, remove the old one, insert the new one. That's just seconds. That's like how long it takes you to type it or if you have a script, how long it takes to type the name of the script to make that happen. If we had to change our whole kernel and reboot, that process would take minutes. But not all modules can be loaded dynamically, right? The key idea is if the code in the module is needed to be able to boot up, then it can't be available after we boot up. It can't be a file in the file system, if we need to support to be able to get to that file system, for example. A common way for desktop and server Linux systems to work is to have the very first file system that Linux uses as an initial Ram file system. So, that means initial RAM file system support have to be data can be linked into the kernel. So, file systems that come later can be loadable kernel modules. For example, the loadable kernel module for support for ext4 could exist as a file in the initial Ram file system, and we mount it from that.