Custom kernel version is not correctly detected by Grub

Hello,

I started recently maintaining the Xanmod kernel in AUR (from the binary sources). My system is Manjaro. The original package maintainers need the binaries in /boot to have a fixed name (their boot manager is not Grub, but syslinux) and each filename modification means that the syslinux configuration needs to be manually modified.

This means that we have currently the following binaries in /boot for our kernel:

initramfs-linux-xanmod-linux-bin-x64v2-fallback.img
initramfs-linux-xanmod-linux-bin-x64v2.img
initramfs-linux-xanmod-linux-bin-x64v2.kver
vmlinuz-linux-xanmod-linux-bin-x64v2

The content of initramfs-linux-xanmod-linux-bin-x64v2.kver is 6.2.9-x64v2-xanmod1 which corresponds to

  • kernel major version
  • kernel minor version
  • kernel release version
  • the architecture name
  • flavor label and package release version

The trouble is that the current grub scripts are not picking the kernel name; from what I understand first the .img file, then then vmlinuz file names are parsed, and then the content of .kver file is retrieved in order to store the value in the macros used by grub scripts when generating the submenu.
So far this logic does not work with our kernel; we end up with menuentry β€˜Manjaro Linux (Kernel: x64v2)’ and menuentry β€˜Manjaro Linux (Kernel: x64v2 - fallback initramfs)’ in grub.cfg , which is, obviously, not enough to correctly identify the version of the kernel.
At the latest update of grub a few minutes ago (2.0.6.r456.g65bc45963-3) I saw the following output:

Creating temporary files...
Reloading device manager configuration...
Arming ConditionNeedsUpdate...
Updating linux initcpios...
==> Building image from preset: /etc/mkinitcpio.d/linux61.preset: 'default'
  -> -k /boot/vmlinuz-6.1-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-6.1-x86_64.img
==> Starting build: '6.1.22-1-MANJARO'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [autodetect]
  -> Running build hook: [modconf]
  -> Running build hook: [kms]
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
  -> Running build hook: [block]
  -> Running build hook: [filesystems]
  -> Running build hook: [usr]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: '/boot/initramfs-6.1-x86_64.img'
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux61.preset: 'fallback'
  -> -k /boot/vmlinuz-6.1-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-6.1-x86_64-fallback.img -S autodetect
==> Starting build: '6.1.22-1-MANJARO'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [modconf]
  -> Running build hook: [kms]
==> WARNING: Possibly missing firmware for module: 'ast'
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
  -> Running build hook: [block]
  -> Running build hook: [filesystems]
  -> Running build hook: [usr]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: '/boot/initramfs-6.1-x86_64-fallback.img'
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux62.preset: 'default'
  -> -k /boot/vmlinuz-6.2-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-6.2-x86_64.img
==> Starting build: '6.2.9-1-MANJARO'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [autodetect]
  -> Running build hook: [modconf]
  -> Running build hook: [kms]
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
  -> Running build hook: [block]
  -> Running build hook: [filesystems]
  -> Running build hook: [usr]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: '/boot/initramfs-6.2-x86_64.img'
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux62.preset: 'fallback'
  -> -k /boot/vmlinuz-6.2-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-6.2-x86_64-fallback.img -S autodetect
==> Starting build: '6.2.9-1-MANJARO'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [modconf]
  -> Running build hook: [kms]
==> WARNING: Possibly missing firmware for module: 'ast'
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
  -> Running build hook: [block]
  -> Running build hook: [filesystems]
  -> Running build hook: [usr]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: '/boot/initramfs-6.2-x86_64-fallback.img'
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux-xanmod-linux-bin-x64v2.preset: 'default'
  -> -k /boot/vmlinuz-linux-xanmod-linux-bin-x64v2 -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-xanmod-linux-bin-x64v2.img
==> Starting build: '6.2.9-x64v2-xanmod1'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [autodetect]
  -> Running build hook: [modconf]
  -> Running build hook: [kms]
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
  -> Running build hook: [block]
  -> Running build hook: [filesystems]
  -> Running build hook: [usr]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: '/boot/initramfs-linux-xanmod-linux-bin-x64v2.img'
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux-xanmod-linux-bin-x64v2.preset: 'fallback'
  -> -k /boot/vmlinuz-linux-xanmod-linux-bin-x64v2 -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-xanmod-linux-bin-x64v2-fallback.img -S autodetect
==> Starting build: '6.2.9-x64v2-xanmod1'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [modconf]
  -> Running build hook: [kms]
==> WARNING: Possibly missing firmware for module: 'ast'
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
  -> Running build hook: [block]
  -> Running build hook: [filesystems]
  -> Running build hook: [usr]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: '/boot/initramfs-linux-xanmod-linux-bin-x64v2-fallback.img'
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux-xanmod-lts-linux-bin-x64v2.preset: 'default'
/usr/lib/initcpio/functions: line 270: printf: `P': invalid format character
  -> -k /boot/vmlinuz-==> ERROR: specified kernel image does not exist: '/boot/vmlinuz-%PKGBASE%'
==> Building image from preset: /etc/mkinitcpio.d/linux-xanmod-lts-linux-bin-x64v2.preset: 'fallback'
/usr/lib/initcpio/functions: line 270: printf: `P': invalid format character
  -> -k /boot/vmlinuz-==> ERROR: specified kernel image does not exist: '/boot/vmlinuz-%PKGBASE%'
Error: command failed to execute correctly
Refreshing PackageKit...
Reloading system bus configuration...

Is there something I could do when building the kernel so that the names of the binaries remain as listed and yet the correct kernel name can be detected and written in the grub.cfg file ?

I also opened a case on Gitlab - #12

Thank you in advance for your help !

The problem I’m facing is that the name of the kernel is not correctly detected by Grub in the grub.cfg file.
Other than that, the kernel works fine, all modules are correctly loaded, dkms works fine as well.
My question goes more towards Grub - and how it fails to retrieve the kernel name, although we are producing the same β€œhints” as the official kernels.
If the kernel files are named using the version and build, then the Grub menu is updated accordingly, but when I published that change on AUR, a lot of users from other distros were impacted - they are not using Grub and they need to manually change their boot config files to see the new kernel image files.
I try to find a middle ground, so that the package can be convenient to use by both AUR based distros and also behave correctly with Manjaro.
My guess is that there can be added a small improvement in Grub.

A Manjaro kernel listing looks like this:

/boot
β”œβ”€β”€ amd-ucode.img
β”œβ”€β”€ efi
β”œβ”€β”€ grub
β”œβ”€β”€ initramfs-5.15-x86_64-fallback.img
β”œβ”€β”€ initramfs-5.15-x86_64.img
β”œβ”€β”€ initramfs-5.18-x86_64-fallback.img
β”œβ”€β”€ initramfs-5.18-x86_64.img
β”œβ”€β”€ initramfs-5.19-x86_64-fallback.img
β”œβ”€β”€ initramfs-5.19-x86_64.img
β”œβ”€β”€ initramfs-5.4-x86_64-fallback.img
β”œβ”€β”€ initramfs-5.4-x86_64.img
β”œβ”€β”€ initramfs-5.9-x86_64-fallback.img
β”œβ”€β”€ initramfs-5.9-x86_64.img
β”œβ”€β”€ initramfs-6.0-x86_64-fallback.img
β”œβ”€β”€ initramfs-6.0-x86_64.img
β”œβ”€β”€ initramfs-6.1-x86_64-fallback.img
β”œβ”€β”€ initramfs-6.1-x86_64.img
β”œβ”€β”€ intel-ucode.img
β”œβ”€β”€ linux515-x86_64.kver
β”œβ”€β”€ linux518-x86_64.kver
β”œβ”€β”€ linux519-x86_64.kver
β”œβ”€β”€ linux54-x86_64.kver
β”œβ”€β”€ linux59-x86_64.kver
β”œβ”€β”€ linux60-x86_64.kver
β”œβ”€β”€ linux61-x86_64.kver
β”œβ”€β”€ memtest86+
β”œβ”€β”€ vmlinuz-5.15-x86_64
β”œβ”€β”€ vmlinuz-5.18-x86_64
β”œβ”€β”€ vmlinuz-5.19-x86_64
β”œβ”€β”€ vmlinuz-5.4-x86_64
β”œβ”€β”€ vmlinuz-5.9-x86_64
β”œβ”€β”€ vmlinuz-6.0-x86_64
└── vmlinuz-6.1-x86_64

4 directories, 30 files

However you fail due to mkinitcpio configs:

==> Building image from preset: /etc/mkinitcpio.d/linux-xanmod-lts-linux-bin-x64v2.preset: 'default'
/usr/lib/initcpio/functions: line 270: printf: `P': invalid format character
  -> -k /boot/vmlinuz-==> ERROR: specified kernel image does not exist: '/boot/vmlinuz-%PKGBASE%'
==> Building image from preset: /etc/mkinitcpio.d/linux-xanmod-lts-linux-bin-x64v2.preset: 'fallback'
/usr/lib/initcpio/functions: line 270: printf: `P': invalid format character
  -> -k /boot/vmlinuz-==> ERROR: specified kernel image does not exist: '/boot/vmlinuz-%PKGBASE%'
Error: command failed to execute correctly

So the generated preset is wrong.

Those may look like this:

/etc/mkinitcpio.d
β”œβ”€β”€ linux515.preset
β”œβ”€β”€ linux518.preset
β”œβ”€β”€ linux519.preset
β”œβ”€β”€ linux53.preset.pacsave
β”œβ”€β”€ linux54.preset
β”œβ”€β”€ linux55.preset.pacsave
β”œβ”€β”€ linux56.preset.pacsave
β”œβ”€β”€ linux58.preset.pacsave
β”œβ”€β”€ linux59.preset
β”œβ”€β”€ linux60.preset
└── linux61.preset

For linux61 the generated content looks like:

# mkinitcpio preset file for the '6.1-x86_64' package

ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/vmlinuz-6.1-x86_64"

PRESETS=('default' 'fallback')

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

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

You may compare your preset content. Make sure you have the right files for generation set:

  # Used by mkinitcpio to name the kernel
  echo "${pkgbase}" | install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modules/${_kernver}/pkgbase"
  echo "${_basekernel}-${CARCH}" | install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modules/${_kernver}/kernelbase"

  # add kernel version
  echo "${pkgver}-${pkgrel}-MANJARO x64" > "${pkgdir}/boot/${pkgbase}-${CARCH}.kver"

Example output:

[phil@infinitybook ~]$ cat /usr/lib/modules/6.1.22-1-MANJARO/pkgbase
linux61
[phil@infinitybook ~]$ cat /usr/lib/modules/6.1.22-1-MANJARO/kernelbase
6.1-x86_64

Fix those files and call mkinitcpio -P again

Sorry to insist, the issue is not that I don’t know how to include the kernel version in the image files, the issue is that in the given context (kernel version should not appear in the names of the image files, for the reasons already mentioned) I’m unable to convince Grub to pick the kernel name from the .kver file, for example, although the Grub scripts are looking for this information.

Here is the relevant part of my PKGBUILD’s package() method:

  local kernver="${pkgver}-${_arch}-xanmod${_xanmodrel}"
  local modulesdir="${pkgdir}/usr/lib/modules/${kernver}"
  mkdir -p "${modulesdir}" "${pkgdir}/usr/share/doc"
  mkdir -p "${pkgdir}"/{boot,usr/lib/modules}

  msg2 "Installing modules..."
  cp -r lib/modules/${kernver}/* "${modulesdir}/"

  # Docs
  cp -r usr/share/doc/linux-image-* "${pkgdir}/usr/share/doc/"

  msg2 "Installing boot image..."
  # systemd expects to find the kernel here to allow hibernation
  # https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
  install -Dm644 "boot/vmlinuz-${kernver}" "${modulesdir}/vmlinuz"

  # Used by mkinitcpio to name the kernel
  echo "${pkgbase}" | install -Dm644 /dev/stdin "${modulesdir}/pkgbase"
  echo "${kernver}" | install -Dm644 /dev/stdin "${modulesdir}/kernelbase"

  # this .kver file is supposed to be read by Grub
  echo "${kernver}" > "${pkgdir}/boot/${pkgbase}.kver"

  local _extramodules="extramodules-${kernver}"
  ln -s "../${_extramodules}" "${modulesdir}/extramodules"

  # add real version for building modules and running depmod from hook
  echo "${kernver}" | install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modules/${_extramodules}/version"

  # now we call depmod...
  depmod -b "${pkgdir}/usr" -F "${srcdir}/boot/System.map-${kernver}"

The key is this line:

  echo "${pkgbase}" | install -Dm644 /dev/stdin "${modulesdir}/pkgbase"

If I put ${kernver} instead of ${pkgbase} then Grub will pick up the name and everything is fine - for Manjaro.

  echo "${kernver}" | install -Dm644 /dev/stdin "${modulesdir}/pkgbase"

But now, the image files names will contain the kernel version, which is upsetting for the other distros that do not use Grub and are expecting a constant file name.
Personally I thing this is a bit far-stretched, but I still hope to find a common ground.
Having looked a bit through Grub’s scripts, I understand that it tries to parse several sources of information in order to deduct the kernel name.
It even lists the contents of the .kver file which, from my script, has the correct kernel name in it. However, another parsing result gets retained, so we end up with Manjaro Linux (Kernel: x64v2) in the Grub menu, instead of Manjaro Linux (Kernel: 6.2.9-x64v2-xanmod1)
Other than that, the kernel loads corectly and all modules work properly.

As I understand your quest - if the ${pkgbase} is empty the script write %PKGBASE% to kver - so perhaps check when writing to kver?

Just throwing an idea

if ! [[ -z ${pkgbase} ]]; then
    echo "${pkgbase}" | install -Dm644 /dev/stdin "${modulesdir}/pkgbase"
else
    echo "${kernver}" | install -Dm644 /dev/stdin "${modulesdir}/pkgbase"
fi

or check if uname contains manjaro then decide which of the above to use?

I also feel that conditional building might be the quick and easy solution; the main β€œhint” would be how to detect that Grub is present or not.
Do you have any idea in that direction ?
Also, the %PKGBASE% error message was a fluke, when I switched from the specifically named image files to the β€œgeneric” named files.

This is only ideas

It should be easy to detect if grub is installed

which grub-mkconfig

Which loader is active - I don’t think you can get a conclusive answer?

You could use - if response contains β€˜BootCurrent’ you know efi is used or not

efibootmgr | grep BootCurrent

This I got from a web search - if you know the boot device - if the response contains GRUB you know grub is used or not - https://unix.stackexchange.com/questions/137570/find-bootloader

sudo dd if=/dev/sda bs=512 count=1 2>&1 | grep GRUB

There is several binaries grub-* perhaps one of them can assist

Testing for the presence of grub.cfg would be a strong enough hint that Grub is used ?

It would - but not conclusive as the file could exist - even if rEFind or systemd-boot is used.

And if a user is using EndeavourOS it may create entirely different issues as they use systemd boot and dracut

So, the most solid solution would be to amend the Grub scripts to search in priority for the .kver file content - which would make sense, actually; these files exist only to provide this exact information, right ?
And if they do not exist, then Grub continues to parse the file names …

I am not sure that is a viable solution - they would be changed when grub is updated.

You will need to figure out how - without modifying any upstream files.

I just tested the current PKGBUILD from AUR - everything play ball - no problems with grub or anything

13:37:19 Β± [fh@tiger] .../nest-misc/linux-xanmod
[master ?:6] $ makepkg -i
==> WARNING: The package group has already been built, installing existing packages...
==> Installing linux-xanmod package group with pacman -U...
[sudo] password for fh: 
loading packages...
resolving dependencies...
looking for conflicting packages...

Package (2)           New Version  Net Change

linux-xanmod          6.2.9-1      370,77 MiB
linux-xanmod-headers  6.2.9-1      145,48 MiB

Total Installed Size:  516,26 MiB

:: Proceed with installation? [Y/n] 
(2/2) checking keys in keyring                                     [------------------------------------] 100%
(2/2) checking package integrity                                   [------------------------------------] 100%
(2/2) loading package files                                        [------------------------------------] 100%
(2/2) checking for file conflicts                                  [------------------------------------] 100%
(2/2) checking available disk space                                [------------------------------------] 100%
:: Processing package changes...
(1/2) installing linux-xanmod                                      [------------------------------------] 100%
Optional dependencies for linux-xanmod
    crda: to set the correct wireless channels of your country [installed]
    linux-firmware: firmware images needed for some devices [installed]
(2/2) installing linux-xanmod-headers                              [------------------------------------] 100%
:: Running post-transaction hooks...
(1/6) Arming ConditionNeedsUpdate...
(2/6) Updating module dependencies...
(3/6) Install DKMS modules
==> dkms install --no-depmod v4l2loopback/0.12.7 -k 6.2.9-x64v1-xanmod1-1
==> dkms install --no-depmod vboxhost/7.0.6_OSE -k 6.2.9-x64v1-xanmod1-1
==> depmod 6.2.9-x64v1-xanmod1-1
(4/6) Updating linux initcpios...
==> Building image from preset: /etc/mkinitcpio.d/linux-xanmod.preset: 'default'
  -> -k /boot/vmlinuz-linux-xanmod -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-xanmod.img --microcode /boot/amd-ucode.img
==> Starting build: '6.2.9-x64v1-xanmod1-1'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [autodetect]
  -> Running build hook: [modconf]
  -> Running build hook: [block]
==> WARNING: Possibly missing firmware for module: 'xhci_pci'
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
==> WARNING: consolefont: no font found in configuration
  -> Running build hook: [plymouth]
  -> Running build hook: [filesystems]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: '/boot/initramfs-linux-xanmod.img'
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux-xanmod.preset: 'fallback'
  -> -k /boot/vmlinuz-linux-xanmod -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-xanmod-fallback.img -S autodetect --microcode /boot/amd-ucode.img
==> Starting build: '6.2.9-x64v1-xanmod1-1'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [modconf]
  -> Running build hook: [block]
==> WARNING: Possibly missing firmware for module: 'aic94xx'
==> WARNING: Possibly missing firmware for module: 'qed'
==> WARNING: Possibly missing firmware for module: 'bfa'
==> WARNING: Possibly missing firmware for module: 'qla2xxx'
==> WARNING: Possibly missing firmware for module: 'wd719x'
==> WARNING: Possibly missing firmware for module: 'qla1280'
==> WARNING: Possibly missing firmware for module: 'xhci_pci'
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
==> WARNING: consolefont: no font found in configuration
  -> Running build hook: [plymouth]
  -> Running build hook: [filesystems]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: '/boot/initramfs-linux-xanmod-fallback.img'
==> Image generation successful
(5/6) Refreshing PackageKit...
(6/6) Updating Grub-Bootmenu
Generating grub configuration file ...
Found theme: /usr/share/grub/themes/manjaro/theme.txt
Found linux image: /boot/vmlinuz-linux-xanmod
Found initrd image: /boot/amd-ucode.img /boot/initramfs-linux-xanmod.img
Found initrd fallback image: /boot/initramfs-linux-xanmod-fallback.img
Found linux image: /boot/vmlinuz-6.2-x86_64
Found initrd image: /boot/amd-ucode.img /boot/initramfs-6.2-x86_64.img
Found initrd fallback image: /boot/initramfs-6.2-x86_64-fallback.img
Found linux image: /boot/vmlinuz-6.1-x86_64
Found initrd image: /boot/amd-ucode.img /boot/initramfs-6.1-x86_64.img
Found initrd fallback image: /boot/initramfs-6.1-x86_64-fallback.img
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
Found memtest86+ image: /boot/memtest86+/memtest.bin
/usr/bin/grub-probe: warning: unknown device type nvme0n1.
Found memtest86+ EFI image: /boot/memtest86+/memtest.efi
/usr/bin/grub-probe: warning: unknown device type nvme0n1.
done
1 Like

And what is the name of the kernel in grub.cfg ?

The default entry is just Manjaro Linux and boots xanmod kernel

The advanced entries are

  • Manjaro Linux(Kernel: xanmod)
  • Manjaro Linux(Kernel: xanmod -fallback initramfs)

The linux-xanmod.preset has this content

[tiger mkinitcpio.d]# cat linux-xanmod.preset
# mkinitcpio preset file for the 'linux-xanmod' package

ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/vmlinuz-linux-xanmod"
ALL_microcode=(/boot/*-ucode.img)

PRESETS=('default' 'fallback')

#default_config="/etc/mkinitcpio.conf"
default_image="/boot/initramfs-linux-xanmod.img"
#default_uki="/efi/EFI/Linux/arch-%PKGBASE%.efi"
#default_options="--splash /usr/share/systemd/bootctl/splash-arch.bmp"

#fallback_config="/etc/mkinitcpio.conf"
fallback_image="/boot/initramfs-linux-xanmod-fallback.img"
#fallback_uki="/efi/EFI/Linux/arch-%PKGBASE%-fallback.efi"
fallback_options="-S autodetect"

I think you got another package, but even with that one, the name is insufficiently chosen by Grub - without further investigation you would not know which version is available from the menu.
Our packages are at linux-xanmod-linux-bin-x64v1, linux-xanmod-lts-linux-bin-x64v2, linux-xanmod-lts-linux-bin-x64v3 and linux-xanmod-lts-linux-bin-x64v4

I can see why you want the version included - I get the prebuilt -bin- but what is the version about?

Ohh - just realized - the v1, v2, v3 and v4 refer to CPU specific features … that makes sense too …

I was speculating where you got the ${kernver} variable from as it is not a default makepkg variable and you have no define of it in your PKGBUILD.

Perhaps you already know but I didn’t so I ran a

grep -rl 'kernver' /usr

and found it belongs in mkinitcpio, lsinitcpio and lib/initcpio/functions scripts.

Perhaps you could generate a grub configuration file 40_xanmod (using 40_custom as template) which would then ensure you have complete control over the menu and identify the kernels as you see fit - you can simply replace the file by adding a xanmod.install script to the package.

/usr/share/pacman/proto.install

# This is a default template for a post-install scriptlet.
# Uncomment only required functions and remove any functions
# you don't need (and this header).

## arg 1:  the new package version
#pre_install() {
        # do something here
#}

## arg 1:  the new package version
#post_install() {
        # do something here
#}

## arg 1:  the new package version
## arg 2:  the old package version
#pre_upgrade() {
        # do something here
#}

## arg 1:  the new package version
## arg 2:  the old package version
#post_upgrade() {
        # do something here
#}

## arg 1:  the old package version
#pre_remove() {
        # do something here
#}

## arg 1:  the old package version
#post_remove() {
        # do something here
#}

If you want to ensure the enduser has a complete list without a submeny you could alter the /etc/default/grub configuration to disable the advanced submenu

GRUB_DISABLE_SUBMENU=y

I found the fix and requested the grub Manjaro team to add a small patch.

--- /etc/grub.d/10_linux	2023-04-05 16:07:52.000000000 +0200
+++ ./10_linux.new	2023-04-08 08:01:50.714844743 +0200
@@ -262,6 +262,10 @@
     if test -e "${dirname}/${kbasename4}.kver" ; then
  	version="$(cat ${dirname}/${kbasename4}.kver)"
     fi
+    kbasename5=$(echo "${basename}" | sed -e 's,vmlinuz-,,g')
+    if test -e "${dirname}/${kbasename5}.kver" ; then
+ 	version=$(cat "${dirname}/${kbasename5}".kver)
+    fi
   fi
 
   initrd_early=

Basically is an additional test that makes β€œvisible” the .kver file.
The 4 scenarios already in place do not catch the name of the .kver file; with this additional scenario the file is found and its content is read.

Thank you, guys, for the time spent on this question ! It has helped me narrow down the list of possibilities.

1 Like

The issue is the following:

+  if test -e "/etc/manjaro-release" ; then
+    kbasename="`echo "${basename}" | sed -e 's,vmlinuz-,linux,g'`"
+    if test -e "${dirname}/${kbasename}.kver" ; then
+ 	version="$(cat ${dirname}/${kbasename}.kver)"
+    fi
+    kbasename2="`echo "${basename}" | sed -e 's,vmlinuz-,linux-,g'`"
+    if test -e "${dirname}/${kbasename2}.kver" ; then
+ 	version="$(cat ${dirname}/${kbasename2}.kver)"
+    fi
+    kbasename3="`echo "${basename}" | sed -e 's,vmlinuz-,linux,g' | sed -e 's,\.,,g'`"
+    if test -e "${dirname}/${kbasename3}.kver" ; then
+ 	version="$(cat ${dirname}/${kbasename3}.kver)"
+    fi
+    kbasename4="`echo "${basename}" | sed -e 's,vmlinuz-,linux-,g' | sed -e 's,\.,,g'`"
+    if test -e "${dirname}/${kbasename4}.kver" ; then
+ 	version="$(cat ${dirname}/${kbasename4}.kver)"
+    fi
+  fi

We expect to have the .kver file starting with linux- based on the search cases we currently have in our custom grub patches.

For linux61 package we have:

/boot/initramfs-6.1-x86_64-fallback.img
/boot/vmlinuz-6.1-x86_64
/boot/initramfs-6.1-x86_64.img
/boot/linux61-x86_64.kver

Content of the pkgbase and kernelbase files is as followed:

[phil@infinitybook ~]$ cat /usr/lib/modules/6.1.22-1-MANJARO/pkgbase
linux61
[phil@infinitybook ~]$ cat /usr/lib/modules/6.1.22-1-MANJARO/kernelbase
6.1-x86_64

So grub looks for vmlinuz-6.1-x86_64 and replaces vmlinuz- with linux, removes the dot and adds the .kver ending, which results into linux61-x86_64.kver

Now to your file naming:

initramfs-linux-xanmod-linux-bin-x64v2-fallback.img
initramfs-linux-xanmod-linux-bin-x64v2.img
initramfs-linux-xanmod-linux-bin-x64v2.kver
vmlinuz-linux-xanmod-linux-bin-x64v2

Why you call the key file starting with initramfs?. If you would name initramfs-linux-xanmod-linux-bin-x64v2.kver as linux-linux-xanmod-linux-bin-x64v2.kver one of the current search cases would pick it up.

But I can also add the following as you posted to remove the extra linux- requirement:

+    kbasename5=$(echo "${basename}" | sed -e 's,vmlinuz-,,g')
+    if test -e "${dirname}/${kbasename5}.kver" ; then
+ 	version=$(cat "${dirname}/${kbasename5}".kver)
+    fi

Then the following file names are needed

initramfs-linux-xanmod-linux-bin-x64v2-fallback.img
initramfs-linux-xanmod-linux-bin-x64v2.img
linux-xanmod-linux-bin-x64v2.kver
vmlinuz-linux-xanmod-linux-bin-x64v2