Message ID | 20231219201719.1967948-1-jtornosm@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v4] rpm-pkg: simplify installkernel %post | expand |
On Tue, Dec 19, 2023 at 09:17:19PM +0100, Jose Ignacio Tornos Martinez wrote: > The new installkernel application that is now included in systemd-udev > package allows installation although destination files are already present > in the boot directory of the kernel package, but is failing with the > implemented workaround for the old installkernel application from grubby > package. > > For the new installkernel application, as Davide says: > <<The %post currently does a shuffling dance before calling installkernel. > This isn't actually necessary afaict, and the current implementation > ends up triggering downstream issues such as > https://github.com/systemd/systemd/issues/29568 > This commit simplifies the logic to remove the shuffling. For reference, > the original logic was added in commit 3c9c7a14b627("rpm-pkg: add %post > section to create initramfs and grub hooks").>> > > But we need to keep the old behavior as well, because the old installkernel > application from grubby package, does not allow this simplification and > we need to be backward compatible to avoid issues with the different > packages. > > Mimic Fedora shipping process and store vmlinuz, config amd System.map > in the module directory instead of the boot directory. In this way, we will > avoid the commented problem for all the cases, because the new destination > files are not going to exist in the boot directory of the kernel package. > > Replace installkernel tool with kernel-install tool, because the latter is > more complete. Suitable manual actions are added as a default if tool is not > present (unusual). > > cc: stable@vger.kernel.org > Co-Developed-by: Davide Cavalca <dcavalca@meta.com> > Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com> Still works for me on Fedora 39, thanks for the fix! Tested-by: Nathan Chancellor <nathan@kernel.org> > --- > V1 -> V2: > - Complete to be backward compatible with the previous installkernel > application. > V2 -> V3: > - Follow the suggestions from Masahiro Yamada and change the installation > V3 -> V4: > - Make the patch applicable to linux-kbuild/for-next (ia64 support was > already removed). > > scripts/package/kernel.spec | 21 ++++++++++----------- > 1 file changed, 10 insertions(+), 11 deletions(-) > > diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec > index 89298983a169..17e7196c9be1 100644 > --- a/scripts/package/kernel.spec > +++ b/scripts/package/kernel.spec > @@ -55,12 +55,12 @@ patch -p1 < %{SOURCE2} > %{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release} > > %install > -mkdir -p %{buildroot}/boot > -cp $(%{make} %{makeflags} -s image_name) %{buildroot}/boot/vmlinuz-%{KERNELRELEASE} > +mkdir -p %{buildroot}/lib/modules/%{KERNELRELEASE} > +cp $(%{make} %{makeflags} -s image_name) %{buildroot}/lib/modules/%{KERNELRELEASE}/vmlinuz > %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install > %{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install > -cp System.map %{buildroot}/boot/System.map-%{KERNELRELEASE} > -cp .config %{buildroot}/boot/config-%{KERNELRELEASE} > +cp System.map %{buildroot}/lib/modules/%{KERNELRELEASE} > +cp .config %{buildroot}/lib/modules/%{KERNELRELEASE}/config > ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build > %if %{with_devel} > %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}' > @@ -70,12 +70,12 @@ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA > rm -rf %{buildroot} > > %post > -if [ -x /sbin/installkernel -a -r /boot/vmlinuz-%{KERNELRELEASE} -a -r /boot/System.map-%{KERNELRELEASE} ]; then > -cp /boot/vmlinuz-%{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm > -cp /boot/System.map-%{KERNELRELEASE} /boot/.System.map-%{KERNELRELEASE}-rpm > -rm -f /boot/vmlinuz-%{KERNELRELEASE} /boot/System.map-%{KERNELRELEASE} > -/sbin/installkernel %{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm > -rm -f /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm > +if [ -x /usr/bin/kernel-install ]; then > +kernel-install add %{KERNELRELEASE} /lib/modules/%{KERNELRELEASE}/vmlinuz > +else > +cp /lib/modules/%{KERNELRELEASE}/vmlinuz /boot/vmlinuz-%{KERNELRELEASE} > +cp /lib/modules/%{KERNELRELEASE}/System.map /boot/System.map-%{KERNELRELEASE} > +cp /lib/modules/%{KERNELRELEASE}/config /boot/config-%{KERNELRELEASE} > fi > > %preun > @@ -94,7 +94,6 @@ fi > %defattr (-, root, root) > /lib/modules/%{KERNELRELEASE} > %exclude /lib/modules/%{KERNELRELEASE}/build > -/boot/* > > %files headers > %defattr (-, root, root) > -- > 2.43.0 >
On Wed, Dec 20, 2023 at 5:17 AM Jose Ignacio Tornos Martinez <jtornosm@redhat.com> wrote: > > The new installkernel application that is now included in systemd-udev > package allows installation although destination files are already present > in the boot directory of the kernel package, but is failing with the > implemented workaround for the old installkernel application from grubby > package. > > For the new installkernel application, as Davide says: > <<The %post currently does a shuffling dance before calling installkernel. > This isn't actually necessary afaict, and the current implementation > ends up triggering downstream issues such as > https://github.com/systemd/systemd/issues/29568 > This commit simplifies the logic to remove the shuffling. For reference, > the original logic was added in commit 3c9c7a14b627("rpm-pkg: add %post > section to create initramfs and grub hooks").>> > > But we need to keep the old behavior as well, because the old installkernel > application from grubby package, does not allow this simplification and > we need to be backward compatible to avoid issues with the different > packages. > > Mimic Fedora shipping process and store vmlinuz, config amd System.map > in the module directory instead of the boot directory. In this way, we will > avoid the commented problem for all the cases, because the new destination > files are not going to exist in the boot directory of the kernel package. > > Replace installkernel tool with kernel-install tool, because the latter is > more complete. Suitable manual actions are added as a default if tool is not > present (unusual). This paragraph should be reworded, and the corresponding code should be fixed. This patch works for fedora 38 and fedora 39, but may break openSUSE tumbleweed, at least. The kernel-install itself does not copy files, but invoked scripts in /usr/lib/kernel/install.d/ In Fedora, /usr/lib/kernel/install.d/20-grub.install copies those files to /boot/. In openSUSE, the 'udev' package provides /usr/bin/kernel-install, but /usr/lib/kernel/install.d/20-grub.install is missing. masahiro@ea071f1f0504:~> rpm -qpl udev-254.5-8.1.x86_64.rpm | grep kernel /usr/bin/kernel-install /usr/lib/kernel /usr/lib/kernel/install.conf /usr/lib/kernel/install.d /usr/lib/kernel/install.d/50-depmod.install /usr/lib/kernel/install.d/90-loaderentry.install /usr/lib/kernel/install.d/90-uki-copy.install /usr/lib/systemd/system/sockets.target.wants/systemd-udevd-kernel.socket /usr/lib/systemd/system/systemd-udevd-kernel.socket /usr/share/bash-completion/completions/kernel-install /usr/share/man/man8/kernel-install.8.gz /usr/share/man/man8/systemd-udevd-kernel.socket.8.gz /usr/share/zsh/site-functions/_kernel-install In openSUSE with the udev package installed, none of vmlinuz, config, System.map is copied to the /boot directory. Applying the following on top should fix the regression, although I did not test any other RPM-based distros. diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec index afef3b0f6a3d..eb5cc440216b 100644 --- a/scripts/package/kernel.spec +++ b/scripts/package/kernel.spec @@ -71,12 +71,13 @@ rm -rf %{buildroot} %post if [ -x /usr/bin/kernel-install ]; then -kernel-install add %{KERNELRELEASE} /lib/modules/%{KERNELRELEASE}/vmlinuz -else -cp /lib/modules/%{KERNELRELEASE}/vmlinuz /boot/vmlinuz-%{KERNELRELEASE} -cp /lib/modules/%{KERNELRELEASE}/System.map /boot/System.map-%{KERNELRELEASE} -cp /lib/modules/%{KERNELRELEASE}/config /boot/config-%{KERNELRELEASE} + /usr/bin/kernel-install add %{KERNELRELEASE} /lib/modules/%{KERNELRELEASE}/vmlinuz fi +for file in vmlinuz System.map config; do + if [ ! -e "/boot/${file}-%{KERNELRELEASE}" ]; then + cp "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}" + fi +done %preun if [ -x /sbin/new-kernel-pkg ]; then > > cc: stable@vger.kernel.org > Co-Developed-by: Davide Cavalca <dcavalca@meta.com> > Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com> > --- > V1 -> V2: > - Complete to be backward compatible with the previous installkernel > application. > V2 -> V3: > - Follow the suggestions from Masahiro Yamada and change the installation > V3 -> V4: > - Make the patch applicable to linux-kbuild/for-next (ia64 support was > already removed). > > scripts/package/kernel.spec | 21 ++++++++++----------- > 1 file changed, 10 insertions(+), 11 deletions(-) > > diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec > index 89298983a169..17e7196c9be1 100644 > --- a/scripts/package/kernel.spec > +++ b/scripts/package/kernel.spec > @@ -55,12 +55,12 @@ patch -p1 < %{SOURCE2} > %{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release} > > %install > -mkdir -p %{buildroot}/boot > -cp $(%{make} %{makeflags} -s image_name) %{buildroot}/boot/vmlinuz-%{KERNELRELEASE} > +mkdir -p %{buildroot}/lib/modules/%{KERNELRELEASE} > +cp $(%{make} %{makeflags} -s image_name) %{buildroot}/lib/modules/%{KERNELRELEASE}/vmlinuz > %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install > %{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install > -cp System.map %{buildroot}/boot/System.map-%{KERNELRELEASE} > -cp .config %{buildroot}/boot/config-%{KERNELRELEASE} > +cp System.map %{buildroot}/lib/modules/%{KERNELRELEASE} > +cp .config %{buildroot}/lib/modules/%{KERNELRELEASE}/config > ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build > %if %{with_devel} > %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}' > @@ -70,12 +70,12 @@ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA > rm -rf %{buildroot} > > %post > -if [ -x /sbin/installkernel -a -r /boot/vmlinuz-%{KERNELRELEASE} -a -r /boot/System.map-%{KERNELRELEASE} ]; then > -cp /boot/vmlinuz-%{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm > -cp /boot/System.map-%{KERNELRELEASE} /boot/.System.map-%{KERNELRELEASE}-rpm > -rm -f /boot/vmlinuz-%{KERNELRELEASE} /boot/System.map-%{KERNELRELEASE} > -/sbin/installkernel %{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm > -rm -f /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm > +if [ -x /usr/bin/kernel-install ]; then > +kernel-install add %{KERNELRELEASE} /lib/modules/%{KERNELRELEASE}/vmlinuz > +else > +cp /lib/modules/%{KERNELRELEASE}/vmlinuz /boot/vmlinuz-%{KERNELRELEASE} > +cp /lib/modules/%{KERNELRELEASE}/System.map /boot/System.map-%{KERNELRELEASE} > +cp /lib/modules/%{KERNELRELEASE}/config /boot/config-%{KERNELRELEASE} > fi > > %preun > @@ -94,7 +94,6 @@ fi > %defattr (-, root, root) > /lib/modules/%{KERNELRELEASE} > %exclude /lib/modules/%{KERNELRELEASE}/build > -/boot/* > > %files headers > %defattr (-, root, root) > -- > 2.43.0 >
Hello Masahiro, Sorry for the delay in answering, I was on holiday. Good catch Ok, I will create a new patch including your suggestion and I will test it with Fedora, openSUSE and others if possible. Thank you again for your help Best regards José Ignacio
diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec index 89298983a169..17e7196c9be1 100644 --- a/scripts/package/kernel.spec +++ b/scripts/package/kernel.spec @@ -55,12 +55,12 @@ patch -p1 < %{SOURCE2} %{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release} %install -mkdir -p %{buildroot}/boot -cp $(%{make} %{makeflags} -s image_name) %{buildroot}/boot/vmlinuz-%{KERNELRELEASE} +mkdir -p %{buildroot}/lib/modules/%{KERNELRELEASE} +cp $(%{make} %{makeflags} -s image_name) %{buildroot}/lib/modules/%{KERNELRELEASE}/vmlinuz %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install %{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install -cp System.map %{buildroot}/boot/System.map-%{KERNELRELEASE} -cp .config %{buildroot}/boot/config-%{KERNELRELEASE} +cp System.map %{buildroot}/lib/modules/%{KERNELRELEASE} +cp .config %{buildroot}/lib/modules/%{KERNELRELEASE}/config ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build %if %{with_devel} %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}' @@ -70,12 +70,12 @@ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA rm -rf %{buildroot} %post -if [ -x /sbin/installkernel -a -r /boot/vmlinuz-%{KERNELRELEASE} -a -r /boot/System.map-%{KERNELRELEASE} ]; then -cp /boot/vmlinuz-%{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm -cp /boot/System.map-%{KERNELRELEASE} /boot/.System.map-%{KERNELRELEASE}-rpm -rm -f /boot/vmlinuz-%{KERNELRELEASE} /boot/System.map-%{KERNELRELEASE} -/sbin/installkernel %{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm -rm -f /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm +if [ -x /usr/bin/kernel-install ]; then +kernel-install add %{KERNELRELEASE} /lib/modules/%{KERNELRELEASE}/vmlinuz +else +cp /lib/modules/%{KERNELRELEASE}/vmlinuz /boot/vmlinuz-%{KERNELRELEASE} +cp /lib/modules/%{KERNELRELEASE}/System.map /boot/System.map-%{KERNELRELEASE} +cp /lib/modules/%{KERNELRELEASE}/config /boot/config-%{KERNELRELEASE} fi %preun @@ -94,7 +94,6 @@ fi %defattr (-, root, root) /lib/modules/%{KERNELRELEASE} %exclude /lib/modules/%{KERNELRELEASE}/build -/boot/* %files headers %defattr (-, root, root)
The new installkernel application that is now included in systemd-udev package allows installation although destination files are already present in the boot directory of the kernel package, but is failing with the implemented workaround for the old installkernel application from grubby package. For the new installkernel application, as Davide says: <<The %post currently does a shuffling dance before calling installkernel. This isn't actually necessary afaict, and the current implementation ends up triggering downstream issues such as https://github.com/systemd/systemd/issues/29568 This commit simplifies the logic to remove the shuffling. For reference, the original logic was added in commit 3c9c7a14b627("rpm-pkg: add %post section to create initramfs and grub hooks").>> But we need to keep the old behavior as well, because the old installkernel application from grubby package, does not allow this simplification and we need to be backward compatible to avoid issues with the different packages. Mimic Fedora shipping process and store vmlinuz, config amd System.map in the module directory instead of the boot directory. In this way, we will avoid the commented problem for all the cases, because the new destination files are not going to exist in the boot directory of the kernel package. Replace installkernel tool with kernel-install tool, because the latter is more complete. Suitable manual actions are added as a default if tool is not present (unusual). cc: stable@vger.kernel.org Co-Developed-by: Davide Cavalca <dcavalca@meta.com> Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com> --- V1 -> V2: - Complete to be backward compatible with the previous installkernel application. V2 -> V3: - Follow the suggestions from Masahiro Yamada and change the installation V3 -> V4: - Make the patch applicable to linux-kbuild/for-next (ia64 support was already removed). scripts/package/kernel.spec | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)