commit:     eccc25ea093340a4e3ba662ed8d9e858800cd134
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Wed Nov 20 00:23:45 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Sun Nov 24 19:59:15 2019 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=eccc25ea

initrd.scripts: modules_load() refactored

- Add support for LABEL/UUID in root kernel parameter

- When loading network, always load all network modules
  even when root block device is already available

- Always load crypto and USB module group when CRYPT_{ROOT,SWAP}
  is set.

- Always load fs module group.

- Add gk.hw.load-all kernel command-line argument to allow
  user to force loading of all module groups.

Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 defaults/initrd.defaults |  1 +
 defaults/initrd.scripts  | 43 ++++++++++++++++++++++++++++++++++++++++---
 defaults/linuxrc         |  8 ++++++++
 doc/genkernel.8.txt      |  7 +++++++
 4 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults
index 8937e65..32f99ec 100644
--- a/defaults/initrd.defaults
+++ b/defaults/initrd.defaults
@@ -72,6 +72,7 @@ VERIFY=0
 IP='dhcp'
 GK_BOOTFONT_DISABLED=0
 GK_DEBUGMODE_STATEFILE="/tmp/debug.enabled"
+GK_HW_LOAD_ALL_MODULES=0
 GK_INIT_LOG='/tmp/init.log'
 GK_INIT_LOG_COPYTO=
 GK_INIT_LOG_COPYTO_DEFAULT='/genkernel-boot.log'

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index 1004ff5..053ac68 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -29,6 +29,37 @@ modules_load() {
 modules_scan() {
        local MODS
        local loaded
+       local smart_loading=yes
+       local _root_dev
+       local root_dev_found="Root block device found, skipping loading of 
module group \"${1}\" ..."
+
+       if [ "${GK_HW_LOAD_ALL_MODULES}" = '1' ]
+       then
+               smart_loading=
+       elif [ "${1}" = "net" ]
+       then
+               # We already load network modules only when we need
+               # network so don't stop loading network modules when
+               # $REAL_ROOT is already present or we will probably
+               # end up without network we wanted ...
+               smart_loading=
+       elif [ "${1}" = "fs" ]
+       then
+               # We don't know if kernel supports root filesystem so
+               # better load all filesystems ...
+               smart_loading=
+       elif [ -n "${CRYPT_ROOT}" ] || [ -n "${CRYPT_SWAP}" ]
+       then
+               if [ "${1}" = "crypto" ]
+               then
+                       smart_loading=
+               elif [ "${1}" = "usb" ]
+               then
+                       # We don't know if user is using an USB keyboard to
+                       # enter passphrase so better load USB ...
+                       smart_loading=
+               fi
+       fi
 
        MODS=$(cat /etc/modules/${1} 2>/dev/null)
        [ -n "${MODS}" ] && [ -z "${QUIET}" ] && \
@@ -54,10 +85,16 @@ modules_scan() {
                                printf "%b\n" "${BOLD}   ::${NORMAL} Skipping 
${x} ..."
                elif [ "${MLOAD}" = "${MLIST}" ]
                then
-                       if [ "${ROOTFSTYPE}" != 'auto' ] && [ -b "${REAL_ROOT}" 
]
+                       if [ -n "${smart_loading}" ]
                        then
-                               echo "Root block device found, continuing ..."
-                               break
+                               _root_dev=$(findfs "${REAL_ROOT}" 2>/dev/null)
+
+                               if [ $? -eq 0 ] && [ -n "${_root_dev}" ] && [ 
-b "${_root_dev}" ]
+                               then
+                                       log_msg "${root_dev_found}"
+                                       printf "%b" "${root_dev_found}"
+                                       break
+                               fi
                        fi
 
                        if is_debug

diff --git a/defaults/linuxrc b/defaults/linuxrc
index ee46293..f01203b 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -283,6 +283,14 @@ do
                        fi
                        unset tmp_disabled
                ;;
+               gk.hw.load-all=*)
+                       tmp_disabled=${x#*=}
+                       if is_true "${tmp_disabled}"
+                       then
+                               GK_HW_LOAD_ALL_MODULES=1
+                       fi
+                       unset tmp_disabled
+               ;;
                gk.log.disabled=*)
                        tmp_disabled=${x#*=}
                        if is_true "${tmp_disabled}"

diff --git a/doc/genkernel.8.txt b/doc/genkernel.8.txt
index bee3017..cb2009f 100644
--- a/doc/genkernel.8.txt
+++ b/doc/genkernel.8.txt
@@ -787,6 +787,13 @@ when not set. This will allow remote user to provide 
answer through
     will load that font. This boolean option allows you to disable
     loading of the user embedded bootfont.
 
+*gk.hw.load-all*=<...>::
+    By default, genkernel loads various module groups (nvme, sata,
+    scsi, pata, usb...) until block device specified in *root* parameter
+    becomes available. This boolean option allows you to force
+    loading of all module groups regardless whether root device is
+    already available.
+
 *gk.log.disabled*=<...>::
     By default, any shown message and external command calls will be logged
     to '/tmp/init.log' in initramfs. This boolean option allows you to

Reply via email to