Compare commits

...
Sign in to create a new pull request.

17 commits

Author SHA1 Message Date
Simon de Vlieger
482a2825c4
spec: own /etc/sysconfig/kernel
`grubby` reads the `/etc/sysconfig/kernel` file which isn't owned by the
package, nor created by it. This leads to all image build tooling having
to take special care to write this file [1] [2] so produced deliverables
automatically update their kernels.

This commit moves the creation of this file to the `grubby` package so
things work 'out of the box' instead of needing to do out-of-package
configuration by third parties.

[1]: https://pagure.io/fedora-kiwi-descriptions/blob/f43/f/root/etc/sysconfig
[2]: a8fafe8d9b/data/distrodefs/fedora/imagetypes.yaml (L1027-L1028)

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-12-10 07:59:31 +01:00
Leo Sandoval
6095bc576b Update cfg when setting a default kernel
Signed-off-by: Raju Cheerla <rcheerla@redhat.com>
Signed-off-by: Leo Sandoval <lsandova@redhat.com>
2025-07-30 12:16:29 -06:00
Fedora Release Engineering
0eb1bed0a5 Rebuilt for https://fedoraproject.org/wiki/Fedora_43_Mass_Rebuild 2025-07-24 16:39:20 +00:00
Leo Sandoval
7d63bffff9 grubby-bls: in s390* systems, run zipl on grub cfg update event
Change takes into account s390* systems as target for zipl execution. Reformat
better archs/scenarios when either zipl or grub2-mkconfig must be run.

Signed-off-by: Leo Sandoval <lsandova@redhat.com>
2025-03-20 11:28:33 -06:00
Fedora Release Engineering
06113ecc4c Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild 2025-01-17 05:15:43 +00:00
Martin Hicks
beb5f2b8a8 Add 'custom' file entries at first gap
Don't add a the next custom file after the last existing entry.  This
could result in a growing custom number with a large gap at the
beginning.  Fill the custom entries starting from 0.

Signed-off-by: Martin Hicks <martin@sr-research.com>
Signed-off-by: Nicolas Frayer <nfrayer@redhat.com>
2025-01-06 11:00:58 +01:00
Martin Hicks
50760fed68 Allow custom filenames to exceed 10
9 sorts after 10, so "next" was always 10 and would overwrite previous
10~custom.conf files

Signed-off-by: Martin Hicks <martin@sr-research.com>
2025-01-06 09:47:28 +00:00
Leo Sandoval
6f82f6bf08 grubby-bls: on PPC systems, remove petiboot's version checks
Signed-off-by: Leo Sandoval <lsandova@redhat.com>
2024-12-06 12:15:22 -06:00
Leo Sandoval
410b6c7592 grubby-bls: in s390* systems, run zipl on grub cfg update event
Signed-off-by: Leo Sandoval <lsandova@redhat.com>
2024-12-06 12:05:42 -06:00
David Abdurachmanov
a94c545ae2 Add riscv64 support
Signed-off-by: David Abdurachmanov <davidlt@rivosinc.com>
2024-12-02 14:01:33 +01:00
Leo Sandoval
014744456d On grub cfg updates, run grub2-mkconfig for Xen systems
Signed-off-by: Leo Sandoval <lsandova@redhat.com>
2024-11-25 14:15:44 -06:00
Fedora Release Engineering
fbdec79a3e Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild 2024-07-18 08:39:45 +00:00
Emanuele Petriglia
197adec183 Fix small typo in --args help message 2024-04-10 14:38:27 +00:00
Fedora Release Engineering
758f62e580 Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild 2024-01-24 21:05:49 +00:00
Fedora Release Engineering
5318daa5c6 Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild 2024-01-20 21:34:21 +00:00
Marta Lewandowska
893f94f428 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:40:17 +01:00
Miroslav Suchý
a73ecd5815 Migrate to SPDX license
This is part of https://fedoraproject.org/wiki/Changes/SPDX_Licenses_Phase_2
2023-12-01 08:13:01 +00:00
4 changed files with 96 additions and 42 deletions

View file

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

View file

@ -356,22 +356,26 @@ get_custom_bls_filename() {
prefix="${bls_target%%${arch}}"
prefix="${prefix%.*}"
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)) || :
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}") || :
if [[ -z $last ]]; then
last="0"
else
last=$((last+1))
if [[ -z "$first_gap" ]]; then
first_gap="0"
fi
echo "${bls_target}" | sed -e "s!${prefix}!${prefix}.${last}~custom!"
echo "${bls_target}" | sed -e "s!${prefix}!${prefix}.${first_gap}~custom!"
}
add_bls_fragment() {
@ -500,7 +504,7 @@ update_bls_fragment() {
if [[ -n $old_args ]]; then
opts="$(update_args "${old_args}" "${remove_args}" "${add_args}")"
opts="$(echo "$opts" | sed -e 's/\//\\\//g')"
sed -i -e "s/^GRUB_CMDLINE_LINUX.*/GRUB_CMDLINE_LINUX=\\\"${opts}\\\"/" "${grub_etc_default}"
sed -i -e "s/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\\\"${opts}\\\"/" "${grub_etc_default}"
fi
fi
@ -563,7 +567,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]}"
}
@ -595,33 +599,29 @@ remove_var_prefix() {
update_grubcfg()
{
# 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
# Turn on RUN_MKCONFIG on different archs/scenarios
if [[ "${arch}" = 's390' ]] || [[ "${arch}" = 's390x' ]]; then
# On s390/s390x systems, run mkconfig/zipl
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
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
fi
fi
if [[ $RUN_MKCONFIG = "true" ]]; then
grub2-mkconfig --no-grubenv-update -o "${grub_config}" >& /dev/null
if [[ $bootloader = "zipl" ]]; then
zipl
else
grub2-mkconfig --no-grubenv-update -o "${grub_config}" &> /dev/null
fi
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

View file

@ -3,15 +3,16 @@
Name: grubby
Version: 8.40
Release: 72%{?dist}
Release: 86%{?dist}
Summary: Command line tool for updating bootloader configs
License: GPLv2+
License: GPL-2.0-or-later
Source1: grubby-bls
# Source2: rpm-sort.c
Source3: COPYING
Source5: 95-kernel-hooks.install
Source6: 10-devicetree.install
Source7: grubby.8
Source8: kernel.sysconfig
BuildRequires: gcc
BuildRequires: glib2-devel
@ -21,7 +22,7 @@ BuildRequires: pkgconfig
BuildRequires: popt-devel
BuildRequires: rpm-devel
BuildRequires: sed
%ifarch aarch64 x86_64 %{power64}
%ifarch aarch64 x86_64 %{power64} riscv64
BuildRequires: grub2-tools-minimal
Requires: grub2-tools-minimal
Requires: grub2-tools
@ -59,6 +60,9 @@ 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)
@ -72,8 +76,52 @@ fi
%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
- 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

6
kernel.sysconfig Normal file
View file

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