LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-29-2012, 01:24 PM   #1
georgewhr
Member
 
Registered: Nov 2012
Location: SF Bay Area
Posts: 47

Rep: Reputation: Disabled
Lightbulb Compiled module, shows invlaid module format


Hey guys, I compile the hello.c and Makefile, it generates a hello.ko module file. But when I tried to insmod it, the console shows"invliad module format". Somebody said it's because the kernel-devel and my kernel are different version. But however, when I type "uname -r", it shows "3.3.4-5.fc17.i686.PAE", and my kernel-devel is "3.3.4-5.fc17.i686" and I don't have "3.3.4-5.fc17.i686.PAE" in my /usr/src/kernels/. Are those two stuff supposed to be same? But why I still got invlaid module format? thanks
 
Old 11-30-2012, 07:04 AM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2020 CentOS6.10 CentOS7.7 + 50+ other Linux OS, for test only.
Posts: 17,397

Rep: Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611
Looks OK. But if any doubts : # yum update kernel kernel-devel
( 'kernel-devel' is headers only : PAE or no PAE, same headers.)
The current version is 3.6.7-4.fc17* .

A code example that works : hello-1.c
Code:
 /*  
 *  hello-2.c - Demonstrating the module_init() and module_exit() macros.
 *  This is preferred over using init_module() and cleanup_module().
 */
#include <linux/module.h>	/* Needed by all modules */
#include <linux/kernel.h>	/* Needed for KERN_INFO */
#include <linux/init.h>		/* Needed for the macros */

static int __init hello_2_init(void)
{
	printk(KERN_INFO "Hello, world 2\n");
	return 0;
}

static void __exit hello_2_exit(void)
{
	printk(KERN_INFO "Goodbye, world 2\n");
}

module_init(hello_2_init);
module_exit(hello_2_exit);
Makefile :
Code:
 
obj-m    := hello-1.o

KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)

EXTRA_CFLAGS += -I/usr/include

default:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
# insmod ./hello-1.ko : No issues, Fedora 17 - i686.

.

Last edited by knudfl; 11-30-2012 at 07:07 AM.
 
Old 11-30-2012, 07:04 PM   #3
georgewhr
Member
 
Registered: Nov 2012
Location: SF Bay Area
Posts: 47

Original Poster
Rep: Reputation: Disabled
thanks man, what's your kernel version? I actually did the same thing you did but it shows invalid format, because my kernel version is 3.3, the kernel-devel version is 3.6


Quote:
Originally Posted by knudfl View Post
Looks OK. But if any doubts : # yum update kernel kernel-devel
( 'kernel-devel' is headers only : PAE or no PAE, same headers.)
The current version is 3.6.7-4.fc17* .

A code example that works : hello-1.c
Code:
 /*  
 *  hello-2.c - Demonstrating the module_init() and module_exit() macros.
 *  This is preferred over using init_module() and cleanup_module().
 */
#include <linux/module.h>	/* Needed by all modules */
#include <linux/kernel.h>	/* Needed for KERN_INFO */
#include <linux/init.h>		/* Needed for the macros */

static int __init hello_2_init(void)
{
	printk(KERN_INFO "Hello, world 2\n");
	return 0;
}

static void __exit hello_2_exit(void)
{
	printk(KERN_INFO "Goodbye, world 2\n");
}

module_init(hello_2_init);
module_exit(hello_2_exit);
Makefile :
Code:
 
obj-m    := hello-1.o

KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)

EXTRA_CFLAGS += -I/usr/include

default:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
# insmod ./hello-1.ko : No issues, Fedora 17 - i686.

.
 
Old 12-01-2012, 02:08 AM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2020 CentOS6.10 CentOS7.7 + 50+ other Linux OS, for test only.
Posts: 17,397

Rep: Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611Reputation: 3611
Please see post #2 : ".. if any doubts : # yum update kernel kernel-devel

Quote:
my kernel version is 3.3, the kernel-devel version is 3.6
The versions of the packages 'kernel' and 'kernel-devel' must be the exact same.

I.e # 'yum install kernel-devel' as an alone package install won't do.

It's always # yum install kernel kernel-devel
.. To check that the kernel is the latest update :
Only the latest "kernel-devel" is available with yum.

.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rtl8187 driver module load error (Invalid module format) j_75080 Linux - Networking 3 07-06-2009 10:37 PM
error: -1 Invalid module format when using insmod with module cross-compiled for arm AndrewShanks Linux - Embedded & Single-board computer 4 10-15-2007 04:50 AM
module.ko: make, install & used many times. Suddenly modprobe=invalid module format?? GrapefruiTgirl Linux - General 16 08-04-2007 06:40 AM
insmod: error inserting 'module.o': -1 Invalid module format ksrinivas Linux - Newbie 5 10-11-2006 08:29 AM
'Invalid module format' loading simple module on Suse Linux Professional 9.1 rocketdude Linux - Distributions 3 07-28-2004 12:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration