LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-26-2011, 11:21 PM   #1
chandru5
LQ Newbie
 
Registered: May 2011
Posts: 16

Rep: Reputation: Disabled
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
 
Old 08-27-2011, 08:29 AM   #2
camorri
LQ 5k Club
 
Registered: Nov 2002
Location: Somewhere inside 9.9 million sq. km. Canada
Distribution: Slackware 15.0, current, slackware-arm-currnet
Posts: 6,213

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

Last edited by camorri; 08-27-2011 at 08:30 AM.
 
Old 08-27-2011, 08:57 AM   #3
chandru5
LQ Newbie
 
Registered: May 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
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
 
Old 08-27-2011, 04:47 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <Newbie> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 08-28-2011, 01:05 AM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by chandru5 View Post
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.
 
Old 08-28-2011, 03:53 AM   #6
chandru5
LQ Newbie
 
Registered: May 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
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
 
Old 08-28-2011, 04:22 AM   #7
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,298
Blog Entries: 61

Rep: Reputation: Disabled
Run this:
Code:
sudo apt-get install build-essential
 
1 members found this post helpful.
Old 08-28-2011, 04:23 AM   #8
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

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

Last edited by Nylex; 08-28-2011 at 04:26 AM.
 
Old 08-28-2011, 12:55 PM   #9
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
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
 
1 members found this post helpful.
Old 08-29-2011, 03:15 PM   #10
chandru5
LQ Newbie
 
Registered: May 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
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
 
Old 08-29-2011, 11:13 PM   #11
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

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

Last edited by Nylex; 08-29-2011 at 11:49 PM.
 
Old 08-29-2011, 11:28 PM   #12
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
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.
 
1 members found this post helpful.
Old 08-30-2011, 03:39 PM   #13
chandru5
LQ Newbie
 
Registered: May 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
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
 
Old 09-03-2011, 05:56 AM   #14
chandru5
LQ Newbie
 
Registered: May 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
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
 
Old 09-03-2011, 05:58 AM   #15
chandru5
LQ Newbie
 
Registered: May 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
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
 
  


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



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:59 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration