Tutorials
goetia
Software
0x53.net

Loading Kernel modules

Many modern UNIX like Kernels have the ability to load and unload drivers as external modules. There are two approaches to module loading at boot time:

  1. Loading each desired module using a dedicated service (e.g. by running modprobe moduleName in a service script on Linux.).
  2. Using the configuration directory /etc/modules.load.d and load all modules on boot at once using a single service. Corresponding source directories for this are part of the Kernel specific packages like goetia-linux, goetia-freebsd, ... . Documentation about the directory structure of /etc/modules.load.d can be found at the documentation pages corresponding to the modules services under these links.

The appproach described in point 1. has the advantage that dependecy managment can be employed: if a daemon requires a specific driver, it can declare dependency upon the oneshot service loading the corresponding module, which causes the module to be loaded only if needed. Further, this makes the depending service not have to wait for the loading of all modules.

Examples

Linux

Create a source directory of type oneshot at the system configuration directory, called load-@MODULE@. @MODULE@ should be a descriptive name for the module loaded by the service.

The resulting file hierarchy looks like this:

src/modules/load-@MODULE@
├── down              # see below
├── type              # oneshot
└── up                # see below
			

up script:

#!/bin/execlineb -P

fdmove -c 2 1

modprobe @exactNameOfTheModule@   # OR modrope /path/to/the/module
			

down script:

#!/bin/execlineb -P

fdmove -c 2 1

modprobe -r @exactNameOfTheModule@
			

FreeBSD

Create a source directory of type oneshot at the system configuration directory, called load-@MODULE@. @MODULE@ should be a descriptive name for the module loaded by the service.

The resulting file hierarchy looks like this:

src/modules/load-@MODULE@
├── down              # see below
├── type              # oneshot
└── up                # see below
			

up script:

#!/bin/execlineb -P

fdmove -c 2 1

kldload -n @exactNameOfTheModule@   # OR kldload -n /path/to/the/module
			

down script:

#!/bin/execlineb -P

fdmove -c 2 1

kldunload @exactNameOfTheModule@