Compare commits

..

1 commit

Author SHA1 Message Date
Marta Lewandowska
7beb5ebb57 Don't overwrite vars that start with GRUB_CMDLINE_LINUX
When updating args for ALL kernels, grubby clobbers all variables
in /etc/default/grub that start with GRUB_CMDLINE_LINUX and renders
that line multiple times, for each variable that exists. This breaks
using recovery mode. Fix so this doesn't happen anymore.

Signed-off-by: Marta Lewandowska <mlewando@redhat.com>
2024-01-11 09:54:16 +01:00
5 changed files with 134 additions and 111 deletions

View file

@ -2,7 +2,7 @@
# set -x
if [[ "$(uname -m)" == arm* || "$(uname -m)" == aarch64 || "$(uname -m)" == riscv64 ]]
if [[ "$(uname -m)" == arm* || "$(uname -m)" == aarch64 ]]
then
COMMAND="$1"
KERNEL_VERSION="$2"

View file

@ -356,26 +356,22 @@ get_custom_bls_filename() {
prefix="${bls_target%%${arch}}"
prefix="${prefix%.*}"
first_gap=$(
first=0
for bls_entry in $(ls "${prefix}".*~custom*.conf 2>/dev/null | sort -V); do
if [[ -e ${bls_entry} ]]; then
bls_entry="${bls_entry##"${prefix}".}"
bls_entry="${bls_entry%%~custom*}"
if [[ "${bls_entry}" = "${first}" ]]; then
first=$((first+1))
else
break
fi
fi
done
echo "${first}") || :
last=($(for bls in ${prefix}.*~custom*.conf ; do
if ! [[ -e "${bls}" ]] ; then
continue
fi
bls="${bls##${prefix}.}"
bls="${bls%%~custom*}"
echo "${bls}"
done | tail -n1)) || :
if [[ -z "$first_gap" ]]; then
first_gap="0"
if [[ -z $last ]]; then
last="0"
else
last=$((last+1))
fi
echo "${bls_target}" | sed -e "s!${prefix}!${prefix}.${first_gap}~custom!"
echo "${bls_target}" | sed -e "s!${prefix}!${prefix}.${last}~custom!"
}
add_bls_fragment() {
@ -567,7 +563,7 @@ set_default_bls() {
echo "default=${default}" >> "${zipl_config}"
fi
fi
update_grubcfg
print_info "The default is ${bls_file[$index]} with index $index and kernel $(get_prefix)${bls_linux[$index]}"
}
@ -599,29 +595,33 @@ remove_var_prefix() {
update_grubcfg()
{
# Turn on RUN_MKCONFIG on different archs/scenarios
if [[ "${arch}" = 's390' ]] || [[ "${arch}" = 's390x' ]]; then
# On s390/s390x systems, run mkconfig/zipl
# Older ppc64le OPAL firmware (petitboot version < 1.8.0) don't have BLS support
# so grub2-mkconfig has to be run to generate a config with menuentry commands.
if [ "${arch}" = "ppc64le" ] && [ -d /sys/firmware/opal ]; then
RUN_MKCONFIG="true"
elif [[ "${arch}" = "ppc64le" ]] && [[ -d /sys/firmware/opal ]]; then
# Older ppc64le OPAL firmware don't have BLS support so grub2-mkconfig has to be run
# to generate a config with menuentry commands.
RUN_MKCONFIG="true"
elif [[ -e /sys/hypervisor/type ]] && grep -q "^xen$" /sys/hypervisor/type; then
if [ ! -e /sys/hypervisor/guest_type ] || ! grep -q "^HVM$" /sys/hypervisor/guest_type; then
# PV and PVH Xen DomU guests boot with pygrub that doesn't have BLS support,
# also Xen Dom0 use the menuentries from 20_linux_xen and not the ones from
# 10_linux. So grub2-mkconfig has to run for both Xen Dom0 and DomU.
RUN_MKCONFIG=true
petitboot_path="/sys/firmware/devicetree/base/ibm,firmware-versions/petitboot"
if test -e ${petitboot_path}; then
read -r -d '' petitboot_version < ${petitboot_path}
petitboot_version="$(echo ${petitboot_version//v})"
if test -n ${petitboot_version}; then
major_version="$(echo ${petitboot_version} | cut -d . -f1)"
minor_version="$(echo ${petitboot_version} | cut -d . -f2)"
re='^[0-9]+$'
if [[ $major_version =~ $re ]] && [[ $minor_version =~ $re ]] &&
([[ ${major_version} -gt 1 ]] ||
[[ ${major_version} -eq 1 &&
${minor_version} -ge 8 ]]); then
RUN_MKCONFIG="false"
fi
fi
fi
fi
if [[ $RUN_MKCONFIG = "true" ]]; then
if [[ $bootloader = "zipl" ]]; then
zipl
else
grub2-mkconfig --no-grubenv-update -o "${grub_config}" &> /dev/null
fi
grub2-mkconfig --no-grubenv-update -o "${grub_config}" >& /dev/null
fi
}
@ -630,7 +630,7 @@ print_usage()
cat <<EOF
Usage: grubby [OPTION...]
--add-kernel=kernel-path add an entry for the specified kernel
--args=args default arguments for the new kernel or new arguments for kernel being updated
--args=args default arguments for the new kernel or new arguments for kernel being updated)
--bad-image-okay don't sanity check images in boot entries (for testing only)
-c, --config-file=path path to grub config file to update ("-" for stdin)
--copy-default use the default boot entry as a template for the new entry being added; if the default is not a linux image, or if the kernel referenced by the default image does not exist, the
@ -827,15 +827,12 @@ fi
remove_var_prefix "$(get_prefix)"
if [[ -n $kernel ]]; then
if [[ $copy_default = "true" ]]; then
opts="${bls_options[$default_index]}"
if [[ -n $args ]]; then
opts="${opts} ${args}"
fi
else
opts="${opts} ${args}"
remove_args="$kernelopts"
update_args "${opts}" "${remove_args}" ""
opts="${bls_options[$default_index]}"
if [[ $copy_default != "true" ]]; then
opts=$(echo $opts | sed -e 's/ .*//')
fi
if [[ -n $args ]]; then
opts="${opts} ${args}"
fi
add_bls_fragment "${kernel}" "${title}" "${opts}" "${initrd}" \

View file

@ -3,16 +3,16 @@
Name: grubby
Version: 8.40
Release: 86%{?dist}
Release: 70%{?dist}
Summary: Command line tool for updating bootloader configs
License: GPL-2.0-or-later
License: GPLv2+
Source1: grubby-bls
# Source2: rpm-sort.c
Source3: COPYING
Source4: installkernel-bls
Source5: 95-kernel-hooks.install
Source6: 10-devicetree.install
Source7: grubby.8
Source8: kernel.sysconfig
BuildRequires: gcc
BuildRequires: glib2-devel
@ -22,7 +22,7 @@ BuildRequires: pkgconfig
BuildRequires: popt-devel
BuildRequires: rpm-devel
BuildRequires: sed
%ifarch aarch64 x86_64 %{power64} riscv64
%ifarch aarch64 x86_64 %{power64}
BuildRequires: grub2-tools-minimal
Requires: grub2-tools-minimal
Requires: grub2-tools
@ -53,6 +53,7 @@ cp %{SOURCE3} . || true
%install
mkdir -p %{buildroot}%{_sbindir}/
install -T -m 0755 %{SOURCE1} %{buildroot}%{_sbindir}/grubby
install -T -m 0755 %{SOURCE4} %{buildroot}%{_sbindir}/installkernel
install -D -m 0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE5}
install -D -m 0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE6}
@ -60,9 +61,6 @@ install -D -m 0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE6}
mkdir -p %{buildroot}%{_mandir}/man8
install -m 0644 %{SOURCE7} %{buildroot}%{_mandir}/man8/
mkdir -p %{buildroot}%{_sysconfdir}/sysconfig
install -m 0644 %{SOURCE8} %{buildroot}%{_sysconfdir}/sysconfig/kernel
%post
if [ "$1" = 2 ]; then
arch=$(uname -m)
@ -73,64 +71,15 @@ fi
%files
%license COPYING
%attr(0755,root,root) %{_sbindir}/grubby
%attr(0755,root,root) %{_sbindir}/installkernel
%attr(0755,root,root) %{_prefix}/lib/kernel/install.d/10-devicetree.install
%attr(0755,root,root) %{_prefix}/lib/kernel/install.d/95-kernel-hooks.install
%{_mandir}/man8/grubby.8*
%config(noreplace) %{_sysconfdir}/sysconfig/kernel
%changelog
* Wed Dec 10 2025 Simon de Vlieger <cmdr@supakeen.com> - 8.40-86
- Own `/etc/sysconfig/kernel` which is used for `grubby` configuration
* Wed Jul 30 2025 Leo Sandoval <lsandova@redhat.com> - 8.40-85
- Update cfg when setting a default kernel
* Thu Jul 24 2025 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-84
- Rebuilt for https://fedoraproject.org/wiki/Fedora_43_Mass_Rebuild
* Thu Mar 20 2025 Leo Sandoval <lsandova@redhat.com> - 8.40-83
- grubby-bls: in s390* systems, run zipl on grub cfg update event
Fixes previous commit and formats better the conditions that trigger grub cfg updates
* Fri Jan 17 2025 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-82
- Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild
* Mon Jan 06 2025 Nicolas Frayer <nfrayer@redhat.com> - 8.40-81
- Fixups to custom kernel targets
* Fri Dec 06 2024 Leo Sandoval <lsandova@redhat.com> - 8.40-80
- grubby-bls: on PPC systems, remove petiboot's version checks
* Fri Dec 06 2024 Leo Sandoval <lsandova@redhat.com> - 8.40-79
- grubby-bls: in s390* systems, run zipl on grub cfg update event
* Mon Dec 02 2024 David Abdurachmanov <davidlt@rivosinc.com> - 8.40-78
- Add riscv64 support
* Mon Nov 25 2024 Leo Sandoval <lsandova@redhat.com> - 8.40-77
- On grub cfg updates, run grub2-mkconfig for Xen systems
* Thu Jul 18 2024 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-76
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild
* Wed Jan 24 2024 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-75
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild
* Sat Jan 20 2024 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-74
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild
* Wed Jan 10 2024 Marta Lewandowska <mlewando@redhat.com> - 8.40-73
* Wed Jan 10 2024 Marta Lewandowska <mlewando@redhat.com> - 8.40-70
- Do not overwrite all vars that start with GRUB_CMDLINE_LINUX
* Mon Sep 11 2023 Zbigniew Jedrzejewski-Szmek <zbyszek@in.waw.pl> - 8.40-72
- Drop installkernel so that it can be provided by systemd
* Thu Jul 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-71
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild
* Tue Feb 21 2023 Marta Lewandowska <mlewando@redhat.com> - 8.40-70
- remove root= when not copying default
* Thu Jan 19 2023 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-69
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

83
installkernel-bls Executable file
View file

@ -0,0 +1,83 @@
#! /bin/sh
#
# /sbin/installkernel
#
# Copyright 2007-2008 Red Hat, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Author(s): tyson@rwii.com
#
usage() {
echo "Usage: `basename $0` <kernel_version> <bootimage> <mapfile>" >&2
exit 1
}
cfgLoader=
if [ -z "$INSTALL_PATH" -o "$INSTALL_PATH" == "/boot" ]; then
INSTALL_PATH=/boot
cfgLoader=1
fi
LINK_PATH=/boot
RELATIVE_PATH=`echo "$INSTALL_PATH/" | sed "s|^$LINK_PATH/||"`
KERNEL_VERSION=$1
BOOTIMAGE=$2
MAPFILE=$3
ARCH=$(uname -m)
if [ $ARCH = 'ppc64' -o $ARCH = 'ppc' ]; then
KERNEL_NAME=vmlinux
else
KERNEL_NAME=vmlinuz
fi
if [ -z "$KERNEL_VERSION" -o -z "$BOOTIMAGE" -o -z "$MAPFILE" ]; then
usage
fi
if [ -f $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION ]; then
mv $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION \
$INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION.old;
fi
if [ ! -L $INSTALL_PATH/$KERNEL_NAME ]; then
if [ -e $INSTALLPATH/$KERNEL_NAME ]; then
mv $INSTALL_PATH/$KERNEL_NAME $INSTALL_PATH/$KERNEL_NAME.old
fi
fi
if [ -f $INSTALL_PATH/System.map-$KERNEL_VERSION ]; then
mv $INSTALL_PATH/System.map-$KERNEL_VERSION \
$INSTALL_PATH/System.map-$KERNEL_VERSION.old;
fi
if [ ! -L $INSTALL_PATH/System.map ]; then
if [ -e $INSTALLPATH/System.map ]; then
mv $INSTALL_PATH/System.map $INSTALL_PATH/System.map.old
fi
fi
ln -sf ${RELATIVE_PATH}$INSTALL_PATH/System.map-$KERNEL_VERSION $LINK_PATH/System.map
cat $BOOTIMAGE > $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION
cp $MAPFILE $INSTALL_PATH/System.map-$KERNEL_VERSION
ln -fs ${RELATIVE_PATH}$INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION $LINK_PATH/$KERNEL_NAME
ln -fs ${RELATIVE_PATH}$INSTALL_PATH/System.map-$KERNEL_VERSION $LINK_PATH/System.map
if [ -n "$cfgLoader" ]; then
kernel-install add $KERNEL_VERSION $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION
exit $?
fi

View file

@ -1,6 +0,0 @@
# UPDATEDEFAULT specifies if kernel-install should make
# new kernels the default
UPDATEDEFAULT=yes
# DEFAULTKERNEL specifies the default kernel package type
DEFAULTKERNEL=kernel-core