FS#49052 - [linux] DKMS modules - mkinitcpio - execution order in kernel update is backwards

Attached to Project: Arch Linux
Opened by James (thx1138) - Friday, 22 April 2016, 15:59 GMT
Last edited by Doug Newgard (Scimmia) - Friday, 18 November 2016, 00:51 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Tobias Powalowski (tpowa)
Architecture All
Severity Very Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 9
Private No

Details

pacman 5.0.1-2

If or when a DKMS-built kernel module is desired in the initramfs-linux.img, currently, mkinitcpio must be manually re-run after a pointless automatic mkinitcpio run, because the new-kernel version of the module is not available when mkinitcpio is first run. This is an uncommon use case, but here is an example, though not the best use case. Perhaps an early-boot driver would be a better use case. Still...

...
:: Running pre-transaction hooks...
(1/1) Remove DKMS modules
==> dkms -q remove -q -m kdbus -v 3227.245fe93 -k 4.5.1-1-ARCH
:: Processing package changes...
...
(4/8) upgrading linux [################################################] 100%
>>> Updating module dependencies. Please wait ...
>>> Generating initial ramdisk, using mkinitcpio. Please wait...
==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'default'
-> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux.img
...
==> ERROR: module not found: `kdbus'
...
==> ERROR: module not found: `kdbus'
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-linux-fallback.img
==> WARNING: errors were encountered during the build. The image may not be complete.
...
:: Running post-transaction hooks...
(1/1) Install DKMS modules
==> dkms -q install -m kdbus -v 3227.245fe93 -k 4.5.2-1-ARCH

So now, to add the just-built module to /boot/initramfs-linux-fallback.img, mkinitcpio must be run again.

Of course, the kernel has to be installed before the module can be re-built. So, it would be better to run dkms after installing the kernel but before running mkinitcpio. Running mkinitcpio could itself be a "post-transaction hook", for instance, run after "Install DKMS modules".
This task depends upon

Closed by  Doug Newgard (Scimmia)
Friday, 18 November 2016, 00:51 GMT
Reason for closing:  Fixed
Additional comments about closing:  linux 4.8.8-2
Comment by Iacopo Isimbaldi (isiachi) - Saturday, 02 July 2016, 15:17 GMT
Same here. When I upgrade the kernel and dkms rebuild the zfs module, I always have to manually run mkinitcpio after to include the module.
Comment by Sebastian Schwarz (seschwar) - Sunday, 17 July 2016, 22:00 GMT
I suffer from this as well. mkinitcpio is run in the kernel package's post_install()/post_upgrade() before the DKMS rebuilds in the PostTransaction hook.

The initcpio should also be generated in a PostTransaction hook, which runs after the DKMS hook. The hook should probably part of the mkinitcpio package. In addition this would reduce code duplication between the install scripts of the kernel packages.

For now I'm using the following hook in /etc/pacman.d/hooks/75-mkinitcpio.hook:

[Trigger]
Operation = Install
Operation = Remove
Operation = Upgrade
Type = File
Target = usr/lib/modules/*/
Target = usr/src/*/dkms.conf

[Action]
Description = rebuild initial ramdisk environment
Depends = mkinitcpio
Exec = /usr/bin/mkinitcpio --allpresets
When = PostTransaction
Comment by Pauli Huttunen (WhiteEyeDoll) - Saturday, 01 October 2016, 19:54 GMT
This also affects the users of nvidia-dkms.

With nvidia blob drivers you need to include nvidia, nvidia_modeset, nvidia_uvm and nvidia_drm into initramfs to enable DRM kernel mode setting.

So I need to run an extra mkinitcpio manually or via a hook after the failed one every time when nvidia-dkms or linux/linux-lts updates.
Comment by Florian (liketechnik2000) - Saturday, 22 October 2016, 15:54 GMT
For me the same too. I have to run mkinitcpio manually after upgrades of linux/zfs updates, otherwise I'll end up with an unbootable system.
Comment by Alfred Krohmer (devkid) - Wednesday, 16 November 2016, 17:10 GMT
Any update on this? I don't agree on this being "low severity" because if you forget to run mkinitcpio after a kernel update just once you might end up with an unbootable system.
Comment by Florian (liketechnik2000) - Thursday, 17 November 2016, 21:15 GMT
On the recent update of linux package with pacman 5.0.1 the rebuild took place before the build of the mkinitcpio image. I don't know if this was random or not but in case it was not this could be considered solved now.
Comment by Pauli Huttunen (WhiteEyeDoll) - Thursday, 17 November 2016, 21:43 GMT
Recent upgrade to linux 4.8.8-2 moved to mkinitcpio running as pacman hook and solved this problem.

For people who want to combine out of tree module rebuilds to this hook:

The hook is currently named 80-linux.hook but there's already a commit that renames it to 99-linux.hook.

By creating a hook file with the same name in /etc/pacman.d/hooks/ you can override the default hook and extend it by appending new [Trigger] conditions to it.
Just remember to copy the contents of the original hook file into the overriding one.

For example my hook to append nvidia-dkms trigger events to it:

------------------------
[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Target = boot/vmlinuz-linux
Target = usr/lib/initcpio/*

[Trigger]
Type = Package
Operation = Install
Operation = Upgrade
Operation = Remove
Target = nvidia-dkms

[Action]
Description = Updating Arch Linux initramfs image
When = PostTransaction
Exec = /usr/bin/mkinitcpio -p linux
------------------------

Loading...