Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Ubuntu This forum is for the discussion of Ubuntu Linux.


  Search this Thread
Old 03-30-2007, 04:07 PM   #1
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
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;
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
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 19,626

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
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.


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
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 > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 04:54 PM.

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