How To Build Kernel Module…


I know that there are books out there that discuss building Linux kernel drivers/modules. Try searching…

maybe just a little source in indonesia about the linux programming, expecially linux drivers

Linux kernel modules should work, regardless whether you use Ubuntu/Xubuntu, or any of the other flavors of Linux… at least that is my understanding.

Here’s a simple kernel module you can play with…


PHP Code:
#include <linux/module.h>

static int __init hello_world( void )
printk( "hello world!\n" );


void __exit goodbye_world( void )
printk( "goodbye world!\n" );

module_init( hello_world );
module_exit( goodbye_world );

To compile it, save this statement into a file called Makefile:

PHP Code:
obj-m += HelloWorld.o

Then on the command line, run this command to build the kernel module:

$ make -C /lib/modules/`uname -r`/build M=`pwd`

To load the kernel module:

$ sudo insmod HelloWorld.ko

To unload the kernel module:

$ sudo rmmod HelloWorld

If you examine the tail end of the file /var/log/messages you will see the output generated by the kernel module.

$ sudo tail /var/log/messages
How To Build Kernel Module…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s