Module compilation and insmodinvalidformat Problems
Source: Internet
Author: User
Module compilation and insmodinvalidformat solution-general Linux technology-Linux programming and kernel information. For details, see the following. Insmod: error inserting 'hello. ko ':-1 Invalid module format
Some less mysterious information is recorded in the file/var/log/messages;
Jun 4 22:07:54 localhost kernel: hello: version magic '2. 6.5-1.358 custom 686
REGPARM 4 KSTACKS gcc-3.3 'could be '2. 6.5-1.358 686 REGPARM 4 KSTACKS gcc-3.3'
In other words, the kernel rejects loading your module because the string that records the version number does not match (more specifically, the version stamp ). The version stamp is stored in the kernel module as a static string. Use vermagic :. The version information is obtained from the file init/vermagic. o in the connection phase. To view the version stamp and other characters in the module, run the following command modinfo module. ko:
[Root @ pcsenonsrv 02-HelloWorld] # modinfo hello-4.ko
License: GPL
Author: Peter Jay Salzman
Descr resume ption: A sample driver
Vermagic: 2.6.5-1.358 686 REGPARM 4 KSTACKS gcc-3.3
Depends:
We can use the option -- force-vermagic to solve this problem, but this method is potentially dangerous, so it is unacceptable in mature modules.
First, prepare the kernel code tree that is exactly the same as your current kernel version. Then, find the compilation configuration file of your current kernel. Usually it can be found in the path/boot, using a file name like a config-2.6.x. You can directly copy it to the path of the kernel code tree: cp/boot/config-'uname-R'/usr/src/linux-'uname-R '/. config.
Even if the identical configuration file is used, the version stamp is slightly different, but this is enough to cause the module loading failure. The difference is that the custom string that appears in the module but does not appear in the kernel is caused by the modified makefile provided by some release versions. Check/usr/src/linux/Makefile to make sure the following specific version information is exactly the same as that of your kernel:
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 5
EXTRAVERSION =-1.358 m
...
You don't have to compile the kernel completely. You only need to get the required file:
Root @ pcsenonsrv linux-2.6.x] # make
CHK include/linux/version. h
UPD include/linux/version. h
SYMLINK include/asm-> include/asm-i386
SPLIT include/linux/autoconf. h-> include/config /*
HOSTCC scr limit pts/basic/fixdep
HOSTCC scr implements pts/basic/split-include
HOSTCC scr ī pts/basic/docproc
HOSTCC scr ī pts/conmakehash
HOSTCC scr ī pts/kallsyms
CC scr merge pts/empty. o
...
If you don't really want to compile a kernel, You can abort the compilation process after SPLIT by pressing the CTRL-C. Because the file you need is ready. Now you can return to your Module Directory and compile and load it: At this time, the module will be fully compiled for your current kernel, and no error will be prompted during the loading.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service