Blame SOURCES/rear-bz2096916.patch

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