How does one automatically load modules during system startup in Linux?
Source: Internet
Author: User
How does Linux automatically load modules when the system is started-Linux general technology-Linux programming and kernel information, the following is a detailed description. To find out how to automatically load modules when the system starts, I have searched for a long time. Many people on the Internet have asked this question, but there is no correct answer, either in the Chinese community or in the English community, the answer is nothing more than about modprobe. conf and modprobe should be discussed, or try different methods for specific problems. Some also suggest writing modprobe modulename into rc. local, but never thought, rc. local execution is placed behind the entire startup sequence, and init is started. d. The service defined below is in rc. if a service needs to use this module, it will not work.
During LVS testing, because the Kernel (2.6.21-1) of my Fedora7 does not load the ip_vs module by default, and the Kernel contains compiled IPVS-related modules, put them in: /lib/modules/2.6.21-1.3194.fc7/kernel/net/ipv4/ipvs/, which is shown below:
Ip_vs.ko is the basic module of IPVS and cannot work without loading IPVS (errors will be reported when running ipvsadm), while others are the scheduling algorithms of IPVS or the auxiliary modules of specific protocols, it must be loaded when needed.
If the system is manually loaded during running, modprobe ip_vs and modprobe ip_vs_sh are required.
To learn how to Automatically load the module (Automatically load kernel modules) at system startup, you must first understand the order in which the system is started, all these startup operations are controlled by files and scripts. Because Google and Baidu cannot solve the problem, man modprobe and man modprobe. conf find that they are not files to be modified.
So the boot Shutdown Process and Loader of the bird's brother are as follows:
1. The entire boot process is
(1) load the BIOS hardware information and obtain the code of the first boot device
(2) read the boot information of the boot Loader (grub) of the mbr of the first boot device.
(3) load the OS Kernel information, decompress the Kernel, and try to drive the hardware.
(4) The Kernel executes the init program and obtains the run-lebel information (such as 3 or 5)
(5) run/etc/rc. d/rc. sysinit in init.
(6) Start the kernel plug-in Module (/etc/modprobe. conf)
(7) init executes various run-level Scripts and starts the service
(8) run/etc/rc. d/rc. local in init.
(9) run/bin/login and wait for the user Login
(10) log in to Shell
It seems that the correct method is to put the modules to be loaded in (5) or (6), but as many people try to modify modprobe on the network. conf fails (for example, in modprobe. install ip_vs...) in conf ...). So I modified/etc/rc. d/rc. sysinit and loaded it successfully.
Initially try to add modprobe. conf ip_vs at the end of rc. sysinit. After restart, lsmod | grep ip_vs will find that it is loaded automatically.
Then, follow the Loading Method of other modules in rc. sysinit to expand and modify the script file, and add the following section at the end:
# Load lvs ipvs modules
If [-d/lib/modules/$ unamer/kernel/net/ipv4/ipvs]; then
For module in/lib/modules/$ unamer/kernel/net/ipv4/ipvs/*; do
Module =$ {module ##*/}
Module =$ {module %. ko}
Modprobe $ module>/dev/null 2> & 1
Done
Fi
All modules under/lib/modules/2.6.21-1.3194.fc7/kernel/net/ipv4/ipvs/are automatically loaded.
Where:
If statement to check whether the directory of ipvs module exists
The for loop traverses all files in the directory.
Module =$ {module ### */}: where # indicates to delete the character from the front, */indicates to delete the character to the last /, if one # is used, only the first/is deleted /. If the variable is followed by #, the string after # gets the longest (until the end). If the variable is followed by #, the smallest segment is obtained.
Module =$ {module %. ko}: indicates to delete. ko from the backend. If the variable is followed by %, the string after % gets the longest (until the beginning). If % is followed, the smallest segment is obtained.
In this way, the module name is obtained after two modifications of multiple modules, that is, the file name does not contain the path or. ko suffix.
Modprobe $ module>/dev/null 2> & 1: load the module. The output points to an empty device.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.