LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Getting Started With Kernel Modules (http://www.linuxquestions.org/questions/linux-newbie-8/getting-started-with-kernel-modules-412309/)

aceman817 02-06-2006 01:51 PM

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!

bulliver 02-06-2006 02:06 PM

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.

aceman817 02-06-2006 05:13 PM

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?

btmiller 02-06-2006 08:50 PM

Read the next section of the TLDP guide about compiling kernel modules.

aceman817 02-06-2006 09:03 PM

The next page talks about a makefile, but what is such a file and what is it saved as?

aceman817 02-06-2006 09:34 PM

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$

jcliburn 02-07-2006 07:04 AM

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?

nx5000 02-07-2006 08:55 AM

You can also have a look at this reference book:
http://lwn.net/Kernel/LDD3/
chapter 2

aceman817 02-07-2006 09:38 AM

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.

jcliburn 02-07-2006 09:55 AM

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`.

aceman817 02-07-2006 12:39 PM

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."

nx5000 02-07-2006 01:13 PM

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.

sundialsvcs 02-07-2006 01:37 PM

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.

aceman817 02-07-2006 02:16 PM

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?

nx5000 02-07-2006 04:06 PM

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).
:study: :study: :study:
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!


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