Setting Linux kernel module parameters

Many Linux kernel modules have parameters that can be set at load time, boot time, and sometimes run-time. In the following I'll demonstrate each method.

Setting module parameter at load time

The easiest way to load kernel modules at run time is using the modprobe command. To set a module parameter put the parameter name and value in the modprobe command line:

modprobe foo parameter=value

The command modinfo lists the parameters that a given kernel module accepts, with the expected type of each parameter. For example, on my Linux 3.2 based system the command modinfo ambassador shows the following parameters info:

parm:           debug:debug bitmap, see .h file (ushort)
parm:           cmds:number of command queue entries (uint)
parm:           txs:number of TX queue entries (uint)
parm:           rxs:number of RX queue entries [4] (array of uint)
parm:           rxs_bs:size of RX buffers [4] (array of uint)
parm:           rx_lats:number of extra buffers to cope with RX latencies (uint)
parm:           pci_lat:PCI latency in bus cycles (byte)

Simple values of type byte or uint are represented by a number:

modprobe ambassador debug=1

Array values are set using a comma separated list of values:

modprobe ambassador rxs=1000,2000,3000,4000

String (charp) values are set using a string:

modprobe parport_pc init_mode=epp

Setting module parameters at boot time

When a module is compiled into the kernel you can't load it at run time, and you can't set its parameters either. You can, however, set the module parameters from the kernel command line as described in Documentation/kernel-parameters.txt. The equivalent of the modprobe commands above, are the following strings in the kernel command line:




Setting module parameters at run-time

Sometimes a kernel modules allows setting a parameter at run time. In this case you'll find the parameter under /sys/module/modulename/parameters/, with writable file permissions. The debug parameter of the ambassador module is an example of such a parameter. Set a value to this parameter with a simple echo command:

echo -n 1 > /sys/module/ambassador/parameters/debug