As suggested by https://bugzilla.redhat.com/show_bug.cgi?id=2394774#c8 Akmods could use the libdnf5-actions(8) interface, packaged in libdnf5-plugin-actions. That allows to execute arbitrary scripts after finishing a transaction before DNF5 exits. Reproducible: Always
Created attachment 2107458 [details] zzz RPM to simuate a long dnf transaction
Hi. I tried using that. This is very promising: one will finally have the kmods build and installed synchronously at the end of a dnf transation, hopefully also with every soft using libdnf5 (like packagekit I hope). That will be a benefit also when doing non offline upgrades. I tested a removal followed by an installation of akmod-VirtualBox in a "long" transaction. The %posttrans of akmod-VirtualBox failed thus with: Transaction failed: Failed to obtain rpm transaction lock. Another transaction is in progress. but the libdnf5-action succeeded afterwards. Setup: - F42 - install akmods-0.6.1-2.fc42 libdnf5-plugin-actions-5.2.16.0-1.fc42 - defines the action: /etc/dnf/libdnf5-plugins/actions.d/akmods.actions as: post_transaction:akmod-*:in:raise_error=0:/bin/bash -c (set\ -x;kmod=${pkg.name};kmod=\$\{kmod#akmod-};/usr/sbin/akmods\ --akmod\ \$kmod)\ |&\ logger\ -t\ akmods-action Note: this would be far simpler if akmods may accept akmod-foo and not only foo with the --akmod option. - untar from / the zzz.tar attached It contains a zzz.spec and a zzz.rpm that only does a sleep in %posttrans - configure zzz: echo 1m > /tmp/zzz.duration # 1m is far too long but makes the logs clearer Test: uname -r 6.16.5-200.fc42.x86_64 dnf -y remove --no-autoremove zzz akmod-VirtualBox kmod-VirtualBox-$(uname -r); \ dnf -y install /root/rpmbuild/RPMS/noarch/zzz-1.0-1.noarch.rpm akmod-VirtualBox; \ rpm -q kmod-VirtualBox-$(uname -r) Trace that shows that the kmod is installed just after dnf finishes: [...] [1/1] Total 100% | 89.9 KiB/s | 25.6 KiB | 00m00s Running transaction [1/4] Verify package files 100% | 2.0 KiB/s | 2.0 B | 00m00s [2/4] Prepare transaction 100% | 14.0 B/s | 2.0 B | 00m00s [3/4] Installing akmod-VirtualBox-0:7.2.2-1.fc42.x86_64 100% | 3.0 MiB/s | 49.0 KiB | 00m00s [4/4] Installing zzz-0:1.0-1.noarch 100% | 1.0 B/s | 124.0 B | 01m18s Warning: skipped OpenPGP checks for 1 package from repository: @commandline Complete! kmod-VirtualBox-6.16.5-200.fc42.x86_64-7.2.2-1.fc42.x86_64 root@fmpc 2025-09-24 08:44:30 tail -F /var/cache/akmods/VirtualBox/.last.log [...] 2025/09/24 08:43:20 akmods: DNF detected Updating and loading repositories: Repositories loaded. Package Arch Version Repository Size Installing: kmod-VirtualBox-6.16.5-200.fc42.x86_64 x86_64 7.2.2-1.fc42 @commandline 211.6 KiB Transaction Summary: Installing: 1 package Total size of inbound packages is 223 KiB. Need to download 0 B. After this operation, 212 KiB extra will be used (install 212 KiB, remove 0 B). Running transaction Transaction failed: Failed to obtain rpm transaction lock. Another transaction is in progress. Warning: skipped OpenPGP checks for 1 package from repository: @commandline 2025/09/24 08:43:26 akmods: Could not install newly built RPMs. You can find them and the logfile in: 2025/09/24 08:43:26 akmods: /var/cache/akmods/VirtualBox/7.2.2-1-for-6.16.5-200.fc42.x86_64.failed.log [...] Total size of inbound packages is 223 KiB. Need to download 0 B. After this operation, 212 KiB extra will be used (install 212 KiB, remove 0 B). Running transaction [1/3] Verify package files 100% | 500.0 B/s | 1.0 B | 00m00s [2/3] Prepare transaction 100% | 7.0 B/s | 1.0 B | 00m00s [3/3] Installing kmod-VirtualBox-6.16.5 100% | 32.2 KiB/s | 212.6 KiB | 00m07s Warning: skipped OpenPGP checks for 1 package from repository: @commandline Complete! 2025/09/24 08:44:29 akmods: Successful. journal: journalctl --since 08:40 -t akmods-action Sep 24 08:44:12 fmpc akmods-action[579164]: + kmod=akmod-VirtualBox Sep 24 08:44:12 fmpc akmods-action[579164]: + kmod=VirtualBox Sep 24 08:44:12 fmpc akmods-action[579164]: + /usr/sbin/akmods --akmod VirtualBox Sep 24 08:44:12 fmpc akmods-action[579164]: Checking kmods exist for 6.16.7-200.fc42.x86_64 [ OK ] Sep 24 08:44:12 fmpc akmods-action[579164]: Checking kmods exist for 6.16.5-200.fc42.x86_64 [ OK ] Sep 24 08:44:29 fmpc akmods-action[579164]: Building and installing VirtualBox-kmod [ OK ] journalctl --since 08:40 | grep zzz Sep 24 08:43:10 fmpc audit[577545]: SOFTWARE_UPDATE pid=577545 uid=0 auid=1000 ses=3 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=remove sw="zzz-1.0-1.noarch" sw_type=rpm key_enforce=0 gpg_res=0 root_dir="/" comm="dnf" exe="/usr/bin/dnf5" hostname=fmpc addr=? terminal=pts/3 res=success' Sep 24 08:43:12 fmpc root[577654]: zzz-posttrans start Sep 24 08:44:12 fmpc root[579161]: zzz-posttrans end Sep 24 08:44:12 fmpc audit[577608]: SOFTWARE_UPDATE pid=577608 uid=0 auid=1000 ses=3 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=install sw="zzz-1.0-1.noarch" sw_type=rpm key_enforce=0 gpg_res=0 root_dir="/" comm="dnf" exe="/usr/bin/dnf5" hostname=fmpc addr=? terminal=pts/3 res=success' There is many other things to try, to choose ... I may test installing a kernel (the one of the F42 release for example).
> I may test installing a kernel (the one of the F42 release for example). Done. It works also as expected. No problem with kernel-devel: the post_transaction actions are really done **after** the whole (RPM) transaction. Setup: - /etc/dnf/libdnf5-plugins/actions.d/akmods.actions: (no more traces) post_transaction:akmod-*:in:raise_error=0:/bin/bash -c kmod=${pkg.name};kmod=\$\{kmod#akmod-};/usr/sbin/akmods\ --akmod\ \$kmod\ |&\ logger\ -t\ akmods-action-${pkg.name} post_transaction:kernel-core:in:raise_error=0:/bin/bash -c /usr/sbin/akmods\ --kernels\ ${pkg.version}-${pkg.release}.${pkg.arch}\ |&\ logger\ -t\ akmods-action-${pkg.name} Test: uses explicitly the needed kernel* RPMs kver=6.14.0-63.fc42.x86_64 krpms=( kernel{,-core,-devel,-modules,-modules-core,-modules-extra}-$kver ) echo 5 > /tmp/zzz.duration # Sufficient in this case dnf -y remove --no-autoremove zzz "${krpms[@]}" kmod-VirtualBox-$kver; \ date; \ dnf -y install /root/rpmbuild/RPMS/noarch/zzz-1.0-1.noarch.rpm "${krpms[@]}"; \ date; \ rpm -q kmod-VirtualBox-$kver Trace: [...] [6/9] Installing kernel-0:6.14.0-63.fc42.x86_64 100% | 3.4 KiB/s | 124.0 B | 00m00s [7/9] Installing kernel-modules-extra-0:6.14.0-63.fc42.x86_64 100% | 674.8 KiB/s | 2.6 MiB | 00m04s [8/9] Installing zzz-0:1.0-1.noarch 100% | 3.8 KiB/s | 124.0 B | 00m00s [9/9] Installing kernel-devel-0:6.14.0-63.fc42.x86_64 100% | 929.3 KiB/s | 82.4 MiB | 01m31s Warning: skipped OpenPGP checks for 1 package from repository: @commandline Complete! Wed Sep 24 03:07:27 PM CEST 2025 kmod-VirtualBox-6.14.0-63.fc42.x86_64-7.2.2-1.fc42.x86_64 journal:j ournalctl --since -1h | grep akmods-action Sep 24 15:03:25 fmpc akmods-action-akmod-VirtualBox[1071340]: Checking kmods exist for 6.14.0-63.fc42.x86_64 [ OK ] Sep 24 15:03:25 fmpc akmods-action-akmod-VirtualBox[1071340]: Checking kmods exist for 6.16.5-200.fc42.x86_64 [ OK ] Sep 24 15:03:41 fmpc akmods-action-akmod-VirtualBox[1071340]: Building and installing VirtualBox-kmod [ OK ] Sep 24 15:07:12 fmpc akmods-action-kernel-core[1108904]: Checking kmods exist for 6.14.0-63.fc42.x86_64 [ OK ] Sep 24 15:07:27 fmpc akmods-action-kernel-core[1108904]: Building and installing VirtualBox-kmod [ OK ] I tried to have the akmod logs in the terminal (by redirecting stdout to stderr since libdnf5-actions parses the stdout) but this is confusing. Example: [2/4] Prepare transaction 100% | 14.0 B/s | 2.0 B | 00m00s [3/4] Installing akmod-VirtualBox-0:7.2.2-1.fc42.x86_64 100% | 2.8 MiB/s | 49.0 KiB | 00m00s [4/4] Installing zzz-0:1.0-1.noarch 100% [==================] | 24.0 B/s | 124.0 B | 00m00+ kmod=akmod-VirtualBox + kmod=VirtualBox + /usr/sbin/akmods --akmod VirtualBox Checking kmods exist for 6.14.0-63.fc42.x86_64 [ OK ] Checking kmods exist for 6.16.5-200.fc42.x86_64 [ OK ] Building and installing VirtualBox-kmod [ OK ] [4/4] Installing zzz-0:1.0-1.noarch 100% | 3.0 B/s | 124.0 B | 00m33s Warning: skipped OpenPGP checks for 1 package from repository: @commandline Complete! there is 2 lines for [4/4] Installing zzz-0:1.0-1.noarch Using logger is IMO better: - simple - pertains to the standard util-linux-core RPM - AFAIK libdnf5-actions does not permit redirecting properly to the dnf output
I suggest to do the following to add libdnf5-plugin-actions support. 1. Add a akmods.actions file in git. See the previous comment: comment3 2. akmods.spec: - In the dnf5 case (ie: fedora >= 41 not for rhel, even rhel10 that still uses dnf-4): - Requires: libdnf5-plugin-actions, /usr/bin/logger - %install: install akmods.actions in /etc/dnf/libdnf5-plugins/actions.d/ - Files: add /etc/dnf/libdnf5-plugins/actions.d/akmods.actions 3. akmods: - no mandatory modifications to do but: - optimisation: do not rebuild a kmod-foo if its RPM already exist under /var/cache/akmods/foo/, only install it with dnf - fix the message line 420: akmods_echo 2 1 "Could not install newly built RPMs. You can find them and the logfile in:" < akmods_echo 2 1 "/var/cache/akmods/${this_kmodname}/${this_kmodverrel}-for-${this_kernelver}.failed.log" > akmods_echo 2 1 "/var/cache/akmods/${this_kmodname} The posttrans calls to akmods will eventually fail due to the rpm transaction lock. but the akmods libdnf5 action will succeed afterwards. The libdnf5 action will takes no time if the posttrans calls succeeded.
See also: https://bugzilla.redhat.com/show_bug.cgi?id=2394774#c11
Please bear in mind that the "action" hook is specific to libdnf5. In Fedora 43 Packagekit (and thus Gnome Software) still uses DNF4 libdnf. We have python3-dnf-plugin-post-transaction-actions, but that is, I think, a plugin for DNF4 program, not for libdnf library.
(In reply to Petr Pisar from comment #6) > Please bear in mind that the "action" hook is specific to libdnf5. In Fedora .. That makes me wonder how to detect that the running transaction is libdnf5 over dnf-4 ? (without going into ps and).
(In reply to Nicolas Chauvet (kwizart) from comment #7) > That makes me wonder how to detect that the running transaction is libdnf5 > over dnf-4 ? (without going into ps and). You can have a different command in the action plugin configuration. Also libdn5 plugin substitutes ${plugin.version} variable. But if you ask for RPM scriptlet, then I guess there is no reliable way.
Anyone to submit a patch in a "git am" form or pagure pull request for review (if not going into error 503) ? I still lake time to look into this. I'm still unsure why this is a problem now and not with older dnf-4 ? (please: concise answer only).
Okay, Luan got a patch that recovered the test from system-upgrade.target, so we don't have the issue anymore. https://src.fedoraproject.org/rpms/akmods/pull-request/26 The libdnf5-plugin-actions is a good way forward but needs proper testing. @francis.montagnac Can you submit a pull request on pagure ? src.fedoraproject.org/rpms/akmods so this can be properly reviewed/tested ? Thanks in advance.