From f399c55bb71f4304dcfc88e754c1d07a8947f86b Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Thu, 28 Feb 2019 13:01:40 +0100 Subject: [PATCH 1/5] grubby-bls: make --update-kernel ALL to update kernelopts var in grubenv Currently there's no way to update the kernelopts variable defined in the grubenv by using the grubby wrapper. Updating it with grub2-editenv - set is tedious and error prone so let's use --update-kernel=ALL option for it. This command currently iterates over all the BLS entries and update them individually, but makes more sense to update the kernelopts grubenv var and only update the BLS entries that don't have the $kernelopts var in their options field. If after an update one of these BLS entries have exactly the same params in their options field than the ones set in $kernelopts, set the options field to $kernelopts again since the parameters have converged again. That way the modified BLS entries will only have a custom options field while its value diverged from the $kernelopts defined in grubenv. Signed-off-by: Javier Martinez Canillas --- grubby-bls | 32 ++++++++++++++++++++++++++++++-- grubby.spec | 5 ++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/grubby-bls b/grubby-bls index c1ea4cf..d4a543e 100755 --- a/grubby-bls +++ b/grubby-bls @@ -218,8 +218,20 @@ expand_var() { echo $var } +has_kernelopts() +{ + local args=${bls_options[$1]} + local opts=(${args}) + + for opt in ${opts[*]}; do + [[ $opt = "\$kernelopts" ]] && return 0 + done + + return 1 +} + get_bls_args() { - local args=${bls_options[$i]} + local args=${bls_options[$1]} local opts=(${args}) for opt in ${opts[*]}; do @@ -473,16 +485,32 @@ update_bls_fragment() { local remove_args=$1 && shift local add_args=$1 && shift local initrd=$1 && shift + local opts if [[ $indexes = "-1" ]]; then print_error "The param $(get_prefix)${param} is incorrect" fi + if [[ $param = "ALL" && $bootloader = grub2 ]] && [[ -n $remove_args || -n $add_args ]]; then + local old_args="$(grub2-editenv "${env}" list | grep kernelopts | sed -e "s/kernelopts=//")" + opts="$(update_args "${old_args}" "${remove_args}" "${add_args}")" + grub2-editenv "${env}" set kernelopts="${opts}" + elif [[ $bootloader = grub2 ]]; then + opts="$(grub2-editenv "${env}" list | grep kernelopts | sed -e "s/kernelopts=//")" + fi + for i in ${indexes[*]}; do if [[ -n $remove_args || -n $add_args ]]; then local old_args="$(get_bls_args "$i")" local new_args="$(update_args "${old_args}" "${remove_args}" "${add_args}")" - set_bls_value "${bls_file[$i]}" "options" "${new_args}" + + if [[ $param != "ALL" || ! "$(has_kernelopts "$i")" ]]; then + set_bls_value "${bls_file[$i]}" "options" "${new_args}" + fi + + if [[ $bootloader = grub2 && ! "$(has_kernelopts "$i")" && $opts = $new_args ]]; then + set_bls_value "${bls_file[$i]}" "options" "\$kernelopts" + fi fi if [[ -n $initrd ]]; then diff --git a/grubby.spec b/grubby.spec index 5606b2c..9df01e6 100644 --- a/grubby.spec +++ b/grubby.spec @@ -1,6 +1,6 @@ Name: grubby Version: 8.40 -Release: 27%{?dist} +Release: 28%{?dist} Summary: Command line tool for updating bootloader configs License: GPLv2+ URL: https://github.com/rhinstaller/grubby @@ -132,6 +132,9 @@ current boot environment. %{_mandir}/man8/*.8* %changelog +* Fri Mar 01 2019 Javier Martinez Canillas - 8.40-28 +- grubby-bls: make --update-kernel ALL to update kernelopts var in grubenv + * Thu Feb 14 2019 Javier Martinez Canillas - 8.40-27 - grubby-bls: error if args or remove-args is used without update-kernel From 6fadbea61563fd7f67d90d8a5fec14b26a13bca7 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Mon, 11 Mar 2019 11:05:27 +0100 Subject: [PATCH 2/5] Only switch to BLS config for s390x / zipl For platforms using GRUB, the switch to BLS should be done in the %post scriptlet for the grub2-tools package. So only switch to BLS for s390x. Related: rhbz#1652806 Signed-off-by: Javier Martinez Canillas --- grubby.spec | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/grubby.spec b/grubby.spec index 9df01e6..b4965c8 100644 --- a/grubby.spec +++ b/grubby.spec @@ -1,6 +1,6 @@ Name: grubby Version: 8.40 -Release: 28%{?dist} +Release: 29%{?dist} Summary: Command line tool for updating bootloader configs License: GPLv2+ URL: https://github.com/rhinstaller/grubby @@ -84,13 +84,8 @@ sed -e "s,@@LIBEXECDIR@@,%{_libexecdir}/installkernel,g" %{SOURCE3} \ %post if [ "$1" = 2 ]; then arch=$(uname -m) - if [[ $arch == "s390x" ]]; then - command=zipl-switch-to-blscfg - else - command=grub2-switch-to-blscfg - fi - - $command --backup-suffix=.rpmsave &>/dev/null || : + [[ $arch == "s390x" ]] && \ + zipl-switch-to-blscfg --backup-suffix=.rpmsave &>/dev/null || : fi %package deprecated @@ -132,6 +127,10 @@ current boot environment. %{_mandir}/man8/*.8* %changelog +* Mon Mar 11 2019 Javier Martinez Canillas - 8.40-29 +- Only switch to BLS config for s390x / zipl + Related: rhbz#1652806 + * Fri Mar 01 2019 Javier Martinez Canillas - 8.40-28 - grubby-bls: make --update-kernel ALL to update kernelopts var in grubenv From 37f094c099cb7c145cc843a24b3b5ae0e5189c40 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Wed, 20 Mar 2019 17:15:00 +0100 Subject: [PATCH 3/5] grubby-bls: fix --add-kernel not working when using the --args option The script prints an error if --args option is used without --update-kernel but it's also valid to use it with the --add-kernel option. Resolves: rhbz#1691004 Signed-off-by: Javier Martinez Canillas --- grubby-bls | 2 +- grubby.spec | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/grubby-bls b/grubby-bls index d4a543e..3551896 100755 --- a/grubby-bls +++ b/grubby-bls @@ -734,7 +734,7 @@ while [ ${#} -gt 0 ]; do shift done -if [[ -z $update_kernel ]] && [[ -n $args || -n $remove_args ]]; then +if [[ -z $update_kernel && -z $kernel ]] && [[ -n $args || -n $remove_args ]]; then print_error "no action specified" fi diff --git a/grubby.spec b/grubby.spec index b4965c8..711c7bc 100644 --- a/grubby.spec +++ b/grubby.spec @@ -1,6 +1,6 @@ Name: grubby Version: 8.40 -Release: 29%{?dist} +Release: 30%{?dist} Summary: Command line tool for updating bootloader configs License: GPLv2+ URL: https://github.com/rhinstaller/grubby @@ -127,6 +127,10 @@ current boot environment. %{_mandir}/man8/*.8* %changelog +* Thu Mar 21 2019 Javier Martinez Canillas - 8.40-30 +- grubby-bls: fix --add-kernel not working when using the --args option + Resolves: rhbz#1691004 + * Mon Mar 11 2019 Javier Martinez Canillas - 8.40-29 - Only switch to BLS config for s390x / zipl Related: rhbz#1652806 From fd37fff732efc23b8ffaa32650abc244682e38bf Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Mon, 17 Jun 2019 17:20:17 +0200 Subject: [PATCH 4/5] Add a kernel-install plugin to execute hook scripts in /etc/kernel/ The kernel hook scripts in /etc/kernel/postinst.d and /etc/kernel/prerm.d were executed by the new-kernel-pkg --rpmposttrans and --remove options. But with a BLS configuration the new-kernel-pkg script isn't executed and instead the kernel-install plugins are used. Add a kernel-install plugin that executes the hooks since packages like dkms and akmod make use of it. Resolves: rhbz#1696202 Signed-off-by: Javier Martinez Canillas --- 95-kernel-hooks.install | 33 +++++++++++++++++++++++++++++++++ grubby.spec | 9 ++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100755 95-kernel-hooks.install diff --git a/95-kernel-hooks.install b/95-kernel-hooks.install new file mode 100755 index 0000000..1313556 --- /dev/null +++ b/95-kernel-hooks.install @@ -0,0 +1,33 @@ +#!/usr/bin/bash + +if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then + exit 0 +fi + +COMMAND="$1" +KERNEL_VERSION="$2" +BOOT_DIR_ABS="$3" + +# If $BOOT_DIR_ABS exists, some other boot loader is active. +[[ -d "$BOOT_DIR_ABS" ]] && exit 0 + +run_hooks() +{ + local f + local files="$1" + for f in $files ; do + [ -x "$f" ] || continue + "$f" "$KERNEL_VERSION" "/boot/vmlinuz-$KERNEL_VERSION" + done +} + +case "$COMMAND" in + add) + run_hooks "/etc/kernel/postinst.d/*[^~] /etc/kernel/postinst.d/$KERNEL_VERSION/*[^~]" + ;; + remove) + run_hooks "/etc/kernel/prerm.d/*[^~] /etc/kernel/prerm.d/$KERNEL_VERSION/*[^~]" + ;; + *) + exit 0 +esac diff --git a/grubby.spec b/grubby.spec index 711c7bc..3c770a0 100644 --- a/grubby.spec +++ b/grubby.spec @@ -1,6 +1,6 @@ Name: grubby Version: 8.40 -Release: 30%{?dist} +Release: 31%{?dist} Summary: Command line tool for updating bootloader configs License: GPLv2+ URL: https://github.com/rhinstaller/grubby @@ -13,6 +13,7 @@ Source1: grubby-bls Source2: grubby.in Source3: installkernel.in Source4: installkernel-bls +Source5: 95-kernel-hooks.install Patch0001: 0001-remove-the-old-crufty-u-boot-support.patch Patch0002: 0002-Change-return-type-in-getRootSpecifier.patch Patch0003: 0003-Add-btrfs-subvolume-support-for-grub2.patch @@ -80,6 +81,7 @@ sed -e "s,@@LIBEXECDIR@@,%{_libexecdir}/grubby,g" %{SOURCE2} \ > %{buildroot}%{_sbindir}/grubby sed -e "s,@@LIBEXECDIR@@,%{_libexecdir}/installkernel,g" %{SOURCE3} \ > %{buildroot}%{_sbindir}/installkernel +install -D -m 0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE5} %post if [ "$1" = 2 ]; then @@ -112,6 +114,7 @@ current boot environment. %attr(0755,root,root) %{_sbindir}/grubby %attr(0755,root,root) %{_libexecdir}/installkernel/installkernel-bls %attr(0755,root,root) %{_sbindir}/installkernel +%attr(0755,root,root) %{_prefix}/lib/kernel/install.d/95-kernel-hooks.install %{_mandir}/man8/[gi]*.8* %files deprecated @@ -127,6 +130,10 @@ current boot environment. %{_mandir}/man8/*.8* %changelog +* Fri Jun 21 2019 Javier Martinez Canillas - 8.40-31 +- Add a kernel-install plugin to execute hook scripts in /etc/kernel/ + Resolves: rhbz#1696202 + * Thu Mar 21 2019 Javier Martinez Canillas - 8.40-30 - grubby-bls: fix --add-kernel not working when using the --args option Resolves: rhbz#1691004 From aa4ddbd63fc48d46605b1028fb00baa2f3e5a7bd Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Fri, 13 Sep 2019 17:28:55 +0200 Subject: [PATCH 5/5] Don't execute the zipl-switch-to-blscfg script in %post scriptlet The zipl-switch-to-blscfg script is executed in a %post scriptlet of the grubby package but that's wrong, since if the package is updated before the s390utils-base package it can execute an older version of the script. Related: rhbz#1748348 Signed-off-by: Javier Martinez Canillas --- grubby.spec | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/grubby.spec b/grubby.spec index 3c770a0..b433022 100644 --- a/grubby.spec +++ b/grubby.spec @@ -1,6 +1,6 @@ Name: grubby Version: 8.40 -Release: 31%{?dist} +Release: 32%{?dist} Summary: Command line tool for updating bootloader configs License: GPLv2+ URL: https://github.com/rhinstaller/grubby @@ -83,13 +83,6 @@ sed -e "s,@@LIBEXECDIR@@,%{_libexecdir}/installkernel,g" %{SOURCE3} \ > %{buildroot}%{_sbindir}/installkernel install -D -m 0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE5} -%post -if [ "$1" = 2 ]; then - arch=$(uname -m) - [[ $arch == "s390x" ]] && \ - zipl-switch-to-blscfg --backup-suffix=.rpmsave &>/dev/null || : -fi - %package deprecated Summary: Legacy command line tool for updating bootloader configs Conflicts: %{name} <= 8.40-18 @@ -130,6 +123,10 @@ current boot environment. %{_mandir}/man8/*.8* %changelog +* Fri Sep 13 2019 Javier Martinez Canillas - 8.40-32 +- Don't execute the zipl-switch-to-blscfg script in %%post scriptlet + Related: rhbz#1748348 + * Fri Jun 21 2019 Javier Martinez Canillas - 8.40-31 - Add a kernel-install plugin to execute hook scripts in /etc/kernel/ Resolves: rhbz#1696202