From: Jan Stancek <[email protected]>

redhat: spec: trigger dracut when modules are installed separately

In most scenarios, users install -core and -modules subpackages
at the same time (as part of same transaction). But it is also
possible to install -core RPM and then -modules RPM separately.
We allow this because some environments don't need modules.

Installing RPMs separately can cause issues. Since we trigger
initramdisk rebuild (in %posttrans script) only for -core package,
some modules may end up missing from init ramdisk.

Introduce state file to determine whether or not -modules subpackage
should trigger dracut to rebuild ramdisk. If both -core and -modules
RPMs are installed in same transaction, there's no extra action.
If -modules RPM is installed separately, trigger dracut in %posttrans
to re-generate init ramdisk.

Signed-off-by: Jan Stancek <[email protected]>

diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template
index blahblah..blahblah 100755
--- a/redhat/kernel.spec.template
+++ b/redhat/kernel.spec.template
@@ -2684,9 +2684,20 @@ fi\
 %define kernel_modules_post() \
 %{expand:%%post %{?1:%{1}-}modules}\
 /sbin/depmod -a %{KVERREL}%{?1:+%{1}}\
+if [ ! -f %{_localstatedir}/lib/rpm-state/kernel/installing_core ]; then\
+       mkdir -p %{_localstatedir}/lib/rpm-state/kernel\
+       touch %{_localstatedir}/lib/rpm-state/kernel/need_to_run_dracut\
+fi\
 %{nil}\
 %{expand:%%postun %{?1:%{1}-}modules}\
 /sbin/depmod -a %{KVERREL}%{?1:+%{1}}\
+%{nil}\
+%{expand:%%posttrans %{?1:%{1}-}modules}\
+if [ -f %{_localstatedir}/lib/rpm-state/kernel/need_to_run_dracut ]; then\
+       echo "Running: dracut -f --kver %{KVERREL}%{?1:+%{1}}"\
+       rm -f %{_localstatedir}/lib/rpm-state/kernel/need_to_run_dracut\
+       dracut -f --kver "%{KVERREL}%{?1:+%{1}}" || exit $?\
+fi\
 %{nil}
 
 # This macro defines a %%posttrans script for a kernel package.
@@ -2701,6 +2712,7 @@ then\
     %{_sbindir}/weak-modules --add-kernel %{KVERREL}%{?1:+%{1}} || exit $?\
 fi\
 %endif\
+rm -f touch %{_localstatedir}/lib/rpm-state/kernel/installing_core\
 /bin/kernel-install add %{KVERREL}%{?1:+%{1}} 
/lib/modules/%{KVERREL}%{?1:+%{1}}/vmlinuz || exit $?\
 %{nil}
 
@@ -2721,6 +2733,8 @@ if [ `uname -i` == "x86_64" -o `uname -i` == "i386" ] &&\
    [ -f /etc/sysconfig/kernel ]; then\
   /bin/sed -r -i -e 
's/^DEFAULTKERNEL=%{-r*}$/DEFAULTKERNEL=kernel%{?-v:-%{-v*}}/' 
/etc/sysconfig/kernel || exit $?\
 fi}\
+mkdir -p %{_localstatedir}/lib/rpm-state/kernel\
+touch %{_localstatedir}/lib/rpm-state/kernel/installing_core\
 %{nil}
 
 #

--
https://gitlab.com/cki-project/kernel-ark/-/merge_requests/1644
_______________________________________________
kernel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/[email protected]
Do not reply to spam on the list, report it: 
https://pagure.io/fedora-infrastructure

Reply via email to