Configure kernel module options in Debian by creating drop-in files in /etc/modprobe.d/. This directory is the standard, persistent location for module parameters and avoids the complexity of modifying bootloader configurations like /etc/default/grub. Using modprobe ensures settings apply correctly during the early boot sequence without interfering with other system services.
The Role of /etc/modprobe.d
The /etc/modprobe.d/ directory serves as the primary configuration hub for kernel modules in Debian-based systems. When the system initializes hardware or loads specific drivers, it consults these configuration files to determine how each module should behave. Unlike temporary runtime adjustments made via sysfs, changes here persist across reboots, making them essential for permanent tuning.
You can place individual configuration files directly inside this directory. The filenames typically end with a .conf extension, although any name works as long as it is readable. The system processes these files in alphabetical order, which allows you to structure your configurations logically. For instance, you might create a file named nvidia.conf for graphics driver settings or usb-storage.conf for storage controller behaviors. This modular approach keeps your system administration clean and prevents a single monolithic file from becoming unmanageable.
Why Avoid /etc/default/grub?
While some older documentation suggests setting module options via the GRUB bootloader configuration, this method is generally discouraged for routine module tuning. Modifying /etc/default/grub requires editing the GRUB_CMDLINE_LINUX variable and then running update-grub to regenerate the bootloader config. This process is error-prone because a syntax error can prevent your system from booting entirely.
Furthermore, passing arguments through the kernel command line is less flexible than using modprobe. The command line passes raw strings to the kernel, whereas modprobe understands module-specific parameter types and dependencies. If you need to set multiple parameters for different modules, managing them all in a single GRUB string becomes messy and difficult to audit. The /etc/modprobe.d/ approach separates concerns, keeping bootloader settings distinct from driver configurations. This separation aligns with Debian’s philosophy of maintaining clear boundaries between system initialization and component behavior.
Creating Configuration Files
To add a new option, create a text file in /etc/modprobe.d/. You will need root privileges to write to this directory. Use a text editor such as nano or vim to create a new file. For example, to configure the snd_hda_intel audio module, you might create /etc/modprobe.d/snd-hda-intel.conf.
Inside this file, use the options directive followed by the module name and the desired parameters. The syntax is straightforward: options modulename param1=value1 param2=value2. Ensure there are no spaces around the equals sign. Once saved, the next time the module is loaded, whether at boot time or manually, it will read these values. You do not need to restart the system immediately to see the effect if you unload and reload the module using modprobe -r and modprobe, though a reboot is often safer for critical drivers.
Handling Module Dependencies and Aliases
Sometimes, you may need to configure a module that is not loaded automatically. In Debian, you can also use the install directive to run commands when a module is loaded. This is useful for complex setups where you need to load auxiliary modules or set environment variables before the main driver initializes. However, for most simple parameter tweaks, the options line is sufficient and preferred for its simplicity.
If you encounter issues where your settings are ignored, check for conflicting configurations. Debian may have default settings in /lib/modprobe.d/ or /usr/lib/modprobe.d/. These directories contain vendor-provided defaults. Your files in /etc/modprobe.d/ take precedence over those in /usr/lib/modprobe.d/ due to the ordering rules defined by the depmod utility. This hierarchy ensures that user customizations always override package defaults, providing a reliable way to maintain your preferred configuration.
Verifying Your Configuration
After applying changes, verify that they have taken effect. You can inspect the current parameters of a loaded module by reading files in /sys/module/module_name/parameters/. For example, checking /sys/module/snd_hda_intel/parameters/model will show the active value. If the value matches what you configured, your setup is correct. If it does not, ensure that the module was actually loaded after your configuration file was created. Sometimes, modules are cached in the initramfs, requiring an update to the initial ramdisk.
To ensure your changes are included in the boot image, run update-initramfs -u. This command rebuilds the initial ramdisk, incorporating any new or modified module configurations. Without this step, your settings might only apply after the root filesystem is mounted, potentially causing early boot failures for critical hardware like storage controllers or network interfaces. Regularly updating the initramfs after changing module options is a best practice in Debian administration.
Frequently Asked Questions
How do I remove a kernel module option?
Delete or comment out the relevant line in the corresponding file within /etc/modprobe.d/. After saving the change, you must either reboot or reload the module using modprobe -r and modprobe for the removal to take effect.
Can I set module options temporarily without editing files?
Yes, you can pass options directly to modprobe at the command line, such as sudo modprobe module_name option=value. However, these settings are lost upon reboot unless you also add them to a configuration file in /etc/modprobe.d/.
What happens if I make a typo in a modprobe config file?
Modprobe typically ignores lines with syntax errors and logs warnings to dmesg. It rarely causes a boot failure, but the specific option will not be applied. Always check dmesg for errors if a module behaves unexpectedly after configuration.
Do I need to run update-grub after changing modprobe files?
No, update-grub is only required when you modify bootloader settings in /etc/default/grub. Changes in /etc/modprobe.d/ do not affect the bootloader configuration. You may need to run update-initramfs -u instead.
Where are the default module settings stored?
Default settings provided by Debian packages are located in /usr/lib/modprobe.d/ or /lib/modprobe.d/. User configurations in /etc/modprobe.d/ always override these defaults, ensuring your custom settings take precedence.