From df62b2deb2cf61d4fe8e4a7ff50187a9de37e8abc4679d6e7e336dc942dd98fd Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Mon, 20 May 2019 06:03:38 +0000 Subject: [PATCH] Accepting request 703735 from home:rwill:branches:Base:System - Check/refresh zipl-kernel before hibernate on s390x. (bsc#940457) (Getting rid of hardcoded 'vmlinuz', which failed on PPC as well.) - Try to refresh zipl-kernel on failed kexec. (bsc#1127293) - Fully support "previous" zipl-kernel, with 'mem=1G' being available on dedicated entries. (bsc#928131) OBS-URL: https://build.opensuse.org/request/show/703735 OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=333 --- grub2-s390x-04-grub2-install.patch | 325 +++++++++++++++---- grub2-s390x-09-improve-zipl-setup.patch | 157 ++++++++- grub2-systemd-sleep.sh | 41 ++- grub2-zipl-setup-fix-btrfs-multipledev.patch | 14 +- grub2.changes | 18 + grub2.spec | 3 + 6 files changed, 464 insertions(+), 94 deletions(-) diff --git a/grub2-s390x-04-grub2-install.patch b/grub2-s390x-04-grub2-install.patch index 857fe90..2c75a20 100644 --- a/grub2-s390x-04-grub2-install.patch +++ b/grub2-s390x-04-grub2-install.patch @@ -47,27 +47,30 @@ V16: * dracut-grub2.sh: force read-only '/usr' for kexec. [bsc#932951] V17: * grub2-zipl-setup: remove arybase dependency by not referencing $[. [bsc#1055280] +V18: + * dracut-zipl-refresh.sh.in: initial submission. [bsc#1127293] + * dracut-grub2.sh: try to call zipl-refresh on failed kexec and drop + to an emergency shell otherwise --- - Makefile.util.def | 39 +++ - configure.ac | 9 - grub-core/Makefile.core.def | 7 - grub-core/osdep/basic/no_platform.c | 7 - grub-core/osdep/unix/platform.c | 11 - grub-core/osdep/windows/platform.c | 6 - include/grub/util/install.h | 4 - util/grub-install-common.c | 1 - util/grub-install.c | 43 +++ - util/s390x/dracut-grub2.sh.in | 110 +++++++++ - util/s390x/dracut-module-setup.sh.in | 19 + - util/s390x/zipl2grub.conf.in | 26 ++ - util/s390x/zipl2grub.pl.in | 424 +++++++++++++++++++++++++++++++++++ - 13 files changed, 702 insertions(+), 4 deletions(-) + Makefile.util.def | 46 +++ + configure.ac | 9 + grub-core/Makefile.core.def | 7 + grub-core/osdep/basic/no_platform.c | 7 + grub-core/osdep/unix/platform.c | 11 + grub-core/osdep/windows/platform.c | 6 + include/grub/util/install.h | 4 + util/grub-install-common.c | 1 + util/grub-install.c | 43 +++ + util/s390x/dracut-grub2.sh.in | 126 +++++++++ + util/s390x/dracut-module-setup.sh.in | 19 + + util/s390x/dracut-zipl-refresh.sh.in | 183 ++++++++++++++ + util/s390x/zipl2grub.conf.in | 26 ++ + util/s390x/zipl2grub.pl.in | 423 +++++++++++++++++++++++++++++++++ + 14 files changed, 908 insertions(+), 3 deletions(-) -Index: grub-2.02/Makefile.util.def -=================================================================== ---- grub-2.02.orig/Makefile.util.def -+++ grub-2.02/Makefile.util.def +--- a/Makefile.util.def ++++ b/Makefile.util.def @@ -352,6 +352,7 @@ program = { ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; @@ -108,7 +111,7 @@ Index: grub-2.02/Makefile.util.def common = grub-core/kern/emu/argp_common.c; common = grub-core/osdep/init.c; -@@ -697,6 +702,38 @@ script = { +@@ -697,6 +702,46 @@ script = { }; script = { @@ -143,11 +146,19 @@ Index: grub-2.02/Makefile.util.def + installdir = platform; +}; + ++script = { ++ name = dracut-zipl-refresh; ++ common = util/s390x/dracut-zipl-refresh.sh.in; ++ enable = emu; ++ emu_condition = COND_s390x; ++ installdir = platform; ++}; ++ +script = { name = grub-mkconfig_lib; common = util/grub-mkconfig_lib.in; installdir = noinst; -@@ -1308,6 +1345,7 @@ program = { +@@ -1308,6 +1353,7 @@ program = { ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; @@ -155,10 +166,8 @@ Index: grub-2.02/Makefile.util.def }; program = { -Index: grub-2.02/configure.ac -=================================================================== ---- grub-2.02.orig/configure.ac -+++ grub-2.02/configure.ac +--- a/configure.ac ++++ b/configure.ac @@ -181,9 +181,9 @@ if test x$platform != xemu ; then esac fi @@ -182,10 +191,8 @@ Index: grub-2.02/configure.ac AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd]) AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux]) -Index: grub-2.02/grub-core/Makefile.core.def -=================================================================== ---- grub-2.02.orig/grub-core/Makefile.core.def -+++ grub-2.02/grub-core/Makefile.core.def +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def @@ -1057,6 +1057,7 @@ module = { module = { name = videotest; @@ -240,10 +247,8 @@ Index: grub-2.02/grub-core/Makefile.core.def }; module = { -Index: grub-2.02/grub-core/osdep/basic/no_platform.c -=================================================================== ---- grub-2.02.orig/grub-core/osdep/basic/no_platform.c -+++ grub-2.02/grub-core/osdep/basic/no_platform.c +--- a/grub-core/osdep/basic/no_platform.c ++++ b/grub-core/osdep/basic/no_platform.c @@ -44,3 +44,10 @@ grub_install_sgi_setup (const char *inst { grub_util_error ("%s", _("no SGI routines are available for your platform")); @@ -255,10 +260,8 @@ Index: grub-2.02/grub-core/osdep/basic/no_platform.c + grub_util_error ("%s", _("no zIPL routines are available for your platform")); +} + -Index: grub-2.02/grub-core/osdep/unix/platform.c -=================================================================== ---- grub-2.02.orig/grub-core/osdep/unix/platform.c -+++ grub-2.02/grub-core/osdep/unix/platform.c +--- a/grub-core/osdep/unix/platform.c ++++ b/grub-core/osdep/unix/platform.c @@ -233,3 +233,14 @@ grub_install_sgi_setup (const char *inst imgfile, destname, NULL }); grub_util_warn ("%s", _("You will have to set `SystemPartition' and `OSLoader' manually.")); @@ -274,10 +277,8 @@ Index: grub-2.02/grub-core/osdep/unix/platform.c + "-z", dest, NULL })) + grub_util_error (_("`%s' failed.\n"), PACKAGE"-zipl-setup"); +} -Index: grub-2.02/grub-core/osdep/windows/platform.c -=================================================================== ---- grub-2.02.orig/grub-core/osdep/windows/platform.c -+++ grub-2.02/grub-core/osdep/windows/platform.c +--- a/grub-core/osdep/windows/platform.c ++++ b/grub-core/osdep/windows/platform.c @@ -422,3 +422,9 @@ grub_install_sgi_setup (const char *inst { grub_util_error ("%s", _("no SGI routines are available for your platform")); @@ -288,10 +289,8 @@ Index: grub-2.02/grub-core/osdep/windows/platform.c +{ + grub_util_error ("%s", _("no zIPL routines are available for your platform")); +} -Index: grub-2.02/include/grub/util/install.h -=================================================================== ---- grub-2.02.orig/include/grub/util/install.h -+++ grub-2.02/include/grub/util/install.h +--- a/include/grub/util/install.h ++++ b/include/grub/util/install.h @@ -99,6 +99,7 @@ enum grub_install_plat GRUB_INSTALL_PLATFORM_I386_XEN, GRUB_INSTALL_PLATFORM_X86_64_XEN, @@ -310,10 +309,8 @@ Index: grub-2.02/include/grub/util/install.h int grub_install_compress_gzip (const char *src, const char *dest); int -Index: grub-2.02/util/grub-install-common.c -=================================================================== ---- grub-2.02.orig/util/grub-install-common.c -+++ grub-2.02/util/grub-install-common.c +--- a/util/grub-install-common.c ++++ b/util/grub-install-common.c @@ -666,6 +666,7 @@ static struct [GRUB_INSTALL_PLATFORM_ARM_EFI] = { "arm", "efi" }, [GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64", "efi" }, @@ -322,10 +319,8 @@ Index: grub-2.02/util/grub-install-common.c }; char * -Index: grub-2.02/util/grub-install.c -=================================================================== ---- grub-2.02.orig/util/grub-install.c -+++ grub-2.02/util/grub-install.c +--- a/util/grub-install.c ++++ b/util/grub-install.c @@ -66,6 +66,7 @@ static int force_file_id = 0; static char *disk_module = NULL; static char *efidir = NULL; @@ -467,11 +462,9 @@ Index: grub-2.02/util/grub-install.c case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON: case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS: case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS: -Index: grub-2.02/util/s390x/dracut-grub2.sh.in -=================================================================== --- /dev/null -+++ grub-2.02/util/s390x/dracut-grub2.sh.in -@@ -0,0 +1,110 @@ ++++ b/util/s390x/dracut-grub2.sh.in +@@ -0,0 +1,126 @@ +#!/bin/sh +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh @@ -566,8 +559,23 @@ Index: grub-2.02/util/s390x/dracut-grub2.sh.in + + debug "Trying grub2-emu (ro=$grub2rofs, TERM=$TERM, ctty=$_ctty)..." + setsid $CTTY -- chroot /sysroot $bindir/grub2-emu -X -X 0<>$_ctty 1>&0 2>&0 -+ if [ -e /grub2force ] && [ $(cat /sys/kernel/kexec_loaded) = 1 ]; then -+ systemctl kexec ++ ++ if [ -x /sysroot/usr/share/grub2/zipl-refresh ]; then ++ setsid $CTTY -- /sysroot/usr/share/grub2/zipl-refresh 0<>$_ctty 1>&0 2>&0 ++ if [ $? != 0 ]; then ++ warn "Not continuing" ++ emergency_shell -n grub2-emu-zipl-refresh ++ else ++ echo "+ reboot" >& $_ctty ++ sleep 3 ++ reboot ++ fi ++ else ++ echo " ++ Attention: 'grub2' failed to start the target kernel and 'zipl-refresh' ++ is not available. This should never happen. Please contact support." >& $_ctty ++ warn "Not continuing" ++ emergency_shell -n grub2-emu-kexec + fi + + $grub2snap || umount /sysroot/.snapshots @@ -578,14 +586,13 @@ Index: grub-2.02/util/s390x/dracut-grub2.sh.in + $grub2roufs || mount -o remount,rw /sysroot/usr + $grub2rofs || mount -o remount,rw /sysroot + else -+ info "No $bindir/grub2-emu in /sysroot--trying to proceed without kexec..." ++ warn "No $bindir/grub2-emu in /sysroot--dropping to emergency shell..." ++ emergency_shell -n no-grub2-emu + fi +fi + -Index: grub-2.02/util/s390x/dracut-module-setup.sh.in -=================================================================== --- /dev/null -+++ grub-2.02/util/s390x/dracut-module-setup.sh.in ++++ b/util/s390x/dracut-module-setup.sh.in @@ -0,0 +1,19 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- @@ -606,10 +613,8 @@ Index: grub-2.02/util/s390x/dracut-module-setup.sh.in + #inst_multiple grub2-emu kexec +} + -Index: grub-2.02/util/s390x/zipl2grub.conf.in -=================================================================== --- /dev/null -+++ grub-2.02/util/s390x/zipl2grub.conf.in ++++ b/util/s390x/zipl2grub.conf.in @@ -0,0 +1,26 @@ +## This is the template for '@zipldir@/config' and is subject to +## rpm's %config file handling in case of grub2-s390x-emu package update. @@ -637,10 +642,8 @@ Index: grub-2.02/util/s390x/zipl2grub.conf.in + 1 = grub2 + 2 = skip-grub2 + -Index: grub-2.02/util/s390x/zipl2grub.pl.in -=================================================================== --- /dev/null -+++ grub-2.02/util/s390x/zipl2grub.pl.in ++++ b/util/s390x/zipl2grub.pl.in @@ -0,0 +1,423 @@ +#!/usr/bin/perl +use strict; @@ -1065,3 +1068,189 @@ Index: grub-2.02/util/s390x/zipl2grub.pl.in +System( @C); +exit( $miss); + +--- /dev/null ++++ b/util/s390x/dracut-zipl-refresh.sh.in +@@ -0,0 +1,183 @@ ++#!/bin/bash ++# ex: ts=8 sw=4 sts=4 et filetype=sh syntax=off ++ ++debug=false ++TIMEOUT=60 ++[ -n "$SYSROOT" ] || ++SYSROOT=/sysroot ++[ -d $SYSROOT/boot ] || SYSROOT= ++ ++sync() { $SYSROOT/usr/bin/sync "$@"; } ++readlink() { $SYSROOT/usr/bin/readlink "$@"; } ++newline() { echo ""; } ++verbose() { ++ local a ++ local m ++ [ -n "$*" ] || return 0 ++ m="+" ++ for a in "$@"; do ++ case "$a" in ++ (*" "*|*" "*|"") m="$m '$a'";; ++ (*) m="$m $a";; ++ esac ++ done ++ echo "$m" ++ [ -n "$SYSROOT" -o "$1" = "chroot" ] || return 0 ++ "$@" ++} ++ ++SYSK="$(readlink $SYSROOT/boot/image)" ++SYSK="${SYSK#image-}" ++ZIPK="$(readlink $SYSROOT/boot/zipl/image)" ++ZIPK="${ZIPK#image-}" ++PRVK="$(readlink $SYSROOT/boot/zipl/image.prev 2> /dev/null)" ++PRVK="${PRVK#image-}" ++RUNK="$(uname -r)" ++# if /boot/zipl is not accessible ZIPK will be empty, assume running kernel ++[ -n "$ZIPK" ] || ZIPK="$RUNK" ++ ++[ -n "$SYSROOT" ] || { ++ echo "$0 is not intended for interactive use!" ++ $debug || ++ exit 0 ++ ## test: ++ TIMEOUT=6 ++ RUNK=110; ZIPK=110; PRVK=101; SYSK=194 ++ ##RUNK=$PRVK; ZIPK=$SYSK # previous booted, newest is default ++ ##t=$ZIPK; ZIPK=$PRVK; PRVK=$t; SYSK=$PRVK # unknown booted ++ ##ZIPK=$SYSK; PRVK="" # no update ++ ##ZIPK=$SYSK # try previous ++ echo "R=$RUNK S=$SYSK Z=$ZIPK P=$PRVK" ++ #verbose echo "a b" z ++ #verbose echo "^h ^j" ^z ++} ++ ++trap newline EXIT ++ ++echo -n " ++ Attention: 'grub2' failed to start the target kernel" ++ ++if [ "$ZIPK" != "$RUNK" -a "$RUNK" != "$SYSK" ]; then ++ # i.e. "previous" has been selected via zipl, but it fails!? ++ [ "$RUNK" = "$PRVK" ] && ++ echo " from previous" || ++ echo " from unknown" ++ ++ echo " ZIPL kernel ($RUNK). If default ($ZIPK) ++ fails as well, please contact support." ++ exit 1 ++fi ++echo "." ++if [ "$ZIPK" = "$SYSK" ]; then ++ [ -z "$PRVK" ] && ++ echo " ++ No kernel update readily available/installed. Please contact support." || ++ echo " ++ You may want to try the previous kernel ($PRVK) with ++ 'IPL ... LOADPARM 4', as no update kernel is readily available/installed." ++ exit 1 ++fi ++ ++echo " ++ A newer kernel ($SYSK) is available and will be deployed ++ in $TIMEOUT seconds. To facilitate this, the affected file-systems have ++ to be made writable, then 'grub2-install --force' needs to be run, ++ and, on success, a 'reboot' will be initiated. ++ ++ Press 'c[Enter]' to interrupt... " ++ ++trap interrupted=1 INT ++interrupted=0 ++input="" ++read -t $TIMEOUT input ++case "$input" in ++ ([Cc]) interrupted=2 ;; ++esac ++if [ $interrupted != 0 ]; then ++ echo " ++ Automatic update cancelled..." ++ exit 1 ++fi ++trap - INT ++echo " ++ Attempting automatic update..." ++ ++ismounted() { ++ local mode="$1" ++ local tgt="$2" ++ local dev mp fs opts dc ++ while read dev mp fs opts dc; do ++ [ "$mp" = "$tgt" ] || continue ++ case ",$opts," in ++ (*,$mode,*) return 0;; ++ esac ++ done < /proc/mounts ++ return 1 ++} ++ismp() { ++ local sysr="$1" ++ local tgt="$2" ++ local dev mp fs opts dc ++ while read dev mp fs opts dc; do ++ case "$dev" in ++ ("#"*) continue;; ++ esac ++ [ "$mp" = "$tgt" ] || continue ++ return 0 ++ done < $sysr/etc/fstab ++ return 1 ++} ++chroot() { ++ local tgt="$1"; shift ++ if [ -z "$tgt" ]; then ++ echo -n "+" ++ verbose "$@" ++ else ++ /usr/bin/chroot "$tgt" "$@" ++ fi ++} ++cleanup() { ++ local mp ++ echo " # cleanup" ++ for mp in $UMOUNT; do ++ verbose chroot "$SYSROOT" umount $mp ++ done ++ for mp in $WMOUNT; do ++ verbose mount -o remount,ro $mp ++ done ++ sync; sync ++ [ -z "$EXIT" ] || echo "$EXIT" ++ echo "" ++} ++trap cleanup EXIT ++UMOUNT="" ++WMOUNT="" ++EXIT="" ++ ++echo " # prepare" ++# remount $SYSROOT{,/boot{,/zipl}} read-write ++for mp in {"",/boot{,/zipl}}; do ++ [ -n "$SYSROOT$mp" ] || continue ++ if ismounted rw $SYSROOT$mp; then ++ echo " # $mp: already read-write: ignore" ++ elif ismounted ro $SYSROOT$mp; then ++ verbose mount -o remount,rw $SYSROOT$mp ++ WMOUNT="$SYSROOT$mp $WMOUNT" ++ elif ismp "$SYSROOT" $mp; then ++ verbose chroot "$SYSROOT" mount -w $mp || exit 1 ++ UMOUNT="$mp $UMOUNT" ++ fi ++done ++if [ ! -w $SYSROOT/boot/zipl/config ]; then ++ EXIT="ERROR: $SYSROOT/boot/zipl/config not writable! Aborting..." ++ exit 1 ++fi ++echo " # action" ++verbose chroot "$SYSROOT" grub2-zipl-setup --force ++ret=$? ++if [ $ret != 0 ]; then ++ EXIT=" # failed ($ret)" ++else ++ EXIT=" # done" ++fi ++exit $ret diff --git a/grub2-s390x-09-improve-zipl-setup.patch b/grub2-s390x-09-improve-zipl-setup.patch index a312a4f..c664831 100644 --- a/grub2-s390x-09-improve-zipl-setup.patch +++ b/grub2-s390x-09-improve-zipl-setup.patch @@ -1,22 +1,68 @@ --- - util/s390x/zipl2grub.conf.in | 2 +- - util/s390x/zipl2grub.pl.in | 19 +++++++++++-------- - 2 files changed, 12 insertions(+), 9 deletions(-) + util/s390x/zipl2grub.conf.in | 30 +++++++++++++++++++- + util/s390x/zipl2grub.pl.in | 64 +++++++++++++++++++++++++++++-------------- + 2 files changed, 73 insertions(+), 21 deletions(-) --- a/util/s390x/zipl2grub.conf.in +++ b/util/s390x/zipl2grub.conf.in -@@ -8,7 +8,7 @@ defaultmenu = menu +@@ -10,17 +10,45 @@ defaultmenu = menu + image = @zipldir@/image + parameters = "root=@GRUB_DEVICE@ @GRUB_EMU_CONMODE@ @GRUB_CMDLINE_LINUX@ @GRUB_CMDLINE_LINUX_DEFAULT@ initgrub quiet splash=silent plymouth.enable=0 " + ++[grub2-mem1G] ++ target = @zipldir@ ++ image = @zipldir@/image ++ ramdisk = @zipldir@/initrd,0x2000000 ++ parameters = "root=@GRUB_DEVICE@ @GRUB_EMU_CONMODE@ @GRUB_CMDLINE_LINUX@ @GRUB_CMDLINE_LINUX_DEFAULT@ initgrub quiet splash=silent plymouth.enable=0 mem=1G " ++ + [skip-grub2] target = @zipldir@ ramdisk = @zipldir@/initrd,0x2000000 image = @zipldir@/image -- parameters = "root=@GRUB_DEVICE@ @GRUB_EMU_CONMODE@ @GRUB_CMDLINE_LINUX@ @GRUB_CMDLINE_LINUX_DEFAULT@ initgrub quiet splash=silent plymouth.enable=0 " -+ parameters = "root=@GRUB_DEVICE@ @GRUB_EMU_CONMODE@ @GRUB_CMDLINE_LINUX@ @GRUB_CMDLINE_LINUX_DEFAULT@ initgrub quiet splash=silent plymouth.enable=0 mem=1G " + parameters = "root=@GRUB_DEVICE@ @GRUB_CONMODE@ @GRUB_CMDLINE_LINUX@ @GRUB_CMDLINE_LINUX_DEFAULT@ " ++#@ ++#@[grub2-previous] ++#@ target = @zipldir@ ++#@ image = @zipldir@/image.prev ++#@ ramdisk = @zipldir@/initrd.prev,0x2000000 ++#@ parameters = "root=@GRUB_DEVICE@ @GRUB_EMU_CONMODE@ @GRUB_CMDLINE_LINUX@ @GRUB_CMDLINE_LINUX_DEFAULT@ initgrub quiet splash=silent plymouth.enable=0 " ++#@ ++#@[grub2-mem1G-previous] ++#@ target = @zipldir@ ++#@ image = @zipldir@/image.prev ++#@ ramdisk = @zipldir@/initrd.prev,0x2000000 ++#@ parameters = "root=@GRUB_DEVICE@ @GRUB_EMU_CONMODE@ @GRUB_CMDLINE_LINUX@ @GRUB_CMDLINE_LINUX_DEFAULT@ initgrub quiet splash=silent plymouth.enable=0 mem=1G " ++#@ ++#@[skip-grub2-previous] ++#@ target = @zipldir@ ++#@ image = @zipldir@/image.prev ++#@ ramdisk = @zipldir@/initrd.prev,0x2000000 ++#@ parameters = "root=@GRUB_DEVICE@ @GRUB_CONMODE@ @GRUB_CMDLINE_LINUX@ @GRUB_CMDLINE_LINUX_DEFAULT@ " - [skip-grub2] + :menu target = @zipldir@ +- timeout = 16 ++ timeout = 60 + default = 1 + prompt = 0 + 1 = grub2 + 2 = skip-grub2 ++ 3 = grub2-mem1G ++#@ 4 = grub2-previous ++#@ 5 = skip-grub2-previous ++#@ 6 = grub2-mem1G-previous + --- a/util/s390x/zipl2grub.pl.in +++ b/util/s390x/zipl2grub.pl.in -@@ -44,12 +44,12 @@ sub System(@) { +@@ -10,6 +10,7 @@ my $sysconfbl = '@sysconfdir@/sysconfig/ + my $defimage = "/boot/image"; + my $definitrd = "/boot/initrd"; + my $Image = "$defimage"; ++my $previous = ".prev"; + my $zipldir = ""; + my $running = ""; + my $refresh = 1; # needs to default to "on" until most bugs are shaken out! +@@ -44,12 +45,12 @@ sub System(@) { return 0 if ($debug); system( @C); if ($? == -1) { @@ -32,7 +78,46 @@ } return( 0); } -@@ -166,7 +166,9 @@ sub Usage($) { +@@ -74,11 +75,13 @@ sub ln($$) { + unlink( $_[1]) || Panic( 1, "$C: unlink: $!.\n") if ( -e $_[1]); + symlink($_[0], $_[1]) || Panic( 1, "$C: symlink: $!.\n"); + } +-sub BootCopy($$$) { ++ ++sub ManagePrev($$$){ + my( $file, $dir, $tgt) = @_; + my $curr = "$dir/$tgt"; +- my $prev = "$dir/$tgt.prev"; +- Info(4, "Copy /boot/$file $dir $tgt\n"); ++ my $prev = "$dir/$tgt$previous"; ++ my $ret = 0; ++ Info(2, "Manage $prev\n"); + if ( -l $curr ) { + my $curf = readlink( $curr); + if ( $curf ne $file ) { +@@ -88,7 +91,21 @@ sub BootCopy($$$) { + rm( $pref); + } + mv( $curr, $prev); ++ $ret = 1; ++ } else { ++ Info(2, " nothing to do ($curr -> $file).\n"); + } ++ } else { ++ Info(2, " nothing to do ($curr no sym-link).\n"); ++ } ++ return $ret; ++} ++sub BootCopy($$$) { ++ my( $file, $dir, $tgt) = @_; ++ my $curr = "$dir/$tgt"; ++ Info(4, "Copy /boot/$file $dir $tgt\n"); ++ if ( $tgt eq "image" && ManagePrev( $file, $dir, $tgt)) { ++ ManagePrev( $file, $dir, "initrd") + } + cp( "/boot/$file", "$dir/$file"); + ln( $file, $curr); +@@ -163,7 +180,9 @@ sub Usage($) { "zIPL directory missing.", "Configuration template missing.", "Configuration template unreadable.", @@ -43,7 +128,7 @@ "" ); my $msg = ""; -@@ -190,7 +192,8 @@ while ( $#ARGV >= 0 ) { +@@ -186,7 +205,8 @@ while ( $#ARGV >= 0 ) { (/^--?help/ || /^-h/) && (Usage(0)); (/^--zipldir$/ || /^-z$/) && ($zipldir = shift || Usage(2), next); (/^--template$/ || /^-T$/) && ($in = shift || Usage(3), next); @@ -53,7 +138,39 @@ (/^-/) && (Usage(1)); Usage(1); } -@@ -403,15 +406,15 @@ if ( -l $Image ) { +@@ -345,7 +365,7 @@ if ( $debug && $verbose > 2 ) { + open( IN, "< $in") || + Panic( 1, "$C: Failed to open 'zipl.conf' template: $!.\n"); + while ( ) { +- Info( 3, "$.. <$_$.. >"); ++ Info( 4, "$.. <$_$.. >"); + if ( $. == 1 && m{^## This} ) { + $_ = "## This file was written by 'grub2-install/$C'\n" . + "## filling '$in' as template\n"; +@@ -366,7 +386,7 @@ while ( ) { + } + s{\@$k\@}{$v}g; + } +- Info( 2, $_); ++ Info( 3, $_); + $cfg .= $_; + } + if ( $miss ) { +@@ -374,13 +394,6 @@ if ( $miss ) { + Panic( 1, "$C: 'zipl.conf' template could not be filled. \n"); + } + +-my $ziplconf = "$zipldir/config"; +-if ( ! $debug ) { +- open( OUT, "> $ziplconf") || die; +- print( OUT $cfg) || die; +- close( OUT); +-} +- + # copy out kernel and initrd + my $ziplimage = "$zipldir/image"; + my $ziplinitrd = "$zipldir/initrd"; +@@ -399,15 +412,15 @@ if ( -l $Image ) { $Image = readlink( $Image); } my ($image, $version) = ($Image =~ m{^(?:/boot/)?([^-]+-(.+))$}); @@ -72,3 +189,21 @@ } if ( $refresh || ChkInitrd( $zipldir, "initrd") <= 0 ) { MkInitrd( $initrd, $zipldir, $version); +@@ -417,6 +430,17 @@ if ( ChkInitrd( $zipldir, "initrd") == 0 + $miss++; + } + ++# write zipl config file ++my $ziplconf = "$zipldir/config"; ++$cfg =~ s{#@}{}g if ( -r "$ziplimage$previous" && -r "$ziplinitrd$previous" ); ++if ( ! $debug ) { ++ open( OUT, "> $ziplconf") || die; ++ print( OUT $cfg) || die; ++ close( OUT); ++} else { ++ print( STDERR $cfg); ++} ++ + # now: go for it! + my @C = ( "/sbin/zipl", (($verbose) ? "-Vnc" : "-nc"), "$ziplconf" ); + System( @C); diff --git a/grub2-systemd-sleep.sh b/grub2-systemd-sleep.sh index 354991f..4cb7bbb 100644 --- a/grub2-systemd-sleep.sh +++ b/grub2-systemd-sleep.sh @@ -8,7 +8,14 @@ GRUB_ONCE="/usr/sbin/grub2-once" GRUB_ENV="/boot/grub2/grubenv" GRUB_EDITENV="/usr/bin/grub2-editenv" GRUB_CONF="/boot/grub2/grub.cfg" +GRUB_SETUP= BLKID="/usr/sbin/blkid" +ARCH=`uname -m` +VMLINUZ="vmlinuz" +case $ARCH in + ppc*) VMLINUZ="vmlinux" ;; + s390*) VMLINUZ="image"; GRUB_SETUP="/usr/sbin/grub2-zipl-setup" ;; +esac error_quit() { @@ -117,7 +124,6 @@ grub-once-restore() find-kernel-entry() { NEXT_BOOT="" - ARCH=`uname -m` declare -i I=0 # DEBUG "running kernel: $RUNNING" DIAG while [ -n "${KERNELS[$I]}" ]; do @@ -126,10 +132,7 @@ find-kernel-entry() # DEBUG "Found kernel symlink $BOOTING => $IMAGE" INFO BOOTING=$IMAGE fi - case $ARCH in - ppc*) BOOTING="${BOOTING#*vmlinux-}" ;; - *) BOOTING="${BOOTING#*vmlinuz-}" ;; - esac + BOOTING="${BOOTING#*${VMLINUZ}-}" if [ "$RUNNING" == "$BOOTING" -a -n "${MENU_ENTRIES[$I]}" ]; then NEXT_BOOT="${MENU_ENTRIES[$I]}" echo " running kernel is grub menu entry $NEXT_BOOT (${KERNELS[$I]})" @@ -149,7 +152,7 @@ find-kernel-entry() # if we did not find a kernel (or BOOT_LOADER is not GRUB) check, # if the running kernel is still the one that will (probably) be booted for # resume (default entry in menu.lst or, if there is none, the kernel file -# /boot/vmlinuz points to.) +# /boot/${VMLINUZ} points to.) # This will only work, if you use "original" SUSE kernels. # you can always override with the config variable set to "yes" prepare-grub() @@ -164,13 +167,14 @@ prepare-grub() # which kernel is booted with the default entry? BOOTING="${KERNELS[$DEFAULT_BOOT]}" # if there is no default entry (no menu.lst?) we fall back to - # the default of /boot/vmlinuz. - [ -z "$BOOTING" ] && BOOTING="vmlinuz" + # the default of /boot/${VMLINUZ}. + [ -z "$BOOTING" ] && BOOTING="${VMLINUZ}" if IMAGE=`readlink /boot/$BOOTING` && [ -e "/boot/${IMAGE##*/}" ]; then BOOTING=$IMAGE fi - BOOTING="${BOOTING#*vmlinuz-}" + BOOTING="${BOOTING#*${VMLINUZ}-}" echo "running kernel: '$RUNNING', probably booting kernel: '$BOOTING'" + check-setup "$RUNNING" if [ "$BOOTING" != "$RUNNING" ]; then error_quit "ERROR: kernel version mismatch, cannot suspend to disk" fi @@ -180,6 +184,7 @@ prepare-grub() T1=`date +"%s%N"` sync; sync; sync # this is needed to speed up grub-once on reiserfs T2=`date +"%s%N"` + check-setup "$RUNNING" echo " running $GRUB_ONCE \"${NEXT_BOOT}\"" ${GRUB_ONCE} "$NEXT_BOOT" T3=`date +"%s%N"` @@ -191,6 +196,24 @@ prepare-grub() echo "INFO: Done." } +############################################################################# +check-setup() +{ + local WANT="$VMLINUZ-$1" + + [ -n "$GRUB_SETUP" ] || return + # implementation below is s390x-only (for now) + echo "INFO: check-setup \"$WANT\" .." + HAVE="/boot/zipl/$VMLINUZ" + [ -r "$HAVE" ] || + error_quit "ERROR: no zipl kernel, cannot suspend to disk" + HAVE=$(readlink $HAVE) || + error_quit "ERROR: zipl kernel no sym-link, cannot suspend to disk" + [ "$HAVE" != "$WANT" ] || + { echo " zipl kernel already in sync, nothing to do"; return; } + echo " running $GRUB_SETUP # (incl. dracut!)" # no --image as running is preferred! + ${GRUB_SETUP} > /dev/null 2>&1 +} ###### main() diff --git a/grub2-zipl-setup-fix-btrfs-multipledev.patch b/grub2-zipl-setup-fix-btrfs-multipledev.patch index 8fd7b5c..d185727 100644 --- a/grub2-zipl-setup-fix-btrfs-multipledev.patch +++ b/grub2-zipl-setup-fix-btrfs-multipledev.patch @@ -1,8 +1,10 @@ -Index: grub-2.02~beta2/util/s390x/zipl2grub.pl.in -=================================================================== ---- grub-2.02~beta2.orig/util/s390x/zipl2grub.pl.in -+++ grub-2.02~beta2/util/s390x/zipl2grub.pl.in -@@ -361,6 +361,10 @@ while ( ) { +--- + util/s390x/zipl2grub.pl.in | 4 ++++ + 1 file changed, 4 insertions(+) + +--- a/util/s390x/zipl2grub.pl.in ++++ b/util/s390x/zipl2grub.pl.in +@@ -384,6 +384,10 @@ while ( ) { } else { $v = ""; } @@ -12,4 +14,4 @@ Index: grub-2.02~beta2/util/s390x/zipl2grub.pl.in + } s{\@$k\@}{$v}g; } - Info( 2, $_); + Info( 3, $_); diff --git a/grub2.changes b/grub2.changes index 2631671..b31531b 100644 --- a/grub2.changes +++ b/grub2.changes @@ -1,3 +1,21 @@ +------------------------------------------------------------------- +Fri May 17 13:57:29 UTC 2019 - rw@suse.com + +- Check/refresh zipl-kernel before hibernate on s390x. (bsc#940457) + (Getting rid of hardcoded 'vmlinuz', which failed on PPC as well.) + * grub2-systemd-sleep.sh + +------------------------------------------------------------------- +Fri May 17 12:22:55 UTC 2019 - rw@suse.com + +- Try to refresh zipl-kernel on failed kexec. (bsc#1127293) + * grub2-s390x-04-grub2-install.patch +- Fully support "previous" zipl-kernel, + with 'mem=1G' being available on dedicated entries. (bsc#928131) + * grub2-s390x-09-improve-zipl-setup.patch +- Refresh + * grub2-zipl-setup-fix-btrfs-multipledev.patch + ------------------------------------------------------------------- Fri May 3 02:42:27 UTC 2019 - mchang diff --git a/grub2.spec b/grub2.spec index 38a02c0..d971e57 100644 --- a/grub2.spec +++ b/grub2.spec @@ -941,6 +941,8 @@ install -m 755 -d $R%{dracutgrubmoddir} for f in module-setup.sh grub2.sh; do mv $R%{_datadir}/%{name}/%{grubarch}/dracut-$f $R%{dracutgrubmoddir}/$f done +mv $R%{_datadir}/%{name}/%{grubarch}/dracut-zipl-refresh \ + $R%{_datadir}/%{name}/zipl-refresh rm -f $R%{_sysconfdir}/grub.d/30_os-prober perl -ni -e ' @@ -1149,6 +1151,7 @@ fi %config(noreplace) %{_sysconfdir}/default/zipl2grub.conf.in %{dracutlibdir} %{_sbindir}/%{name}-zipl-setup +%{_datadir}/%{name}/zipl-refresh %endif %{_sbindir}/%{name}-install %{_sbindir}/%{name}-mkconfig