Making dracut run after akmods?

I installed akmod-nvidia-470xx and added do /etc/dracut.conf.d/my.conf:
add_drivers+=" nvidia nvidia_modeset nvidia_uvm nvidia_drm "

Unfortunately, on dnf upgrade, dracut runs before akmods – so importing these is not possible.
How can I make dracut wait until after akmods is finished??

I would write a shell script to do all the steps required.

I use systemctl list-jobs to make sure that there is nothing running after the update.

In the case of the akmod-nvidia-470xx it will be the akmods job that is running.
I code a loop that waits after the dnf update --refresh -y until there are no jobs running.

Then you can run dracut as you want.

This has never been an issue for me. My upgrades always seem to work well without mucking around with the timing of when dracut executes.

I do not think the actual driver is stored in the initramfs file (which is what dracut creates) but that the initramfs file tells the kernel which drivers to load from the root file system. If I am wrong in that belief I hope an expert corrects me, but this is what I have understood for a long time.

I think @ksvist forced the nvidia drivers into the initramfs from the dracut snippet.

That’s right, I manually set up Dracut to import nvidia modules. This was mostly based on a hunch & some comments – but it seems to make the setup work, even though it doesn’t make sense (I’m using nvidia as an offload card on my laptop).

@barryascott I found this thread. The annoyance with that setup is that initrd is already generated by some earlier script… so my script would have to run dracut -f to overwrite the just-generated version (blah). Anything better out there?

Looking in a bit more, /usr/lib/kernel/install.d/ has 50-dracut.install and 95-akmodsposttrans.install, which is pretty straightforward… but akmods wants to run in the background after the rpm transactions are done. :person_facepalming:

Have you considered /usr/lib/dracut/dracut.conf.d/99-nvidia-dracut.conf?
akmods has to run in the background and the result installed after the initial dnf transaction completes.

1 Like

This is on purpose since we won’t be able to install the generated kmod when the transaction occurs. Running dracut twice is indeed the best way forward on new kernel update.

But you also needs to deal with this on nvidia version upgrade.

Thanks, I guess I’ll do that!

“Luckily” for me, my nvidia driver is frozen :stuck_out_tongue:

Here’s what I ended up doing:
Edited /usr/lib/systemd/system/akmods@.service to add this line:
ExecStartPost=/usr/bin/systemd-inhibit --mode=block --what=idle:sleep:shutdown --who="akmods" --why="Post-Akmods Dracut Transaction running" /usr/bin/dracut --force --kver %i

This is kinda brittle, but makes it much easier in terms of not having to check when akmods is running.

Aside, not sure why this config uses RemainAfterExit=yes

The akmods service must remain active so it can perform its job when new akmods packages are installed, kernels are updated, etc. This seems why it remains running in the background.

But it’s configured as a Type=oneshot and is being run as is run as /bin/systemctl restart akmods@${KERNEL_VERSION}.service --no-block >/dev/null 2>&1 from /usr/lib/kernel/install.d/95-akmodsposttrans.install.
Also, the main command it runs (akmods ...) quits after it’s completed.
systemctl status ... says Active: active (exited)

I think it’s just an oversight.

It is to indicate that the one-shot service has run and would not run again if you do a systemctl start .... To re-run the service a systemctl restart would be required.

For services that run continuously systemd uses the existence of a process to know the service is active.

But for oneshot services you need to set RemainAfterExit=yes so that the systemd state management does not have to rely of a process runnimg.

1 Like

Followup after having used my config for a while:

  • This config does not survive a system upgrade :frowning: Hopefully, some systemD magic can make it work… but for now manually copying over the config
  • I also added a snapper entry after dracut to make sure there’s a good “post” snapshot including all the drivers built. The other day I had to roll back – and the rollback snapshot didn’t include the post-update built changes :frowning:

Since the config gets overwritten, this should help:
Add a file /etc/systemd/system/akmods@.service.d/override.conf with

[Service]
ExecStartPost=/usr/bin/systemd-inhibit --mode=block --what=idle:sleep:shutdown --who="akmods" --why="Post-Akmods Dracut Transaction running" /usr/bin/dracut --force --kver %i
ExecStartPost=/usr/bin/systemd-inhibit --mode=block --what=idle:sleep:shutdown --who="akmods" --why="Post-Akmods Snapper Transaction running" /usr/bin/snapper create --read-only --description "Post-Akmods snapshot"