LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 03-30-2007, 04:07 PM   #1
dinesh_t
LQ Newbie
 
Registered: Jan 2006
Posts: 15

Rep: Reputation: 0
how to insert a hello world module into kernel


Hai i am using ubuntu 6.06 (2.6.15-23-amd64 kernel)

Recently i have downloaded a driver programming tutorial.
It has a small helloworld program.

program : hello.c
#define MODULE
#include <linux/module.h>
int init_module(void) { printk("<1>Hello, world\n"); return 0; }
void cleanup_module(void) { printk("<1>Goodbye cruel world\n"); }

i tried to compile program using "gcc -c hello.c" command and it failed
then i removed the line #include<linux/module.h>, then it compilied successfully
and hello.o is created.

Then i tried to insert the module into kernel using the command
"insmod ./hello.o"
but it failed with the error "invalid module"

I came to know from google search that we have to compile the kernel for this to work.

can any body tell me how to compile the kernel and make this module work
 
Old 03-31-2007, 01:33 AM   #2
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
The kernel is already compiled, you're running it. If you're going to compile kernel modules the you need the kernel headers, you'll also need to include the headers in the search path.
Something like this should do it;
Code:
gcc -I/usr/src/linux-headers-2.6.15-23/include/ -c hello.c
A better place to ask this would probably be in the Linux Kernel forum.
 
1 members found this post helpful.
Old 03-31-2007, 03:08 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Doesn't sound like much of a tutorial to me.
Try buying a decent book - maybe Linux Device Drivers by Corbet et al.
 
0 members found this post helpful.
  


Reply



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
system call to insert a module in kernel sharad Linux - General 1 03-22-2007 04:15 AM
how to insert a loadable module into the kernel.? moog Linux - Newbie 2 01-08-2007 08:37 AM
insert module into non-running kernel... howto? euph0rix Linux - Newbie 2 01-25-2005 06:29 PM
failled tp insert module into kernel actteoh Linux - Hardware 2 05-07-2004 10:18 AM
Can't insert module into kernel swamysk Linux - Newbie 14 08-22-2003 05:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 02:15 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