How to add kernel module parameters?

57,311

Solution 1

/etc/modules seems to be loaded by /etc/init/module-init-tools.conf. The first argument is the module name, other arguments are the parameters. Adding the following to /etc/modules seems fine:

thinkpad_acpi fan_control=1

To load this module and set these parameters in the very early stage of boot, add the previous line to /etc/initramfs-tools/modules file. After a change in that file, you need to regenerate the ramdisk:

sudo update-initramfs -u

As a possible alternative, you can try to add the options to the kernel line (I haven't tested it myself, but it seems to work for settings like i915.modeset=1. Edit /etc/default/grub and find the line with GRUB_CMDLINE_LINUX_DEFAULT="quiet splash". Replace it by something like:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash thinkpad_acpi.fan_control=1"

To get a list of options for a kernel module:

modinfo -p thinkpad_acpi

This did not work for i915, for that I had to run:

modinfo i915 | grep ^parm

To get the current value of a module parameter, run:

sudo cat /sys/module/MODULE/parameters/PARAM

For the fan_control parameter of the thinkpad_acpi module, you have to run:

sudo cat /sys/module/thinkpad_acpi/parameters/fan_control

If this function returns an error, check if the module was loaded and whether the option exist or not.

Solution 2

Setting module options using files in /etc/modprobe.d/

Files in /etc/modprobe.d/ directory can be used to pass module settings to udev, which will use modprobe to manage the loading of the modules during system boot. Configuration files in this directory can have any name, given that they end with the .conf extension. The syntax is:

/etc/modprobe.d/myfilename.conf
---------------------------------------------------------
options modname parametername=parametervalue

For example:

/etc/modprobe.d/thinkfan.conf
---------------------------------------------------------
# On ThinkPads, this lets the 'thinkfan' daemon control fan speed
options thinkpad_acpi fan_control=1

Source:Kernel modules - ArchWiki


As far as I know, you can use the mentioned method for modules that are automatically loaded at boot time (to avoid unloading and reloading modules with special parameters, as this might be the case for driver modules), and the /etc/modules file for modules that are not automatically loaded at boot time.

Solution 3

With Ubuntu 16.04 one can no longer include kernel module parameters in /etc/modules. An error is generated in the boot log saying it can't find "my_kernel_mod myparam=x".

Instead one needs to put only the kernel module name in /etc/modules and put the options in /etc/modprobe.d/myfilename.conf (as suggested above).

Share:
57,311

Related videos on Youtube

waterloo2005
Author by

waterloo2005

Updated on September 18, 2022

Comments

  • waterloo2005
    waterloo2005 over 1 year

    How to add a kernel module parameter in Ubuntu 11.04?

    Can I use the /etc/module file? If yes, how?

    • Lekensteyn
      Lekensteyn almost 13 years
      Do you mean parameters like i915.modeset=1?
    • waterloo2005
      waterloo2005 almost 13 years
      I mean 'options thinkpad_acpi fan_control=1' in a file under /etc/modprobe.d/ or 'thinkpad_acpi fan_control=1' in /etc/modules ?
  • waterloo2005
    waterloo2005 almost 13 years
    How to know a parameter of module have took effect ? thanks
  • Lekensteyn
    Lekensteyn almost 13 years
    @waterloo2005: You can use /sys for that. See the revised answer.
  • waterloo2005
    waterloo2005 almost 13 years
    I find I do not add parameter in /etc/modules. I only need to add them in /etc/modprobe.d/ . Thanks
  • Lekensteyn
    Lekensteyn almost 13 years
    The distinction between /etc/modules and /etc/modprobe.d: the first applies to modules loaded in the early stage of boot (right after Plymouth starts), the latter is loaded later (by initscripts)
  • Lekensteyn
    Lekensteyn almost 13 years
    I found it out by analysing the source code, you can confirm that modules in modprobe.d is loaded as initscript in /etc/init/module-init-tools.conf and /usr/share/initramfs-tools/scripts/functions line 339 (load_modules, this script is called from /usr/share/initramfs-tools/init which is copied into a initrd). Manual pages: man mkinitramfs, man modules
  • waterloo2005
    waterloo2005 over 12 years
    'sudo cat /sys/module/thinkpad_acpi/parameters/fan_control' gives me 'N' . How to open this function ?
  • Lekensteyn
    Lekensteyn over 12 years
    What do you mean by "open"? Make it 1?
  • Lekensteyn
    Lekensteyn over 12 years
    Which function? Fan control? What do you want to achieve?
  • waterloo2005
    waterloo2005 over 12 years
    Yes , I mean if I need to add 'echo Y > /sys/module/thinkpad_acpi/parameters/fan_control' in my rc.local to make it work.
  • Lekensteyn
    Lekensteyn over 12 years
    Have you added thinkpad_acpi fan_control=1 to /etc/modules and executed suo update-initramfs -u afterwards?
  • waterloo2005
    waterloo2005 over 12 years
    Thanks, A few days ago I install ubuntu11.10 . And forgot to add the line to /etc/modules. Now cat /sys/module/thinkpad_acpi/parameters/fan_control gives Y.