Thursday, July 16, 2009

To load modules on startup LINUX

There are so many situations to add our new compiled modules on system startup like to add custom device driver extension for existing modules, etc..
we will make(build or compile) our modules using the help of make utility on linux.
this utility or cammand uses Makefile as its input for compiling or building modules.
after build the modules we will get our executable module as
(make modules install for compiling kernel also install all modules in /lib/modules/uname -r/kernel directory)


if we want to load module ,
insmod modulename.ko

there are somany issues for this modules are depended on another module.
if say our module modulename.ko is depended on module1.ko and module2.ko
in this case we want to load

insmod module1.ko
insmod module2.ko
insmod modulename.ko

to simplify this task we have a modprob utility
we could set dependency in a file /lib/modules/($SHELL uname -r)/modules.dep
modprobe actually uses insmod to insert module in a running kernel.

the entry in modules.dep is like as follows
/lib/modules/2.6.26-1-686/kernel/mymodule.ko: /lib/modules/2.6.26-1-686/kernel/module1.ko /lib/modules/2.6.26-1-686/kernel/module1.ko

(eg: modulename : (colon) first dependency (space)second dependacy (space) etc....)
syntax is important!!!

use command
modprobe mymodule.ko
it will automatically add module1.ko and module2.ko automatically

lets come to the context if we want to load it on startup we will have to configure modprobe. For that we could use /etc/modprobe.conf or /etc/modules.conf or /etc/modules according to different distributions of linux
/etc/modules.conf uses 2.4 and earlier version now we are popular 2.6 kernel so it is modeprobe.conf(/etc/modprobe.d/)

add a single line to that file will load the module on the startup
just add
at the end of line

it is very easy to play with modprobe.conf there is a command line interface also there.

man modprobe ,for more information!

we could set aliases for our modules in this file

hope u get some idea about how load module into running kernel at runtime....


No comments:

Post a Comment


Related Posts with Thumbnails