site  contact  subhomenews

Select alternative kernel version

October 26, 2026 — BarryK

EasyOS is now being built with the 7.2.x kernel; however, some people might prefer an older kernel. There is now a mechanism to switch kernels.

I have created 'linux-kernel_6.12.109_amd64.sfs', that SFSget will be able to download and install. It will install to the main filesystem only, not in a container. After install, reboot, and the 6.12.109 kernel will be automatically used. Ditto, in the BootManager, untick it (uninstall) and at next bootup there will be an automatic revert to the default kernel.

There is a new script in the initrd, /inc/05kernel-change:

#!/bin/sh
#if a "linux-kernel" sfs is to be loaded, switch to use its kernel.

#find vmlinuz have booted from...
#if BOOT_* passed on kernel cmdline and vmlinuz there...
if [ -n "$BOOT_DEV" ];then
mkdir -p /mnt/${BOOT_DEV}
if [ ! -f /mnt/${BOOT_DEV}/${BOOT_DIR}vmlinuz ];then
mount -t ${BOOT_FS} /dev/${BOOT_DEV} /mnt/${BOOT_DEV}
fi
VM_DEV="${BOOT_DEV}"; VM_DIR="${BOOT_DIR}"
else
VM_DEV="${WKG_DEV}"; VM_DIR="${WKG_DIR}"
fi
if [ ! -f /mnt/${VM_DEV}/${VM_DIR}vmlinuz ];then
err_exit_func "${Lm}${LINENO} Failed to find vmlinuz"
fi

#find linux-kernel sfs...
LK="$(grep '^EASY_LAYER_RO.*linux-kernel' /mnt/${WKG_DEV}/${WKG_DIR}releases/easy-${INIT_DISTRO_VERSION}/configuration)"

KV2="$(uname -r)"
if [ -z "$LK" ];then
#make sure boot default kernel...
KV1="$(strings /mnt/${WKG_DEV}/${WKG_DIR}releases/easy-${INIT_DISTRO_VERSION}/vmlinuz | grep -E '^[0-9]+\.[0-9]+\.[0-9]+' | cut -f 1 -d ' ')"
if [ "${KV1}" != "${KV2}" ];then
#restore default kernel...
cp -f /mnt/${WKG_DEV}/${WKG_DIR}releases/easy-${INIT_DISTRO_VERSION}/vmlinuz /mnt/${VM_DEV}/${VM_DIR}
sync
#reboot...
echo -e "\\033[1;31m ${S560:-Kernel version change:} ${KV2} ${KV1}\\033[0;39m" #red.
echo -e "\\033[1;31m ${S503:-Counting down to restart...}\\033[0;39m" #red.
KPARAMS="$(cat /proc/cmdline)"
countdown_func 10
/bin/kexec --load /mnt/${VM_DEV}/${VM_DIR}vmlinuz --initrd=/mnt/${VM_DEV}/${VM_DIR}initrd --command-line="${KPARAMS}"
/bin/kexec -e
fi
else
#read the kernel version in sfs...
#full readlink...
#note, if broken link, later code will delete it...
readlink -q -e /mnt/${WKG_DEV}/${WKG_DIR}releases/easy-${INIT_DISTRO_VERSION}/linux-kernel.sfs
if [ $? -eq 0 ];then
K3="$(readlink -e /mnt/${WKG_DEV}/${WKG_DIR}releases/easy-${INIT_DISTRO_VERSION}/linux-kernel.sfs)"
KV3="$(echo -n "${K3}" | -cut -f 2 -d '_')"
if [ "${KV2}" != "${KV3}" ];then
#extract vmlinuz out of the sfs...
mkdir -p /mnt/sfs
mount -t squashfs ${K3} /mnt/sfs
cp -f /mnt/sfs/boot/vmlinuz /mnt/${VM_DEV}/${VM_DIR}
sync
umount /mnt/sfs
#reboot...
echo -e "\\033[1;31m ${S560:-Kernel version change:} ${KV2} ${KV3}\\033[0;39m" #red.
echo -e "\\033[1;31m ${S503:-Counting down to restart...}\\033[0;39m" #red.
KPARAMS="$(cat /proc/cmdline)"
countdown_func 10
/bin/kexec --load /mnt/${VM_DEV}/${VM_DIR}vmlinuz --initrd=/mnt/${VM_DEV}/${VM_DIR}initrd --command-line="${KPARAMS}"
/bin/kexec -e
fi
fi
fi

The logic seems OK, yet to be tested.   

Tags: easy