Monday, October 27, 2014

How to compile Linux kernel module.

** In the following example Ubuntu 12.04 is used.
** Ubuntu 12.04 is installed on VMware as VM

Steps are as follows:
1. Login as "root"
2. Execute following commands.
   a. sudo apt-get update
   b. sudo apt-get install make
   c. sudo apt-get install build-essential
   d. sudo apt-get install linux-headers-$(uname -r)
3. create a Makefile using following command
          vi Makefile
4. insert following content into the Makefile and save it.








5. create "hello.c" file and insert following content.
 











 
 


6. Keep both "Makefile" and "hello.c" file in same directory.
7. execute following commands
    a. make
    b. insmod hello.ko
          After executing above command you should get the message "Hello, Baby..."
          This command load the "hello" module.
    c. rmmod hello
        output:  "Goodbye, cruel world....."
          This command unload the above inserted module.



*Oracle VirtualBox can be use as an alternative for VMware (See how to)
*See how to install Ubuntu on Oracle VirtualBox. (link)




-Thank  you




 

 
 

No comments:

Post a Comment