LinuxKernel compilation process and dynamic module Loading
Keywords:
Kernel compilation module Loading
Version Control driver 2.6.15-1.2054 _ fc5
Preface:
If this is the happiest time for Kaka to drive Linux in the past few days, it cannot be too much. Just as repeated kernel compilation failed, the machine was almost paralyzed, and it was comforting itself to "learn to give up ",
The next attempt finally succeeded. It's really "no way in the mountains, no way, no way out !"
At this moment, I feel happy to cry.
It is said that Kaka started to use Linux driver programming from the book ldd3 (linuxdevice driver version3. The routine hello. C (hello. Ko) in the book creates a lot of trouble for him. First, the kernel must be re-compiled and version control must be canceled.
Then Kaka fell into this time-consuming war. I have read countless books, read numerous online posts, compiled the kernel for countless times, and at the beginning, the machine was almost on the verge of a crash, but it was not successful, after the machine is restarted, only the fc5 shell environment is left, and even the graphic interface is high. I'm dizzy!
Several times later, although the kernel compilation process was successful, I was bored with a lot of options and Y/N in makemenuconfig. I had a lot of online materials, however, many options of playing chess are related to the hardware configuration of your machine. The configuration I tried several times later proved to have failed. There is no way to continue surfing the Internet. After all, we can only save ourselves. Who will let us start Linux alone?
Later, I found a Kernel configuration post, which corresponds to the 1.1 point and the hardware. I tried to select (m) as much as possible, compile it into a module, and load it dynamically. But there are still some bugs in it. Although the kernel has been compiled successfully, the insmodhello. Ko always prompts: insmod: Error
Inserting 'hello. Ko ':-1 invalid module format.
Despair...
It has been a few days since now, and it takes about half an hour to compile the kernel each time (if this is a broken machine, I would have threw it myself ), I am worried that everyone else is preparing the opening report. Then I told myself: The last time.
Then, after waiting for more than an hour, I did not expect it to succeed.
As a result, I would like to take down this specific operation and precautions as a summary. I also hope that it will be helpful to some of my Linux brothers and sisters, and I will not take any detours. After all, sometimes it is too time to test a person's patience.
Let's talk less about things and get into the question.
First of all, there are several precautions to be declared at the beginning. These considerations are very important, and are related to the success or failure of the entire kernel compilation. Therefore, be sure to note:
The code downloaded by yourself. The best version and System Version (use uname
-R view) if the value is the same or lower. Otherwise, the driver module cannot be loaded. (As for the reason, Kaka is not clear yet. I hope you can tell me .)
Make sure to disable the version control option in the Kernel configuration option (source checksum for all modules). It is located in the loadable module support directory and I have been searching for it for a long time)
The results are all incorrect. After the RPM package is decompressed, many configuration files will be generated in the directory corresponding to RedHat, and these files can be copied from other places, but it is very troublesome. We recommend that greenhand use the RPM package (many downloads on the Internet ).
I don't think about anything else. In short, you must be careful to succeed.
Everybody, come on.
First, download the source code package based on your kernel version.
Determine your kernel version:
[Root @ localhost/] # uname-rm
Next, follow these steps Step by step. mydir represents the storage location of the kernel source code package, depending on your situation. Note that my mydir directory is/usr/src
[Root @ localhostmydir] # rpm-Uvhkernel-2.6.15-1.2054_FC5.src.rpm
Note,Kernel-2.6.15-1.2054_FC5.src.rpmIs the source code package corresponding to my kernel version.
After running this step, the inux-2.6.15.tar.bz2 in the rpmpackage is decompressed in the/usr/src/RedHat/sources directory.
[Root @ localhostmydir] # cd/usr/src/RedHat/specs
[Root @ localhostspecs] # rpmbuild-BP -- target $ (uname-m) kernel-2.6.spec
[Root @ localhostspecs] # ls/usr/src/RedHat/build/kernel-2.6.15/
Config. mklinux-2.6.15.i686vanilla xenxen-vanilla
[Root @ localhostspecs] # cd/usr/src
[Root @ localhostsrc] # mkdir kernels
[Root @ localhostsrc] # cd kernels/
[Root @ localhostkernels] # ln-S ../RedHat/build/kernel-2.6.15/linux-2.6.15.i686/2.6.15-1.2054 _ FC5-i686
[Root @ localhostkernels] # ls
2.6.15-1.2054 _ FC5-i686
[Root @ localhostkernels] # cd 2.6.15-1.2054 _ FC5-i686/
[Root@localhost2.6.15-1.2054 _ FC5-i686] # cp configs/kernel-2.6.15-i686.config. config
CP:Overwrite ". config "? Y
Note: EnterYThis step is important to confirm coverage.
[Root@localhost2.6.15-1.2054 _ FC5-i686] # uname-R
Next, modify the content in makefile:
Set
Extraversion =-prep
Change
Extraversion =-1.2054 _ fc5
In this way, the version consistency is ensured.
Then continue Compilation:
[Root@localhost2.6.15-1.2054 _ FC5-i686] # Make mrproper
[Root@localhost2.6.15-1.2054 _ FC5-i686] # Make menuconfig
Note: I executed the makemenuconfig command, removed a version check option, and then saved and exited.
[Root@localhost2.6.15-1.2054 _ FC5-i686] # Make
Note: It takes a long time to complete this step. My broken machine is an hour and a half.
[Root@localhost2.6.15-1.2054 _ FC5-i686] # Make modules_install
At this point, the kernel source code tree compilation is complete.
Finally, my hello. C and makefile files are all placed under/usr/src, and then execute the following
[Root @ localhostmydir] # Make
Make-C/lib/modules/2.6.15-1.2054 _ fc5/build M =/mydirmodules
Make [1]: Entering directory '/usr/src/RedHat/build/kernel-2.6.15/linux-2.6.15.i686'
CC [m]/mydir/Hello. o
Building modules, stage 2.
Modpost
CC/mydir/Hello. Mod. o
LD [m]/mydir/Hello. Ko
Make [1]: Leaving directory '/usr/src/RedHat/build/kernel-2.6.15/linux-2.6.15.i686'
View the result after make:
[Root @ localhostmydir] # ls
Hello. c hello. Ko hello. Mod. c hello. Mod. O hello. o
Well, make is successful. Use the insmod command to load the module DRIVER:
[Root @ localhostmydir] # insmod./Hello. Ko
Finally uninstall: [root @ localhost mydir] # rmmod hello. Ko
If you cannot see it, use the dmesg command.
In this way, you can use it anyway. Good luck to you.
PS: This log has two appendices:
Appendix 1: Common Linux Kernel configuration options
Appendix 2: Hello. C and makefile
If you need to go to my blog: http://duangangshare.spaces.live.com to view