- Linux: How to load a kernel module automatically at boot time
- Kernel module
- Contents
- Obtaining information
- Automatic module loading with systemd
- Manual module handling
- Setting module options
- Manually at load time using modprobe
- Using files in /etc/modprobe.d/
- Using kernel command line
- Aliasing
- Blacklisting
- Using files in /etc/modprobe.d/
- Using kernel command line
- Troubleshooting
- Modules do not load
Linux: How to load a kernel module automatically at boot time
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
Try this method to load module at boot time
#echo module_name >> /etc/rc.modules
#chmod +x /etc/rc.modules
Hello,
I use Ubuntu 11.4 (Linux 2.6.38)
I tried both the files modules.conf and rc.modules.
Unfortunately the modules is not loaded.
Do you have any idea?
Thanks,
Yacob.
/etc/modules is the file you’re looking for Yacob
Thank you.
I tried this file also but the modules are not loaded.
Do you have another idea?
Thanks,
Yacob.
Try this:
echo “modprobe module_name” >> /etc/modprobe.d/modeprobe.conf
My understanding is that modprobe.conf and modules.conf are only configuration files. They do not invoke modprobe. All they do is provide modprobe with information about what it should do when it is invoked.
Scripts that are run immediately after the boot (in the start up sequence) are called rc scripts. Many systems have a script called rc.local. This script is arranged in such a way (normally with symlinks) that it is executed as the last script in the start up sequence. This is a good place to put additional commands that are required and which have not been invoked already. The normal location of this script is /etc/rc.d/rc.local.
Therefore if the modprobe command is added to that script it will be executed at the end, and before a login shell prompt is provided. Determine the location of modprobe. If, for example, it is /sbin/modprobe, then the end of the rc.local file should look something like this:
# Put your required modprobe command here:
/sbin/modprobe name-of-module
Note that if the module in question requires options, then a place to put these is in /etc/modprobe.conf, because when modprobe runs it will read that configuration file and pick up any required options from there.
Your steps helped me. It works.
I wanted to bring 8021q after every reboot.
I added it in /etc/rc.local file.
For me /etc/rc.d/rc.local doesn’t exist, I have Ubuntu 14.04 platform.
I am glad that helped you.
I use “linux from scratch”. That is a system in which the operating system is built step by step, not simply installed from some disk or web site. It takes a long time but can give some improvements in understanding and control.
Different distributions tend to store files (including configuration files) in different places. It appears that with Ubuntu there is a configuration file called /etc/modules which lists the names of modules to be loaded at boot time. If so then that might be a better place to put the 8021q module name. rc.local tends to be used for “local” after thoughts – anything unusual that needs to be done for that one host. There is a web page that describes Ubuntu’s /etc/modules here:
https://help.ubuntu.com/community/Loadable_Modules
The use of the 8021q module for vlan’s in Ubuntu is described here:
https://wiki.ubuntu.com/vlan
The section “Making it permanent”, which comes at the end of the article, seems to be relevant in your case. If that’s right then it might be tidier to do it that way than to use rc.local (even though it does work).
Hi all,
i am new buddy to Linux module programming.I am facing same problem in loading a module at boot time in Ubuntu 11.04. Can any one tell me the perfect steps to load the module at the boot time.
same problem here. I did change /etc/modules, but where do I put the module object itself so moprob can find it?
To put the question in another way, what are the default lcoation that modprobe look for modules?
i i tried to put the .KO file with the all drivers .KO file.But that doesn’t worked.
The other way to do this is configuring the Kconfig file and recompile the kernel.
But i am not getting proper documentation.
I figured that out.
add a line to /etc/modules for your module (without .ko)
copy the module file to /lib/modules/
do
sudo depmod -a
reboot and it worked for me on Ubuntu 12.04
error. copy the module file to /lib/modules/
This solution worked for me too on 12.04 . Thanks redjupiter.
Thanks redjupiter. It worked with ubuntu 11.04.
Glad it worked. one correction for others:
copy the module file to /lib/modules/
there is no /etc/modules…rather /etc/modprobe.conf is there…
please suggest
quite often there is no need for a modprobe configuration file. As I said before (see previous remark from November, 2011), modprobe is not invoked by that configuration file. Its just that if you need to provide it with additional information, then that can be done from the configuration file. The name used for the configuration file has changed a bit between different versions, and sometimes it is given as a file in a directory, modprobe.d. On my workstation (built from scratch) there is no modprobe configuration file. Its not needed.
The critical thing usually is making the kernel aware of modules. To do this you have to put the module in the right place, and run depmod to update the module dependencies.
Perhaps if you explained what you were trying to do, then it would be possible to provide a more specific explanation.
I would like to add that some systems have the modules file in /etc/sysconfig/modules
To load a module by filename (i.e. one that is not installed in /lib/modules/$(uname -r)/):
# insmod filename [args]
To unload a module:
# modprobe -r module_name
Or, alternatively:
# rmmod module_name
Check this link for more info on how to work with modules:
https://wiki.archlinux.org/index.php/kernel_modules
You forgot to mention about unsupported modules file.
Источник
Kernel module
Kernel modules are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the functionality of the kernel without the need to reboot the system.
To create a kernel module, you can read The Linux Kernel Module Programming Guide. A module can be configured as built-in or loadable. To dynamically load or remove a module, it has to be configured as a loadable module in the kernel configuration (the line related to the module will therefore display the letter M ).
Contents
Obtaining information
Modules are stored in /usr/lib/modules/kernel_release . You can use the command uname -r to get your current kernel release version.
To show what kernel modules are currently loaded:
To show information about a module:
To list the options that are set for a loaded module:
To display the comprehensive configuration of all the modules:
To display the configuration of a particular module:
List the dependencies of a module (or alias), including the module itself:
Automatic module loading with systemd
Today, all necessary modules loading is handled automatically by udev, so if you do not need to use any out-of-tree kernel modules, there is no need to put modules that should be loaded at boot in any configuration file. However, there are cases where you might want to load an extra module during the boot process, or blacklist another one for your computer to function properly.
Kernel modules can be explicitly listed in files under /etc/modules-load.d/ for systemd to load them during boot. Each configuration file is named in the style of /etc/modules-load.d/program.conf . Configuration files simply contain a list of kernel modules names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is # or ; are ignored.
See modules-load.d(5) for more details.
Manual module handling
Kernel modules are handled by tools provided by kmod package. You can use these tools manually.
To load a module:
To load a module by filename (i.e. one that is not installed in /usr/lib/modules/$(uname -r)/ ):
To unload a module:
Setting module options
To pass a parameter to a kernel module, you can pass them manually with modprobe or assure certain parameters are always applied using a modprobe configuration file or by using the kernel command line.
Manually at load time using modprobe
The basic way to pass parameters to a module is using the modprobe command. Parameters are specified on command line using simple key=value assignments:
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:
Using kernel command line
If the module is built into the kernel, you can also pass options to the module using the kernel command line. For all common bootloaders, the following syntax is correct:
Simply add this to your bootloader’s kernel-line, as described in Kernel Parameters.
Aliasing
Aliases are alternate names for a module. For example: alias my-mod really_long_modulename means you can use modprobe my-mod instead of modprobe really_long_modulename . You can also use shell-style wildcards, so alias my-mod* really_long_modulename means that modprobe my-mod-something has the same effect. Create an alias:
Some modules have aliases which are used to automatically load them when they are needed by an application. Disabling these aliases can prevent automatic loading but will still allow the modules to be manually loaded.
Blacklisting
Blacklisting, in the context of kernel modules, is a mechanism to prevent the kernel module from loading. This could be useful if, for example, the associated hardware is not needed, or if loading that module causes problems: for instance there may be two kernel modules that try to control the same piece of hardware, and loading them together would result in a conflict.
Some modules are loaded as part of the initramfs. mkinitcpio -M will print out all automatically detected modules: to prevent the initramfs from loading some of those modules, blacklist them in a .conf file under /etc/modprobe.d and it shall be added in by the modconf hook during image generation. Running mkinitcpio -v will list all modules pulled in by the various hooks (e.g. filesystems hook, block hook, etc.). Remember to add that .conf file to the FILES array in /etc/mkinitcpio.conf if you do not have the modconf hook in your HOOKS array (e.g. you have deviated from the default configuration), and once you have blacklisted the modules regenerate the initramfs, and reboot afterwards.
Using files in /etc/modprobe.d/
Create a .conf file inside /etc/modprobe.d/ and append a line for each module you want to blacklist, using the blacklist keyword. If for example you want to prevent the pcspkr module from loading:
However, there is a workaround for this behaviour; the install command instructs modprobe to run a custom command instead of inserting the module in the kernel as normal, so you can force the module to always fail loading with:
This will effectively blacklist that module and any other that depends on it.
Using kernel command line
You can also blacklist modules from the bootloader.
Simply add module_blacklist=modname1,modname2,modname3 to your bootloader’s kernel line, as described in Kernel parameters.
Troubleshooting
Modules do not load
In case a specific module does not load and the boot log (accessible by running journalctl -b as root) says that the module is blacklisted, but the directory /etc/modprobe.d/ does not show a corresponding entry, check another modprobe source folder at /usr/lib/modprobe.d/ for blacklisting entries.
A module will not be loaded if the «vermagic» string contained within the kernel module does not match the value of the currently running kernel. If it is known that the module is compatible with the current running kernel the «vermagic» check can be ignored with modprobe —force-vermagic .
Источник