You are not logged in.

#1 2021-09-28 11:23:48

Kerosin
Member
Registered: 2021-09-28
Posts: 5

different kernel version loading

Hello,
I am wondering whether it is possible to load different os (both arch) but running different kernel versions while sharing the same boot folder?
I utilize "A" kernel version for the os arch1, thus, having vmlinuz and iniramfs generated properly (placed at /dev/sda1), the os runs fine.
I have the second OS arch2 that runs "B" kernel version, having iniramfs_2  generated specifically for the "B" kernel version and placed also at /dev/sda1.
The problem appears when I am trying to boot into arch2, having the error "/lib/modules/B/modules not found, what is right from the arch1 perspective because vmlinuz and initramfs have been generated from the A kernel version.

For me, it seems like vmlinuz is being generated according to "A" kernel version makes it impossible to load the "B" kernel version..

How do I resolve this problem?

Offline

#2 2021-09-28 11:38:36

Scimmia
Fellow
Registered: 2012-09-01
Posts: 13,729

Re: different kernel version loading

Sharing the same boot dir? No, not without using a totally separate kernel package. You would need to mount sda1 elsewhere, then bind mount a separate dir to /boot for each OS.

Last edited by Scimmia (2021-09-28 11:39:58)

Offline

#3 2021-09-28 11:43:30

Kerosin
Member
Registered: 2021-09-28
Posts: 5

Re: different kernel version loading

Seems like I have got an insight.
Right vmlinuz file for arch2 can be found in modules/"B" folder in arch2 filesystem. Copying this file to boot folder, changing the name to vmlinuz_arch2, fixing grub.cfg accordingly fixes startup issue.
However, maybe there is a cleverer approach to my problem.

Offline

#4 2021-09-28 12:23:37

Kerosin
Member
Registered: 2021-09-28
Posts: 5

Re: different kernel version loading

Scimmia wrote:

Sharing the same boot dir? No, not without using a totally separate kernel package. You would need to mount sda1 elsewhere, then bind mount a separate dir to /boot for each OS.

Thanks, I will also try out this method.

Offline

#5 2021-10-01 06:45:29

Kerosin
Member
Registered: 2021-09-28
Posts: 5

Re: different kernel version loading

Scimmia wrote:

Sharing the same boot dir? No, not without using a totally separate kernel package. You would need to mount sda1 elsewhere, then bind mount a separate dir to /boot for each OS.

Hello again, so now I understand what you meant, and what your method aimed to.

When updating linux package, OS runs command "-k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux.img" (mkinicpio -p linux). As I understand, in brief, this command copies kernal elf (with defaul name vmlinuz-linux), (downloaded via pacman), generates new initramfs and replaces coressponding files in /boot.
I am not sure whether it is so, because in mkinicpio.d/linux-preset we have:

  3 ALL_config="/etc/mkinitcpio.conf"
  4 ALL_kver="/boot/vmlinuz-linux"
  5 
  6 PRESETS=('default' 'fallback')
  7 
  8 #default_config="/etc/mkinitcpio.conf"
  9 default_image="/boot/initramfs-linux.img"

so here is an obvious name for an output initramfs on line 9, and as it seems default kernel elf on line 4, based on which all will be generated.

The question is.. in case not using separate /boot folder, is it possible to copy kernel elf to /boot with a custom name? then It seems that in this case
4 ALL_kver="/boot/vmlinuz-linux"
can be changed to vmlinuz_custom_name to have the desired effect (to have a separate kernel and initrams in the same folder)

Offline

#6 2021-10-01 15:25:25

loqs
Member
Registered: 2014-03-06
Posts: 18,994

Re: different kernel version loading

You would have to customize /usr/share/libalpm/scripts/mkinitcpio-install but those changes would be overwritten when mkinitcpio is updated instead override /usr/share/libalpm/hooks/90-mkinitcpio-install.hook with /etc/pacman.d/hooks/90-mkinitcpio-install.hook that uses a different script file.
You would be changing the script file so that the kernel and mkinitcpio preset have different names.

Offline

#7 2021-10-27 14:10:45

Kerosin
Member
Registered: 2021-09-28
Posts: 5

Re: different kernel version loading

loqs wrote:

You would have to customize /usr/share/libalpm/scripts/mkinitcpio-install but those changes would be overwritten when mkinitcpio is updated instead override /usr/share/libalpm/hooks/90-mkinitcpio-install.hook with /etc/pacman.d/hooks/90-mkinitcpio-install.hook that uses a different script file.
You would be changing the script file so that the kernel and mkinitcpio preset have different names.

Hello, sorry I was on vacation and did not answer.
I did not get your approach.. there is not etc/pacman.d/hooks/90-mkinitcpio-install.hook file.. and /usr/share/libalpm/hooks/90-mkinitcpio-install.hook seems to contain no relevant field about kernel output file name.
Could you explain to me more clearly how to do what you meant?

Offline

#8 2021-10-27 23:28:32

loqs
Member
Registered: 2014-03-06
Posts: 18,994

Re: different kernel version loading

/usr/share/libalpm/hooks/90-mkinitcpio-install.hook used the script /usr/share/libalpm/scripts/mkinitcpio-install which does decide the kernel name.
I mention /usr/share/libalpm/hooks/90-mkinitcpio-install.hook because to ensure your changes are not overwritten on package upgrade you would create /etc/pacman.d/hooks/90-mkinitcpio-install.hook based on /usr/share/libalpm/hooks/90-mkinitcpio-install.hook but calling a script based on /usr/share/libalpm/scripts/mkinitcpio-install but modified with the changes you want.

/usr/share/libalpm/scripts/mkinitcpio-install

#!/bin/bash -e

args=()
all=0

while read -r line; do
    if [[ $line != */vmlinuz ]]; then
        # triggers when it's a change to usr/lib/initcpio/*
        all=1
        continue
    fi

    if ! read -r pkgbase > /dev/null 2>&1 < "${line%/vmlinuz}/pkgbase"; then
        # if the kernel has no pkgbase, we skip it
        continue
    fi

    preset="/etc/mkinitcpio.d/${pkgbase}.preset"
    if [[ ! -e $preset ]]; then
        if [[ -e $preset.pacsave ]]; then
            # move the pacsave to the template
            mv "${preset}.pacsave" "$preset"
        else
            # create the preset from the template
            sed "s|%PKGBASE%|${pkgbase}|g" /usr/share/mkinitcpio/hook.preset \
                | install -Dm644 /dev/stdin "$preset"
        fi
    fi

    # always install the kernel
    install -Dm644 "${line}" "/boot/vmlinuz-${pkgbase}"

    # compound args for each kernel
    args+=(-p "${pkgbase}")
done

if (( all )) && compgen -G /etc/mkinitcpio.d/"*.preset" > /dev/null; then
    # change to use all presets
    args=(-P)
fi

if (( ${#args[@]} )); then
    mkinitcpio "${args[@]}"
fi

$pkgbase read from usr/lib/modules/*/pkgbase holds the value of the kernel name to used as part of the kernel images filename and mkinitcpio preset name.

Offline

Board footer

Powered by FluxBB