Solved

Error when using the "insmod" command in Fedora 5

Posted on 2006-07-21
3
445 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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