Solved

Error when using the "insmod" command in Fedora 5

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tallylog file 2 2,774
GUI development for Ubuntu 8 215
A "Helper" for python 2 87
automating commands in linux on start up 2 45
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…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

21 Experts available now in Live!

Get 1:1 Help Now