How to auto load kernel module on system boot in
CentOS 5
If you're in need to auto load a kernel module during boot time on
CentOS 5 Linux, but you want to do it in the
"proper way"
instead o f placing it directly into the good old
/etc/rc.local .
Then it might be a good idea to know that CentOS is loading it's
kernel modules using the wrapper script
/etc/rc.sysinit
In that script there is a small for loop which instructs the system
to load all scripts located in the
/etc/sysconfig/modules/
directory.
Thereafter a quick way to include a new kernel module to auto boot
up on startup could be accomplished through:
echo "modprobe somemodulename" >
/etc/sysconfig/modules/somemodulename.modules
chmod +x
/etc/sysconfig/modules/somemodulename.modules
Here I'll illustrate with a real life example, let's say you're in
need to auto lood during server boot process the kernel module
softdog
which is a must have in most Linux hardwares since they don't
include a hardware watchdog equipped with it.
Execute the commands below to instruct your CentOS to autoload the
softdog kernel module next time on boot:
[hipo@centos-server ~]# echo -e '#!/bin/sh\nMODULES="softdog'
> /etc/sysconfig/modules/softdog.modules
[hipo@centos-server ~]# echo -e "for i in $MODULES ; do\nmodprobe
$i >/dev/null 2>&1; done" >>
/etc/sysconfig/modules/softdog.modules
[hipo@centos-server ~]# echo "modprobe watchdog" >>
/etc/sysconfig/modules/softdog.modules
[hipo@centos-server ~]# chmod +x
/etc/sysconfig/modules/softdog.modules
To also load the same module immediately use
modprobe
[hipo@centos-server ~]# /sbin/modprobe
softdog
This kind of approach to the problem should also work in other
Redhat based Linux distributions like Redhat, Fedora, RHEL
etc.
A similar article to this could be seen on
The really right, modern and clean way to load modules in
CentOS 5