Blame SOURCES/rear-bz2096916.patch

5d051d
commit b06d059108db9b0c46cba29cc174f60e129164f1
5d051d
Author: Johannes Meixner <jsmeix@suse.com>
5d051d
Date:   Tue Mar 9 14:40:59 2021 +0100
5d051d
5d051d
    Merge pull request #2580 from rear/jsmeix-load-nvram-module
5d051d
    
5d051d
    In etc/scripts/system-setup.d/41-load-special-modules.sh
5d051d
    load the nvram kernel module if possible to make /dev/nvram appear
5d051d
    because /dev/nvram should be there when installing GRUB,
5d051d
    see https://github.com/rear/rear/issues/2554
5d051d
    and include the nvram kernel module in the recovery system
5d051d
    because nvram could be a module in particular on POWER architecture
5d051d
    see https://github.com/rear/rear/issues/2554#issuecomment-764720180
5d051d
5d051d
diff --git a/usr/share/rear/build/GNU/Linux/400_copy_modules.sh b/usr/share/rear/build/GNU/Linux/400_copy_modules.sh
5d051d
index d8d733d2..a0ca9084 100644
5d051d
--- a/usr/share/rear/build/GNU/Linux/400_copy_modules.sh
5d051d
+++ b/usr/share/rear/build/GNU/Linux/400_copy_modules.sh
5d051d
@@ -116,8 +116,12 @@ for dummy in "once" ; do
5d051d
     # As a way out of this dilemma we add the below listed modules no longer via conf/GNU/Linux.conf
5d051d
     # but here after the user config files were sourced so that now the user can specify
5d051d
     # MODULES=( 'moduleX' 'moduleY' ) in etc/rear/local.conf to get additional kernel modules
5d051d
-    # included in the recovery system in addition to the ones via an empty MODULES=() setting:
5d051d
-    MODULES+=( vfat
5d051d
+    # included in the recovery system in addition to the ones via an empty MODULES=() setting.
5d051d
+    # nvram could be a module in particular on POWER architecture,
5d051d
+    # cf. https://github.com/rear/rear/issues/2554#issuecomment-764720180
5d051d
+    # and https://github.com/rear/rear/pull/2580#issuecomment-791344794
5d051d
+    MODULES+=( nvram
5d051d
+               vfat
5d051d
                nls_iso8859_1 nls_utf8 nls_cp437
5d051d
                af_packet
5d051d
                unix
5d051d
diff --git a/usr/share/rear/finalize/Linux-ppc64le/660_install_grub2.sh b/usr/share/rear/finalize/Linux-ppc64le/660_install_grub2.sh
5d051d
index 4c2698f3..0cb3ee41 100644
5d051d
--- a/usr/share/rear/finalize/Linux-ppc64le/660_install_grub2.sh
5d051d
+++ b/usr/share/rear/finalize/Linux-ppc64le/660_install_grub2.sh
5d051d
@@ -104,9 +104,39 @@ fi
5d051d
 # Do not update nvram when system is running in PowerNV mode (BareMetal).
5d051d
 # grub2-install will fail if not run with the --no-nvram option on a PowerNV system,
5d051d
 # see https://github.com/rear/rear/pull/1742
5d051d
-grub2_install_option=""
5d051d
+grub2_no_nvram_option=""
5d051d
 if [[ $(awk '/platform/ {print $NF}' < /proc/cpuinfo) == PowerNV ]] ; then
5d051d
-    grub2_install_option="--no-nvram"
5d051d
+    grub2_no_nvram_option="--no-nvram"
5d051d
+fi
5d051d
+# Also do not update nvram when no character device node /dev/nvram exists.
5d051d
+# On POWER architecture the nvram kernel driver could be also built as a kernel module
5d051d
+# that gets loaded via etc/scripts/system-setup.d/41-load-special-modules.sh
5d051d
+# but whether or not the nvram kernel driver will then create /dev/nvram
5d051d
+# depends on whether or not the hardware platform supports nvram.
5d051d
+# I <jsmeix@suse.de> asked on a SUSE internal mailing list
5d051d
+# and got the following reply (excerpts):
5d051d
+# ----------------------------------------------------------------
5d051d
+# > I would like to know when /dev/nvram exists and when not.
5d051d
+# > I assume /dev/nvram gets created as other device nodes
5d051d
+# > by the kernel (probably together with udev).
5d051d
+# > I would like to know under what conditions /dev/nvram
5d051d
+# > gets created and when it is not created.
5d051d
+# > It seems on PPC /dev/nvram usually exist but sometimes not.
5d051d
+# In case of powerpc, it gets created by nvram driver
5d051d
+# (nvram_module_init) whenever the powerpc platform driver
5d051d
+# has ppc_md.nvram_size greater than zero in it's machine
5d051d
+# description structure.
5d051d
+# How exactly ppc_md.nvram_size gets gets populated by platform
5d051d
+# code depends on the platform, e.g. on most modern systems
5d051d
+# it gets populated from 'nvram' device tree node
5d051d
+# (and only if such node has #bytes > 0).
5d051d
+# ----------------------------------------------------------------
5d051d
+# So /dev/nvram may not exist regardless that the nvram kernel driver is there
5d051d
+# and then grub2-install must be called with the '--no-nvram' option
5d051d
+# because otherwise installing the bootloader fails
5d051d
+# cf. https://github.com/rear/rear/issues/2554
5d051d
+if ! test -c /dev/nvram ; then
5d051d
+    grub2_no_nvram_option="--no-nvram"
5d051d
 fi
5d051d
 
5d051d
 # When GRUB2_INSTALL_DEVICES is specified by the user
5d051d
@@ -134,7 +164,7 @@ if test "$GRUB2_INSTALL_DEVICES" ; then
5d051d
         else
5d051d
             LogPrint "Installing GRUB2 on $grub2_install_device (specified in GRUB2_INSTALL_DEVICES)"
5d051d
         fi
5d051d
-        if ! chroot $TARGET_FS_ROOT /bin/bash --login -c "$grub_name-install $grub2_install_option $grub2_install_device" ; then
5d051d
+        if ! chroot $TARGET_FS_ROOT /bin/bash --login -c "$grub_name-install $grub2_no_nvram_option $grub2_install_device" ; then
5d051d
             LogPrintError "Failed to install GRUB2 on $grub2_install_device"
5d051d
             grub2_install_failed="yes"
5d051d
         fi
5d051d
@@ -170,7 +200,7 @@ for part in $part_list ; do
5d051d
         LogPrint "Found PPC PReP boot partition $part - installing GRUB2 there"
5d051d
         # Erase the first 512 bytes of the PPC PReP boot partition:
5d051d
         dd if=/dev/zero of=$part
5d051d
-        if chroot $TARGET_FS_ROOT /bin/bash --login -c "$grub_name-install $grub2_install_option $part" ; then
5d051d
+        if chroot $TARGET_FS_ROOT /bin/bash --login -c "$grub_name-install $grub2_no_nvram_option $part" ; then
5d051d
             # In contrast to the above behaviour when GRUB2_INSTALL_DEVICES is specified
5d051d
             # consider it here as a successful bootloader installation when GRUB2
5d051d
             # got installed on at least one PPC PReP boot partition:
5d051d
diff --git a/usr/share/rear/skel/default/etc/scripts/system-setup.d/41-load-special-modules.sh b/usr/share/rear/skel/default/etc/scripts/system-setup.d/41-load-special-modules.sh
5d051d
index 9b0b3b8a..2e1d1912 100644
5d051d
--- a/usr/share/rear/skel/default/etc/scripts/system-setup.d/41-load-special-modules.sh
5d051d
+++ b/usr/share/rear/skel/default/etc/scripts/system-setup.d/41-load-special-modules.sh
5d051d
@@ -1,6 +1,24 @@
5d051d
-# some things are special
5d051d
+# Special cases of kernel module loading.
5d051d
 
5d051d
-# XEN PV does not autoload some modules
5d051d
-if [ -d /proc/xen ] ; then
5d051d
-	modprobe xenblk
5d051d
+# XEN PV does not autoload some modules:
5d051d
+test -d /proc/xen && modprobe xenblk
5d051d
+
5d051d
+# On POWER architecture the nvram kernel driver may be no longer built into the kernel
5d051d
+# but nowadays it could be also built as a kernel module that needs to be loaded
5d051d
+# cf. https://github.com/rear/rear/issues/2554#issuecomment-764720180
5d051d
+# because normally grub2-install gets called without the '--no-nvram' option
5d051d
+# e.g. see finalize/Linux-ppc64le/620_install_grub2.sh
5d051d
+# which is how grub2-install should be called when the hardware supports nvram.
5d051d
+# Nothing to do when the character device node /dev/nvram exists
5d051d
+# because then the nvram kernel driver is already there:
5d051d
+if ! test -c /dev/nvram ; then
5d051d
+    # Nothing can be done when there is no nvram kernel module.
5d051d
+    # Suppress the possible 'modprobe -n nvram' error message like
5d051d
+    # "modprobe: FATAL: Module nvram not found in directory /lib/modules/..."
5d051d
+    # to avoid a possible "FATAL" false alarm message that would appear
5d051d
+    # on the user's terminal during recovery system startup
5d051d
+    # cf. https://github.com/rear/rear/pull/2537#issuecomment-741825046
5d051d
+    # but when there is a nvram kernel module show possible 'modprobe nvram'
5d051d
+    # (error) messages on the user's terminal during recovery system startup:
5d051d
+    modprobe -n nvram 2>/dev/null && modprobe nvram
5d051d
 fi