LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Linux_Kernel_UBUNTU 9.10 (https://www.linuxquestions.org/questions/programming-9/linux_kernel_ubuntu-9-10-a-899738/)

chandru5 08-26-2011 11:21 PM

Linux_Kernel_UBUNTU 9.10
 
Hi every one,
Am new to Linux Kernel programming, presently am using UBUNTU 9.10 version, but I heard its not possible to install and remove the modules, if so please suggest me know which vendor's linux is helpful for beginners. Thanking you in advance.


Thanks and Regards
Chandru

camorri 08-27-2011 08:29 AM

Quote:

I heard its not possible to install and remove the modules
I have no idea where you heard this. Modules can be inserted and removed with modprobe. That will work with any linux distro, assuming the modules were compiled for the kernel you have.

Now if you you are implying you can not re-compile an existing kernel, and remove modules that were originally compiled into the kernel, that also is not true. Ubuntu uses linux kernels, that is how linux kernels work. You will run into people on the ubuntu forums who strongly discourage this, I guess they have their reasons. I do run Ubuntu on my netbook, it works, and since I use the netbook for traveling I use it as is... Now my desktop I run Slackware. If you want to learn how to compile kernels, add and remove any module, then take a look at Slackware. It is stable, and comes without a lot of user gui applications to "make it easier for the beginner".

When you install Slackware, you get what is called the 'huge kernel'. This has almost everything under the sun compiled in. It will boot on just about any i386 or later configuration you can throw at it. You are encouraged to re-compile after install. I simply take out most of the stuff I don't need for my hardware. So, if you are not afraid to learn a little, look at it as an alternative. There is a very large and active community on this board for Slackware.

Hope this helps.

chandru5 08-27-2011 08:57 AM

Thanks camorri for your information. I have one more question, since am new to linux I don't have much knowledge. I installed UBUNTU 9.10 and then I write a small "Hello World" program, but I cant build it. Do I need to install any compiler which builds '.c' file to '.o' file, so that I can install this module to kernel at run time.


Thanks and Regards
Chandru

Tinkster 08-27-2011 04:47 PM

Moved: This thread is more suitable in <Newbie> and has been moved accordingly to help your thread/question get the exposure it deserves.

Nylex 08-28-2011 01:05 AM

Quote:

Originally Posted by chandru5 (Post 4454846)
I have one more question, since am new to linux I don't have much knowledge. I installed UBUNTU 9.10 and then I write a small "Hello World" program, but I cant build it. Do I need to install any compiler which builds '.c' file to '.o' file, so that I can install this module to kernel at run time.

First of all, it's "Ubuntu" and 9.10 reached its end of life in April. That means that it's no longer supported and you won't get any security updates.

By "program", I assume you mean "module" (since kernel modules aren't like standard programs, really). You need gcc to build the kernel; I don't think any other C compiler will do. Also, you need to tell us what "can't build it" means. We can't see your screen, so that really isn't enough information for anyone to help.

chandru5 08-28-2011 03:53 AM

I wanted to learn Linux Kernel Programming, I write a small Hello World Program, and then I tried to build that to create Object file, add to that 'Hello world' program to kernel at run time and display the 'TEXT' in terminal, but I couldn't able to compile it. Do i need to install any package to compile the 'C' program from Terminal.


Thanks and Regards
Chandru

brianL 08-28-2011 04:22 AM

Run this:
Code:

sudo apt-get install build-essential

Nylex 08-28-2011 04:23 AM

Again, you need to tell us what you mean when you say you couldn't compile the module. If there are errors, you need to tell us what those are. Obviously, you need gcc installed. You probably want the tools listed in Documentation/Changes in the kernel source directory, too. It might also help if you post the code.

Edit: Where exactly are you learning from? Presumably not Linux Device Drivers, as that gives you the info you need (e.g. how to write a makefile for kernel modules).

bsat 08-28-2011 12:55 PM

gcc must be there in ubuntu 9.10 by default. you should be able to compile it with out any problems.
As pointed out by Nylex please check the resource you are learning from, check one of these

http://lwn.net/Kernel/LDD3/
http://tldp.org/LDP/lkmpg/2.6/html/index.html

chandru5 08-29-2011 03:15 PM

I wrote a small C program which displays some text and I saved it as Hello.c in my own directory. I want to add this program to my existing Kernel so that I can display the 'Text' in the program at the terminal (This is my first Kernel program), but in order to add to the kernel at run time, I need to generate .ko file, before that I need to create '.o' file.

I used the commands obj-m += Hello.o and obj-m = Hello.o, but I got result "bash: obj-m: command not found", so how can I generate a '.o' file from my "Hello.c" file.


I am using UBUNTU 9.10 OS.


Thanks and Regards
Chandru

Nylex 08-29-2011 11:13 PM

Those commands are supposed to go in a makefile and you run "make" to build the module. Edit: Also, repeating your problem isn't really helpful.

bsat 08-29-2011 11:28 PM

Please read through first two chapters of the book

http://lwn.net/Kernel/LDD3/

It also gives the makefile that has be to used to compile the code.

chandru5 08-30-2011 03:39 PM

I saved my .c file in /root/Desktop/Kernel_Programming and When I run this command "make -C /lib/modules/2.6.28-11-generic/build M=/root/Desktop/Kernel_Programming" to compile my kernel program(which is a simple "Hello World" program), I got this result


make: Entering directory `/usr/src/linux-headers-2.6.28-11-generic'
scripts/Makefile.build:41: /root/Desktop/Kernel_Programming/Makefile: No such file or directory
make[1]: *** No rule to make target `/root/Desktop/Kernel_Programming/Makefile'. Stop.
make: *** [_module_/root/Desktop/Kernel_Programming] Error 2
make: Leaving directory `/usr/src/linux-headers-2.6.28-11-generic'

First I taught, when we compile our kernel program, it generates a .ko file and its reference is saved in 'Makefile', which is used by "insmod and rmmod" commands for further action but now am confused. Please help me.


Thanks and Regards
Chandru

chandru5 09-03-2011 05:56 AM

Need Help to compile Kernel Program
 
Hi all,
I wrote a small kernel program to display some text

"#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("Dual BSD/GPL");

int init_module(void)
{
printk(KERN_ALERT" Hello.\n");
return(0);
}
void Clean_Moule()
{
printk(KERN_ALERT "Bye.\n");
}
module_init(init_module);
module_exit(Clean_Module);"
and Makefile as
"obj−m += hello−1.o
all:
make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules
clean:
make −C /lib/modules/$(shell uname −r)/build M=$(PWD) clean
"
I saved these two files in /root/Dektop/Kernel_Programming directory.
when I entered the command "make -C /lib/modules/2.6.28-11-generic/build M=/root/Desktop/Kernel_Programming" in the terminal three files are generated namely "Module.makers, Module.symvers and Module.order", I taught .o and .ko files will be generated, but I got these files. Please help me to compile my first kernel program.

Thanks and Regards
Chandru

chandru5 09-03-2011 05:58 AM

and this is the result a got in the terminal.

root@chandru-desktop:~/Desktop/Kernel_Programming# make -C /lib/modules/2.6.28-11-generic/build M=/root/Desktop/Kernel_Programming
make: Entering directory `/usr/src/linux-headers-2.6.28-11-generic'
Building modules, stage 2.
MODPOST 0 modules
make: Leaving directory `/usr/src/linux-headers-2.6.28-11-generic'
root@chandru-desktop:~/Desktop/Kernel_Programming#


I am using Ubuntu 9.10 , kernel 2.6.28.11


All times are GMT -5. The time now is 12:33 AM.