Here are some simple methods to help you fix your 2.6 kernel module problem.
Quick and Easy PC Repair
The most significant LKM change between Linux 2.4 and Linux 2.6 is an incredible internal change: LKM boots differently. Most people won’t see much of a difference other than changing the suffix of the file containing the LKM as they use highly skilled LKM processing tools in addition to the immutable interface of those tools.
Kernel modules need to be compiled a little differently,custom area of common applications. Previous kernel mockups required us to be carefula lot in a variety of options that are usually stored in Makefiles.well organized, many repetitive settingsaccumulate in children’s makefiles and all with big and beautifuldifficult to maintain. Fortunately, is there a new way?these things called kbuild and this build process forthe loadable module is now just fully integrated into a homogeneous kernelConstruction mechanism. To read more about how modules are typically compiledis not part of the official core (as with all examples youcan be found in these instructions), see the file linux / Documentation / kbuild / modules.txt .
So read on and check out the makefile that will help you create a callable module. simplify hello-1.c :
From a complex point of view, only the first baseline is real.necessaryHowever, “whole” as well as “clean” have been added for many clean purposes.Convenience.
You can now compile the module from the output of the make command. You should get a really similar result.Next:
Note that Kernel 2 introduces some new 6 file naming conventions:Kernel modules have the extension .ko .(instead of the old .o extension) defines whichjust from regular object files. aboveThis is because they grab an extra .modinfo section.the one where additional selective information about the module is stored. Fountainwe will soon see what this information is, just forever.
Nothing special yet. It changes as soon as we use itModinfo from our examples, later hello-5.ko .
You will find a lot of useful information here. Author’s channel forBug reports, even info, short description andThe parameters it accepts.
What is the difference between Modprobe and Insmod?
modprobe is the smart version that uses insmod. insmod just adds a nice solid module where modprobe checks all dependencies (in case that particular module might depend on another module) but loads them.
More information about kernel Makefiles for modules:available at linux / Documentation / kbuild / makefiles.txt . Sureread this and make sure you read the files before you finally startdon’t hackMakefiles. This will probably save you a lot of work.
It’s time to replace the newly assembled modulekernel uses insmod ./hello-1.ko (ignoreeverything you see on the cores; messed up, we’ll talk about itshort) .Module
all loaded into the kernel are listed together in / proc / modules . Go cougar and this file to see themthat your personal module is indeed part of the kernel. Congratulations,You are now the author of the Linux kernel code! When novelty wearsoff, remove your element from the core simply using rmmod hello-1. Look in / var / log / messages to make sure it has been authorizedSyslog file.
Here’s another exercise for the reader. See answer abovereturn statement in init_module () ?Change this return value to a negative value, recompile and reload as a resultmodule again. This happened ?
What is kernel module for?
Linux kernel modules. Kernel modules are pieces of code that can be loaded and unloaded directly into the kernel as needed. They are lightweightThey make the kernel work without rebooting the system. A bug in the resource driver built into our kernel can stop the system, for example, start at all.
obj-m + = hello-1.oEverything: make -C Uname / lib / modules / $ (shell -r) / build M = $ (PWD) Moduleclean: Help -C Uname / lib / modules / $ (shell -r) / build M = $ (PWD) clean
Hostname: ~ / lkmpg-examples / 02-HelloWorld # makemake -C /lib/modules/2.6.11/build M = / root / lkmpg-examples / 02-HelloWorld Modulemake : Directory with entry `/usr/src/linux-2.6. eleven ' CC [M] /root/lkmpg-examples/02-HelloWorld/hello-1.o Building modules, state 2. MODPOST CC /root/lkmpg-examples/02-HelloWorld/hello-1.mod.o LD [m] /root/lkmpg-examples/02-HelloWorld/hello-1.komake : Leave the information free `/usr/src/linux-2.6.11 'Hostname: ~ / lkmpg-examples / 02-HelloWorld #
Hostname: ~ / lkmpg-examples / 02-HelloWorld # modinfo hello-1.koFilename: hello-1.kovermagic: some .6.11 supplant PENTIUMII 4KSTACKS gcc-3.3depends on:
Hostname: ~ / lkmpg-examples / 02-HelloWorld # modinfo hello-5.koFilename: Hello-5 .koLicense: GPLBy Peter Jay Saltzmanvermagic: 2.6.11 proactive PENTIUMII 4KSTACKS gcc-3.3depends on:parm: myintArray: array, most commonly associated with integers (array of integers)parm: mystring: string (character)parm: mylong: good (long) integerparm: myint: integer (int)parm: myshort: short integer (short)Hostname: ~ / lkmpg-examples / 02-HelloWorld #
Core web templating modules must compile differently than regular user-space applications. Earlier versions required by the kernel, wewatch carefully for these parameters, which are regularly saved in makefiles. Even though they are well-organized hierarchsOf course, many of them are superfluous.Parameters accumulated in child makefiles and became cumbersome and rather tedious to maintain.Fortunately, there is a completely new way to do this, usually kbuild and a build process for creating external loadable modules.the engine installed in the standard kernel is now fully integrated. To read more on how to compile modules that couldn’t bePart of the official kernel (like all the examples you choose in this guide) see. linux / Documentation / kbuild / modules file.txt . Let’s see
So, take a look at a simple makefile to compile the module, which confirms as hello-1.c :
From a technical point of view, the first line is really necessary,All and clean lenses have been added for convenience.
You can now compile the module by running the exact make command.You need to buy a publication similar to ours:
Hostname: ~ / lkmpg-examples / 02-HelloWorld # makemake -C /lib/modules/2.6.11/build M = / root / lkmpg-examples / 02-HelloWorld Modulemake : Directory with entry `/usr/src/linux-2.6. eleven ' CC [M] /root/lkmpg-examples/02-HelloWorld/hello-1.o Assembly modules, several stages. MODPOST CC /root/lkmpg-examples/02-HelloWorld/hello-1.mod.o LD [m] /root/lkmpg-examples/02-HelloWorld/hello-1.komake : exit list `/usr/src/linux-2.6.11 'Hostname: ~ / lkmpg-examples / 02-HelloWorld #
Note that the 2.6 kernel introduces an interesting file convention: the direct naming of kernel modules is .ko Extension (old .o extension at destination) that differs conveniently from regular modelsFiles. This is because they contain an extra .modinfo area where the information is almost the sameThe module is supported. We will soon see what this information is for.
Use modinfo hello – * .ko to find out what information an element contains.
Hostname: ~ / lkmpg-examples / 02-HelloWorld # modinfo hello-1.koFilename: hello-1.kovermagic: somewhat .6.11 superseded by PENTIUMII 4KSTACKS gcc-3.3depends on:
Nothing special yet. This changes the minute we use modinfo on one of our later Examples, hello-5.ko .
Hostname: ~ / lkmpg-examples / 02-HelloWorld # modinfo hello-5.koFilename: Hello-5 .koLicense: GPLBy Peter Jay Saltzmanvermagic: 2.6.11 proactive PENTIUMII 4KSTACKS gcc-3.3depends on:parm: myintArray: set White numbers (array Int)parm: mystring: character loop (charp)parm: mylong: extended integer (long)parm: myint: integer (int)parm: myshort: short integer (short)hostname: ~ / lkmpg-examples / 02-HelloWorld #
There is a lot of useful information here. Author’s channel for receiving bug reports,Information about the license, even a banal description of the parameters it accepts.
How do I install a Linux kernel module?
To load a kernel module, run modprobe module_name as root,By default modprobe tries to load the module type from / lib / modules / kernel_version / kernel / drivers /.Some components have dependencies that are opposite kernel modules that must be loaded before the module in question can be loaded.
More information is available about makefiles as kernel modules. linux / Documentation / kbuild / makefiles in.txt .SecureMake sure you read this and related files before you start cracking the makefiles.This will likely save you a large chunk of your career.
It’s time to push your newly compiled module all over the kernel with insmod ./hello-1.(Ignore kb everything you see on Corrupted Hearts; we’ll get back to that soon).
All modules loaded directly into the kernel are listed from / proc / modules .Go ahead and grasp the pivot file to see that your segment is indeed part of a connected core.Congratulations, you are finally the author of the Linux kernel! When a novelty is delayedRemove the kernel module using -rmmod with hello-1. Take a look at a specific look / var / log / messages to see which log file was logged into. Other
Here is an exercise for the representative. See the comment above this return statement in init_module () ? Change the actual return to a negative value, recompile and optionally reload the module. This happened ?
obj-m + = hello-1.oEverything:make -C / lib / modules / $ (wrapper -r) / build uname M = $ (PWD) Moduleclean:make -C / lib / modules / $ (wrapper -r) / build uname M = $ (PWD) cleanEnjoy a faster