Solved

Error when using the "insmod" command in Fedora 5

Posted on 2006-07-21
3
440 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

15 Experts available now in Live!

Get 1:1 Help Now