ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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.
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).
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
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 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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.