Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error when using the "insmod" command in Fedora 5

Posted on 2006-07-21
3
Medium Priority
?
459 Views
Last Modified: 2010-04-22
Hi, I am trying to compile a very simple hello world kernel modules example, but we I try to insmod it into my kernel, I get the error saying that my module is invalid.
I have list my source code, makefile, and terminal output below:

===========================================Source Code===================================
[root@localhost ModulesCode]# cat hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
    printk(KERN_ALERT "Hello, world\n");
    return 0;
}
static void hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);

===========================================Makefile=================================
[root@localhost ModulesCode]# cat Makefile
obj-m := hello.o

KDIR  := /usr/src/kernels/2.6.17-1.2157_FC5-i586

PWD   := $(shell pwd)

default:
        $(MAKE) -C $(KDIR) M=$(PWD) modules

===========================================Compile and Insert=================================
[root@localhost ModulesCode]# make
make -C /usr/src/kernels/2.6.17-1.2157_FC5-i586 M=/root/ModulesCode modules
make[1]: Entering directory `/usr/src/kernels/2.6.17-1.2157_FC5-i586'
  CC [M]  /root/ModulesCode/hello.o
  Building modules, stage 2.
  MODPOST
  CC      /root/ModulesCode/hello.mod.o
  LD [M]  /root/ModulesCode/hello.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.17-1.2157_FC5-i586'
[root@localhost ModulesCode]# insmod hello.ko
insmod: error inserting 'hello.ko': -1 Invalid module format
0
Comment
Question by:yarock
  • 2
3 Comments
 
LVL 8

Assisted Solution

by:manish_regmi
manish_regmi earned 1500 total points
ID: 17158745
there are several reasons for that.

1) your running kernel is different from what used to compile.
   Ans: use the same kernel.
2) The running kernel was compiled with different compiler than your modules.
  Ans: Compile the kernel and modules with same GCC version and same GCC flags.
       
what does uname -r give.
dmesg gives more info on why the insmod failed.

just after the insmod fails, type
dmesg | tail

regards
Manish Regmi
0
 

Author Comment

by:yarock
ID: 17160780
when I do "uname -r" is give me something different other than 2.6.17-1.2157_FC5-i586. This can be the problem,

Anyway, I'm now try to follow Fedora 5 Release note, and it state the KDIR = /lib/modules/build
and install kernel-devl is enought to compile modules.

So I installed kernel-devel, and put /lib/modules/build as my KDIR, the new problem is that when I goto the /lib/modules directory, I see "build" in color, maybe it's a sysmbolic linke (sorry, I'm new to linux).

But when I type make, i got the error that "/lib/modules/build" no such directory or file.
0
 
LVL 8

Accepted Solution

by:
manish_regmi earned 1500 total points
ID: 17161869
Yes, the problem is that the running kernel is different from what you are building from.

In this case you need the whole source. First compile your new kernel and boot with it and compile your modules using that headers and sources.

> But when I type make, i got the error that "/lib/modules/build" no such directory or file.
The correct directory is /lib/modules/`uname -r/source

regards
Manish Regmi


0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question