LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-06-2006, 01:51 PM   #1
aceman817
LQ Newbie
 
Registered: Apr 2001
Distribution: Ubuntu 5.10
Posts: 24

Rep: Reputation: 15
Getting Started With Kernel Modules


I'm trying to learn kernel modules and I'm not sure how to get started. I want to install the simple "hello world" one at http://www.tldp.org/LDP/lkmpg/2.6/html/x181.html, but it's not very specific on how to do it. It says that modules should be built from the console and not from X. Do I just open up a console window? Do I use a text editor like GEDIT to write the module? I'm running a pretty standard Ubuntu 5.10 release on my laptop. Any help is greatly appreciated!
 
Old 02-06-2006, 02:06 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86; Gentoo PPC; Gentoo Sparc64; FreeBSD; OS X; Solaris
Posts: 3,731
Blog Entries: 4

Rep: Reputation: 66
Quote:
Do I use a text editor like GEDIT to write the module?
If you want, or you could use one of vim, emacs, nano etc..
You just need to type the 'make' commands etc in the terminal.
 
Old 02-06-2006, 05:13 PM   #3
aceman817
LQ Newbie
 
Registered: Apr 2001
Distribution: Ubuntu 5.10
Posts: 24

Original Poster
Rep: Reputation: 15
Ok. So I have booted up my system in GNOME and I copied all the code at http://www.tldp.org/LDP/lkmpg/2.6/html/x121.html to a file called "hello-1.c" on my desktop. Where do I go from here?
 
Old 02-06-2006, 08:50 PM   #4
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,066

Rep: Reputation: 295Reputation: 295Reputation: 295
Read the next section of the TLDP guide about compiling kernel modules.
 
Old 02-06-2006, 09:03 PM   #5
aceman817
LQ Newbie
 
Registered: Apr 2001
Distribution: Ubuntu 5.10
Posts: 24

Original Poster
Rep: Reputation: 15
The next page talks about a makefile, but what is such a file and what is it saved as?
 
Old 02-06-2006, 09:34 PM   #6
aceman817
LQ Newbie
 
Registered: Apr 2001
Distribution: Ubuntu 5.10
Posts: 24

Original Poster
Rep: Reputation: 15
I copied the necessary code from the tutorial into a file and named it "makefile." I saved it on the desktop and ran "make" from a terminal. This is the error that I got:

allen@slaptop:~/Desktop$ make
make -C /lib/modules/2.6.12-10-386/build M=/home/allen/Desktop modules
make: *** /lib/modules/2.6.12-10-386/build: No such file or directory. Stop.make: *** [all] Error 2
allen@slaptop:~/Desktop$
 
Old 02-07-2006, 07:04 AM   #7
jcliburn
Member
 
Registered: Dec 2003
Location: Mississippi, USA
Distribution: Fedora
Posts: 435

Rep: Reputation: 33
Somewhere in your makefile you should see something like this.

Code:
default:
        $(MAKE)  blah blah blah
The whitespace leading that $(MAKE) rule must be a tab, not spaces.

Also, what does the command "uname -r" produce?

Last edited by jcliburn; 02-07-2006 at 07:20 AM.
 
Old 02-07-2006, 08:55 AM   #8
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 52
You can also have a look at this reference book:
http://lwn.net/Kernel/LDD3/
chapter 2
 
Old 02-07-2006, 09:38 AM   #9
aceman817
LQ Newbie
 
Registered: Apr 2001
Distribution: Ubuntu 5.10
Posts: 24

Original Poster
Rep: Reputation: 15
The makefile code that I posted earlier is from the tutorial at http://www.tldp.org/LDP/lkmpg/2.6/html/x181.html. It seems like it cannot find the directory. I do not have a directory named "build" in the shell folder. I can't seem to create one either.
 
Old 02-07-2006, 09:55 AM   #10
jcliburn
Member
 
Registered: Dec 2003
Location: Mississippi, USA
Distribution: Fedora
Posts: 435

Rep: Reputation: 33
In Red Hat/Fedora land, the "build" you're referring to is created upon installation of the "kernel-devel" package, and it's a symbolic link to /usr/src/kernels/`uname -r`.
 
Old 02-07-2006, 12:39 PM   #11
aceman817
LQ Newbie
 
Registered: Apr 2001
Distribution: Ubuntu 5.10
Posts: 24

Original Poster
Rep: Reputation: 15
I'm not sure what you mean by your last post, jcliburn. I think Ubuntu is based on Debian. I made a directory called "build" but now I receive an error saying that "*** No rule to make target 'modules'. Stop."
 
Old 02-07-2006, 01:13 PM   #12
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 52
Code:
file /lib/modules/`uname -r`/build
If this command do not say "symbolic link to <something>" then you have not **recompiled** and installed a kernel, you only have the binary kernel.

You have to download a kernel source , compile it (make all) then install it (make install,make modules_install).

Then reboot

then retry following tldp

It would be the easiest.
 
Old 02-07-2006, 01:37 PM   #13
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,278

Rep: Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088
Given that your eventual goal is a kernel module, you would be very wise to practice with the tools, such as make and so-forth, before attempting to build a kernel module with them.

Also be sure that the instructions you are following are correct for the kernel (2.4 vs. 2.6) that you are using.
 
Old 02-07-2006, 02:16 PM   #14
aceman817
LQ Newbie
 
Registered: Apr 2001
Distribution: Ubuntu 5.10
Posts: 24

Original Poster
Rep: Reputation: 15
When I run the following line at the terminal, this is what I get:

Code:
allen@slaptop:~/Desktop$ file /lib/modules/`uname -r`/build
/lib/modules/2.6.12-10-386/build: directory
Do I need to compile a new kernel? If so, what is the easiest way to do it? Can I use a "live" cd like Knoppix or something similar?
 
Old 02-07-2006, 04:06 PM   #15
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 52
Quote:
Originally Posted by aceman817
When I run the following line at the terminal, this is what I get:

Code:
allen@slaptop:~/Desktop$ file /lib/modules/`uname -r`/build
/lib/modules/2.6.12-10-386/build: directory
Are you sure you have typed
Code:
file /lib/modules/`uname -r`/build
and not
Code:
file /lib/modules/`uname -r`/build/
?
You have to remove the last / as I posted before.
Otherwise then you have created yourself the directory and then you are beginning to break things, this directory is created when a new kernel is install, don't create it yourself

Quote:
Do I need to compile a new kernel? If so, what is the easiest way to do it? Can I use a "live" cd like Knoppix or something similar?
Hum you should look on google or on tldp.org for compiling linux kernel. Quickly said, what you need is kernel source and gnu compiler (gcc).

http://www.digitalhermit.com/linux/K...ild-HOWTO.html

As sundialsvcs, you should not try building kernel modules now. If you skip steps, you will end up with bad knowledge.
Try to compile and use your own kernel first. After this, ask again for kernel modules
Learning make is maybe not really needed (if you have time, do it but you look like impatient) , see here:
http://www.linuxquestions.org/questi...0&goto=newpost

Good luck!
 
  


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
kernel compilation-From where it should be started for already compiled kernel b0nd Linux - Newbie 11 08-17-2005 01:08 PM
Kernel Modules and modules.conf init Linux - General 0 02-20-2004 06:51 PM
new kernel (2.4.22 up from 2.4.20-6) - missing modules - use old modules? Simon Bridge Linux - Software 1 02-04-2004 05:52 AM
Kernel modules: why are some kernel modules zipped? hampel Slackware 3 06-30-2003 06:33 AM
Updated kernel and system started locking up? liljnr70 Linux - Distributions 1 04-17-2003 02:29 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration