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!
|
Quote:
You just need to type the 'make' commands etc in the terminal. |
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?
|
Read the next section of the TLDP guide about compiling kernel modules.
|
The next page talks about a makefile, but what is such a file and what is it saved as?
|
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$ |
Somewhere in your makefile you should see something like this.
Code:
default: Also, what does the command "uname -r" produce? |
|
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.
|
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`.
|
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."
|
Code:
file /lib/modules/`uname -r`/build 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. |
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. |
When I run the following line at the terminal, this is what I get:
Code:
allen@slaptop:~/Desktop$ file /lib/modules/`uname -r`/build |
Quote:
Code:
file /lib/modules/`uname -r`/build 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:
: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! |
Thanks for the prompt reply and links. As per my earlier post, there is no forward-slash after "build." Regardless, I get the same message either way. So it looks like I need to compile a new kernel to get my simple kernel module to work. Please pardon my ignorance as I'm new to Linux and trying to use it for both personal and business purposes. I'm also taking an operating systems course that deals heavily with Linux/Unix and the questions being asked of us assume that we have previous experience with the OS despite the fact that many people do not and there are no prerequisites. Needless to say, I have many reasons to learn Linux quickly and efficiently. Are there any good books that you can recommend? I think I may be stopping by the library soon.
|
All times are GMT -5. The time now is 08:48 AM. |