Solved

Error when using the "insmod" command in Fedora 5

Posted on 2006-07-21
3
443 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 500 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 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
OS & DB Recommendation 4 46
pipe to sed or perl, please help 5 128
Linux 10 107
Help with Ubuntu 14.04 LTS 10 135
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now