Article Title: proficient in building initramfs stepbystep (7 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
22. kernel module support
So far, no kernel module support has been involved in init ramfs construction, and all hardware drivers used are directly compiled into the kernel. Now let's take a look at how to make init ramfs support kernel modules.
First, the Kernel configuration must support the module and the automatic loading function of the kernel module: Activate the following configuration items in the Kernel configuration menu, compile it into the kernel Load module support/Enable loadable module support/Automatic kernel loading;
Then, compile the required hardware driver configuration module, for example, compile the driver of the hard drive controller on my machine into a module, select
Device Driver
| ----> SCSI device support
| ----> SCSI disk support
| -----> Verbose SCSI error reporting (not required, but easy to locate)
| -----> SCSI low-level drivers
| ----> Serial ATA (SATA) support
| ----> Intel PIIX/ich sata support
Configure them as modules.
Finally, compile the kernel and install the compiled kernel module to the image directory:
Make
Make INSTALL_MOD_PATH = ~ /Init ramfs-test/image modules_install
After the command is executed, four kernel modules are installed in the image/lib/modules/2.6.17.13/kernel/drivers/scsi Directory: scsi_mod.ko, sd_mod.ko, ata_piix.ko, and libata. ko, which is the driver of the required hard disk controller.
Now, you are ready to use the cpio command to generate inintramfs. However, to facilitate subsequent experiments, we can change the init script
#! /Bin/sh
Mount-t proc/proc
Mount-t sysfs/sys
Mdev-s
Exec/bin/sh
Run the switch_root command to enable the system to enter the shell environment after startup and run the exec command to set the shell pid to 1.
23. Experiment: Use the kernel module in init ramfs to install the Hard Disk File System
Start the system with the newly generated init ramfs, and the kernel does not automatically load the drive program of the hard disk controller. Therefore, there are no hard disk device files such as sda in the/dev directory. Okay, let's load the kernel module File ourselves. Unfortunately, The modprobe command of busybox is not executed normally and cannot load the kernel module. It is suspected that the modprobe command of busybox has a problem in configuration or compilation. In the future, take the time to locate it and load it with the insmod command in sequence. View/lib/modules/2.6.17.13/modules. dep, find out the dependency between the four modules, and execute the following command to load:
Insmod scsi_mod
Insmod libata
Insmod ata_piix
Insmod sd_mod
And then use
Mdev-s
Command to generate the device file of the hard disk.
Now, you can install the hard disk partition of CLFS and switch the root file system to the hard disk partition of CLFS:
Mount/dev/sda8/mnt
Exec switch_root/mnt/sbin/init
After the system is started to CLFS normally, we can use the drive module of the hard disk controller in init ramfs to install the hard disk partition.
24. hotplug mode of mdev
In the above test, after loading the driver module, we call the mdev-s command to generate the device file of the hard disk. In fact, you can use the hotplug mode of mdev to automatically generate the corresponding device file when loading the kernel:
Before executing the insmod command, use
Echo/sbin/mdev>/proc/sys/kernel/hotplug
Command to set the system's hotplug program to mdev.
When the module is loaded using the insmod command, the system automatically calls mdev to generate the corresponding device file.
Note: The kernel must be configured to support the hotplug function, but the simplest Kernel configuration solution of CLFS mentioned above does not support hotplug.