How can I ensure certain kernel modules are included in the initrd or initramfs in RHEL?
Environment
- Red Hat Enterprise Linux
Issue
- How can I configure the system to load a module early in the boot process?
- How can I ensure
mkinitrdincludes certain modules in RHEL 4 and 5? - How can I ensure dracut includes certain modules in RHEL 6, 7, 8, 9 & 10?
- When I manually run
mkinitrdI can include my own modules using--with=<module>, but I need to configure the system so that modules will be included whenmkinitrdis run automatically by akernelrpm installation.
Resolution
The method for including kernel modules in the initrd / initramfs varies based on RHEL version. In all examples replace <kernel module> with the module name, not including .ko.
RHEL 6, 7, 8, 9 and 10.
There are two methods to achieve this:
IMPORTANT NOTE: Replace <kernelVersion> with the full version of the kernel you wish to rebuild in the below steps.
EXAMPLE: (for kernel version "5.14.0-70.22.1.el9_0.x86_64")
# cp /boot/initramfs-5.14.0-70.22.1.el9_0.x86_64.img /boot/5.14.0-70.22.1.el9_0.x86_64.bak.$(date +%m-%d-%H%M%S).img
# dracut -f /boot/initramfs-5.14.0-70.22.1.el9_0.x86_64.img 5.14.0-70.22.1.el9_0.x86_64
Method 1
Step 1. Make a backup copy of the initramfs:
# cp /boot/initramfs-<kernelVersion>.img /boot/<kernelVersion>.bak
Step 2. Use the --add-drivers option and specify the module name[without.ko extension] when manually building the initramfs with dracut:
# dracut -fv --add-drivers <kernel module> /boot/initramfs-<kernelVersion>.img <kernelVersion>
Step 3. Verify the module has been loaded in initramfs image file created by dracut:
# lsinitrd /boot/initramfs-<kernelVersion>.img | grep <module_name>
Method 2
Step 1. Add a space-separated list of kernel modules(minus any file extensions such as `.ko`) to the `add_drivers` directive in `/etc/dracut.conf` or `/etc/dracut.conf.d/
add_drivers+="<kernel module>"
Step 2. Make a backup copy of the initramfs:
# cp /boot/initramfs-<kernelVersion>.img /boot/<kernelVersion>.bak
Step 3. Rebuild the initramfs:
# dracut -fv /boot/initramfs-<kernelVersion>.img <kernelVersion>
Step 4. Verify the module has been loaded in initramfs image file created by dracut:
# lsinitrd /boot/initramfs-<kernelVersion>.img | grep <module_name>
RHEL 4 and 5
Three methods can be used to include a kernel module in the initial RAM disk:
-
Use the
--withoption when manually building the ram disk withmkinitrd:# mkinitrd --with=<kernel module> /boot/initrd-$(uname -r).img $(uname -r) -
For storage-related modules put an alias in
/etc/modprobe.conf. If more than one is needed increment the alias entry:alias scsi_hostadapter <kernel module> alias scsi_hostadapter1 <kernel module> alias scsi_hostadapter2 <kernel module>
The above will cause the kernel module (plus any dependencies) to be included in the initrd.
-
For non-storage kernel modules, add a line to /etc/modprobe.conf similar to the following:
install <kernel module> /sbin/modprobe -q --ignore-install <kernel module>; /bin/true
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.