This is a Dracut module that will add all loaded kernel modules to the initramfs. It doesn't do any filtering or other silly things, just requires that the host building the initramfs has present and correct /proc/modules.
These instructions work for Dracut on Arch, but should work on any distro. You might have to slightly adjust the paths below (look up Dracut package contents on your distro to figure out the correct paths).
- Clone this Git repo into
/usr/lib/dracut/modules.d/99loaded-modules(this dir should containmodule-setup.sh). - Run
sudo chmod +x /usr/lib/dracut/modules.d/99loaded-modules/module-setup.sh - In
/etc/dracut.conf(or in a file under/etc/dracut.conf.d), addadd_dracutmodules+=loaded-modules. - Optionally, drop
loaded-modules.conffrom this repo into/etc/dracut.conf.dif you'd like. - Regenerate the initramfs and see if the amount of included modules increased (
lsinitrdcan help, try something likelsinitrd /boot/initramfs-test.img | grep usr/lib/modules | wc -lon images with and without this module).