[projects/geninitrd] add support for using modprobe instead of insmod

atler atler at pld-linux.org
Tue Nov 2 01:50:12 CET 2021


commit 2959c3b96a70fbee3110465418c54ab5ce202d42
Author: Jan Palus <atler at pld-linux.org>
Date:   Mon Nov 1 22:38:55 2021 +0100

    add support for using modprobe instead of insmod
    
    allows honouring module parameters passed in kernel command line

 geninitrd | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 55 insertions(+), 8 deletions(-)
---
diff --git a/geninitrd b/geninitrd
index 444addb..8baaffa 100755
--- a/geninitrd
+++ b/geninitrd
@@ -23,7 +23,8 @@ target=""
 kernel=""
 force=""
 verbose=""
-MODULES=""
+MODULES_TO_INSTALL=""
+MODULES_TO_LOAD=""
 img_vers=""
 fstab=/etc/fstab
 modext=.o
@@ -478,13 +479,19 @@ find_module() {
 
 		# add each module only once
 		local m have=0
-		for m in $MODULES; do
+		for m in $MODULES_TO_INSTALL; do
 			[ $m = $mod ] && have=1
 		done
 		if [ $have = 0 ]; then
-			MODULES="$MODULES $mod"
+			MODULES_TO_INSTALL="$MODULES_TO_INSTALL $mod"
+			if ! is_yes "$USE_MODPROBE"; then
+				MODULES_TO_LOAD="$MODULES_TO_LOAD $mod"
+			fi
 		fi
 	done
+	if is_yes "$USE_MODPROBE" && [ -n "$mod" ]; then
+		MODULES_TO_LOAD="$MODULES_TO_LOAD $mod"
+	fi
 }
 
 # install a file to temporary mount image.
@@ -578,6 +585,12 @@ inst_exec() {
 	done
 }
 
+files_exist() {
+	local start_point="$1" pattern="$2"
+	shift
+	test -n "$(find "$start_point" -mindepth 1 -maxdepth 1 -name "$pattern" -print -quit)"
+}
+
 # output modules.conf / modprobe.conf
 modprobe_conf() {
 	echo "$modprobe_conf_cache"
@@ -836,7 +849,10 @@ modules_add_linuxrc() {
 
 		# name of the module
 		local module=${modpath##*/}; module=${module%$modext}
-		local options=$(modprobe_options "$module")
+		local options
+		if ! is_yes "$USE_MODPROBE"; then
+			options=$(modprobe_options "$module")
+		fi
 		local genericname=$(echo $module | tr - _)
 		local usleep=$(eval echo \$MODULE_${genericname}_USLEEP)
 		local firmware=$(eval echo \$MODULE_${genericname}_FIRMWARE)
@@ -864,7 +880,11 @@ modules_add_linuxrc() {
 			done
 		fi
 
-		echo "insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
+		if is_yes "$USE_MODPROBE"; then
+			echo "/sbin/modprobe $module $options" | add_linuxrc
+		else
+			echo "insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
+		fi
 		if [ -n "$usleep" ]; then
 			echo "usleep $usleep" | add_linuxrc
 		fi
@@ -1252,6 +1272,12 @@ while [ $# -gt 0 ]; do
 	--without-fbcondecor)
 		FB_CON_DECOR=no
 		;;
+	--with-modprobe)
+		USE_MODPROBE=yes
+		;;
+	--without-modprobe)
+		USE_MODPROBE=no
+		;;
 	--without-swsusp)
 		USE_SWSUSP=no
 		;;
@@ -1546,7 +1572,7 @@ fi
 find_modules_uvesafb
 find_modules_fbsplash
 
-if [ -n "$ifneeded" -a -z "$MODULES" ]; then
+if [ -n "$ifneeded" -a -z "$MODULES_TO_LOAD" ]; then
 	verbose "No modules are needed -- not building initrd image."
 	exit 0
 fi
@@ -1561,7 +1587,12 @@ ln -s linuxrc $DESTDIR/init
 # create dirs that we really need
 inst_d /{lib,bin,sbin,etc,dev{,/pts,/shm},loopfs,var,proc,run,sys,tmp}
 
-modules_install "$MODULES"
+modules_install "$MODULES_TO_INSTALL"
+
+if is_yes "$USE_MODPROBE"; then
+	inst /lib/modules/$kernel/modules.{builtin,order} /lib/modules/$kernel
+	depmod -b "$DESTDIR" $kernel
+fi
 
 # mknod'ing the devices instead of copying them works both with and
 # without devfs...
@@ -1668,7 +1699,23 @@ EOF
 mount_tmp
 mount_run
 
-modules_add_linuxrc $MODULES
+if is_yes "$USE_MODPROBE"; then
+	if files_exist /lib/modprobe.d '*.conf'; then
+		inst_d /lib/modprobe.d
+		inst /lib/modprobe.d/*.conf /lib/modprobe.d
+	fi
+	if files_exist /etc/modprobe.d '*.conf'; then
+		inst_d /etc/modprobe.d
+		inst /etc/modprobe.d/*.conf /etc/modprobe.d
+	fi
+	if files_exist /etc/modprobe.d/$kernel '*.conf'; then
+		inst_d /etc/modprobe.d/$kernel
+		inst /etc/modprobe.d/$kernel/*.conf /etc/modprobe.d/$kernel
+	fi
+	inst_exec /sbin/modprobe /sbin
+fi
+
+modules_add_linuxrc $MODULES_TO_LOAD
 
 # TODO: rewrite for busybox
 #if [ -n "$loopDev" ]; then
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/geninitrd.git/commitdiff/95afa3ecf50575a1bc44cf0510c3b96878418f71



More information about the pld-cvs-commit mailing list