Linux: How to load a kernel module automatically at boot time

Linux: How to load a kernel module automatically at boot time

To load a kernel module automatically at boot time on a Linux system, you can use the modprobe command with the -a option. The modprobe command is used to add or remove modules from the Linux kernel.

Here's the basic syntax for the modprobe command:

modprobe [-a] module-name
Sour‮w:ec‬ww.lautturi.com

module-name is the name of the kernel module that you want to load.

To load a kernel module automatically at boot time, you will need to create a configuration file in the /etc/modules-load.d directory. This configuration file should contain the name of the kernel module that you want to load, one module per line.

For example, to load the nfs kernel module at boot time, you can create a configuration file /etc/modules-load.d/nfs.conf with the following content:

nfs

You can also use the -a option to load multiple kernel modules at the same time. For example, to load the nfs and cifs kernel modules at boot time, you can create a configuration file /etc/modules-load.d/network-fs.conf with the following content:

nfs
cifs

Once you have created the configuration file, the kernel modules will be loaded automatically at boot time.

It's important to note that the modprobe command does not work for kernel modules that are built into the kernel. To load a built-in kernel module, you will need to modify the kernel boot parameters. You can do this by adding the name of the kernel module to the GRUB_CMDLINE_LINUX variable in the /etc/default/grub file, and then running the update-grub command to update the GRUB boot menu.

GRUB_CMDLINE_LINUX="modulename"
update-grub

Overall, the modprobe command is a useful tool for loading kernel modules.

Created Time:2017-10-30 10:17:45  Author:lautturi