Kernel upgrades from `pacman -Syu` fails. Presets aren't being created in `/etc/mkinitcpio.d/`

I’ve had this issue for over a year now and have been resolving it by, after every kernel upgrade, booting into a separate distro, mounting and chrooting into the arch install, running mkinitcpio manually, and copying the kernel and initram to where reFIND searches for them. I figure it’s time I understand and fix it. I am sure this is my fault, a result of some customization I made to my boot process (multi-booting with reFIND).

Here’s part of the output of my most recent yay -Syu.

(13/27) Updating linux initcpios...
==> Building image from preset: /etc/mkinitcpio.d/linux510.preset: 'default'
  -> -k /boot/efi/Manjaro/vmlinuz-5.10-x86_64 -c /etc/mkinitcpio.conf -g /boot/efi/Manjaro/initramfs-5.10-x86_64.img
==> ERROR: '/lib/modules/5.10.89-1-MANJARO' is not a valid kernel module directory
==> Building image from preset: /etc/mkinitcpio.d/linux510.preset: 'fallback'
  -> -k /boot/efi/Manjaro/vmlinuz-5.10-x86_64 -c /etc/mkinitcpio.conf -g /boot/efi/Manjaro/initramfs-5.10-x86_64-fallback.img -S autodetect
==> ERROR: '/lib/modules/5.10.89-1-MANJARO' is not a valid kernel module directory
error: command failed to execute correctly

The only file I have in /etc/mkinitcpio.d is a file named linux510.preset
From the Arch linux wiki on mkinitcpio I read:

Every time a kernel is installed or upgraded, a pacman hook automatically generates a .preset file saved in /etc/mkinitcpio.d/. For example linux.preset for the official stable linux kernel package. A preset is simply a list of information required to create initial ramdisk images, instead of manually specifying the various parameters and the location of the output files. By default, it contains the instructions to create two images:

I have the script and hook in /usr/share/libalpm. I don’t understand what I’m seeing when I view them though. I haven’t been able to track down the issue.

less /usr/share/libalpm/scripts/mkinitcpio-install
less /usr/share/libalpm/hooks/90-mkinitcpio-install.hook

I found those by searching the arch github for “preset” which led me to this page for a file that looked relevant: scripts/mkinitcpio-install

My partition/boot scheme has EFI with reFIND on one partition. That gives me options to boot windows or kernels/initrams from a 1 gig unencrypted partition where my root filesystem is a luks encrypted device.

Hope I provided enough info to be pointed in the right direction. Happy to provide more. Thanks.

Just to gather some data:
is /lib a symlink to /usr/lib?
ls -hl /lib
What is in /lib/modules?
ls -hl /lib/modules
What is in the preset file?
cat /etc/mkinitcpio.d/linux510.preset
No need to post it, but I have read of people who had an empty file there …

can you provide

sudo mhwd -li 
sudo ls /etc/mkinitcpio.d/*.preset
sudo ls /boot/
sudo ls /lib/modules/

To Nachlese:

➜  ~ ls -hl /lib
lrwxrwxrwx 1 root root 7 Dec 18 09:21 /lib -> usr/lib
➜  ~ ls -hl /lib/modules
total 32K
drwxr-xr-x 5 root root 4.0K Jan 29 16:36 5.10.42-1-MANJARO
drwxr-xr-x 5 root root 4.0K Jan 29 16:36 5.10.53-1-MANJARO
drwxr-xr-x 6 root root 4.0K Jan 29 16:37 5.10.56-1-MANJARO
drwxr-xr-x 5 root root 4.0K Jan 29 16:36 5.10.59-1-MANJARO
drwxr-xr-x 5 root root 4.0K Jan 29 16:36 5.10.60-1-MANJARO
drwxr-xr-x 5 root root 4.0K Jan 29 16:36 5.10.83-1-MANJARO
drwxr-xr-x 5 root root 4.0K Jan 29 16:36 5.10.93-1-MANJARO
drwxr-xr-x 2 root root 4.0K Jan 29 16:30 extramodules-5.10-MANJARO
➜  ~ cat /etc/mkinitcpio.d/linux510.preset
# mkinitcpio preset file for the 'linux510' package

ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/efi/Manjaro/vmlinuz-5.10-x86_64"

PRESETS=('default' 'fallback')

default_config="/etc/mkinitcpio.conf"
default_image="/boot/efi/Manjaro/initramfs-5.10-x86_64.img"
#default_options=""

#fallback_config="/etc/mkinitcpio.conf"
fallback_image="/boot/efi/Manjaro/initramfs-5.10-x86_64-fallback.img"
fallback_options="-S autodetect"

To stephane:

➜  ~ sudo mhwd -li
> Installed PCI configs:
--------------------------------------------------------------------------------
                  NAME               VERSION          FREEDRIVER           TYPE
--------------------------------------------------------------------------------
           video-linux            2018.05.04                true            PCI


Warning: No installed USB configs!
➜  ~ sudo ls /etc/mkinitcpio.d/*.preset
/etc/mkinitcpio.d/linux510.preset
➜  ~ sudo ls /boot
'$RECYCLE.BIN'                            efi               linux510-x86_64.kver   System.map-5.12.2-pentoo-x86_64          vmlinuz-5.10-x86_64
 config-5.13.8-gentoo-dist-hardened       grub              memtest86+             System.map-5.13.8-gentoo-dist-hardened
 config-5.13.8-gentoo-dist-hardened.old   intel-ucode.img   syslinux              'System Volume Information'
➜  ~ sudo ls /lib/modules
5.10.42-1-MANJARO  5.10.53-1-MANJARO  5.10.56-1-MANJARO  5.10.59-1-MANJARO  5.10.60-1-MANJARO  5.10.83-1-MANJARO  5.10.93-1-MANJARO  extramodules-5.10-MANJARO

And boot-related entries in /etc/fstab:

# <file system>             <mount point>  <type>  <options>  <dump>  <pass>
UUID=EA81-1874                            /boot      vfat    umask=0077 0 2
/boot/efi /boot none bind 0 0
/dev/nvme0n1p1 /mnt/p1 vfat defaults 0 2

I can’t remember why /boot/efi /boot none bind 0 0 is in there or what it does. Looking at it now, I question it.

/mnt/p1 is my EFI partition with reFIND.

Device              Start        End   Sectors   Size Type
/dev/nvme0n1p1       2048     534527    532480   260M EFI System
/dev/nvme0n1p2     534528     567295     32768    16M Microsoft reserved
/dev/nvme0n1p3     567296  974360575 973793280 464.3G Microsoft basic data
/dev/nvme0n1p4 1998360576 2000408575   2048000  1000M Windows recovery environment
/dev/nvme0n1p5  974360576  976457727   2097152     1G Microsoft basic data
/dev/nvme0n1p6  978554880 1188270079 209715200   100G Linux filesystem
/dev/nvme0n1p7 1188270080 1964806143 776536064 370.3G Linux filesystem
/dev/nvme0n1p8 1964806144 1998360575  33554432    16G Linux swap
/dev/nvme0n1p9  976457728  978554879   2097152     1G Microsoft basic data

it should not be here ( only version 5.10.93-1-MANJARO in /lib/modules )

drwxr-xr-x 5 root root 4.0K Jan 29 16:36 5.10.42-1-MANJARO
drwxr-xr-x 5 root root 4.0K Jan 29 16:36 5.10.53-1-MANJARO
drwxr-xr-x 6 root root 4.0K Jan 29 16:37 5.10.56-1-MANJARO
drwxr-xr-x 5 root root 4.0K Jan 29 16:36 5.10.59-1-MANJARO
drwxr-xr-x 5 root root 4.0K Jan 29 16:36 5.10.60-1-MANJARO
drwxr-xr-x 5 root root 4.0K Jan 29 16:36 5.10.83-1-MANJARO

remove these old modules

and you can add linux515 and linux516 ,( see mhwd-kernel )
you will have only one version in /boot/ and in /lib/modules

You issue may be caused by an earlier event where your system has been interupted during the actual transaction.

E.g. a power failure or a gui initiated sync which has left the system unresponsive and a forced shutdown has been executed.

When such event occurs - the kernel hooks has not been executed correct - thus leaving your system in a dysfunctional haf-finished state.

Only a manual cleanup can remedy such state.

A write-up on how to best avoid such issues can be found at below link