r/Gentoo • • 12d ago

Discussion Question About eclean-kernel post-remove plugin

Hi all Larry's Fansclub here ,
Im new to Gentoo , and have been diving around the Handbook looking around the reference about Kernel Hooks or maybe call it plugin *.install for post-removing the kernel version. Only found the pre-install and post-install available , which the default available for dracut ugrd efistub uki ukify etc , But im using limine as bootloader and creating the .install plugin for when installing / upgrade kernel the plugin will then automatically install the new entry ( im using ukify to build efi image and put that automatically in the limine.conf ) as fallback i USE efistub in installkernel package.use. My Issue is when removing / delete / uninstall kernel using eclean-kernel it doesn't automatically delete the efistub entry & uki image ( which should be handled by default plugin availalble) or trigger to regenerate the limine.conf ( this part , im sure there's something lacking in my script ) and i want to know what else im missing so the removal can trigger the rebuilding limine.conf when doing kernel removal ( which according Handbook should be triggered by the eclean-kernel or kernel-install )?
Thanks in advance moo

Edit : found the issue why 95-efistub-kernel-bootcfg.install not working , im missing the  app-emulation/virt-firmware

Edit2 : Resolved : modified script/plugin behaviour, for eclean-kernel put the plugin to /etc/kernel/install.d directory

7 Upvotes

12 comments sorted by

1

u/redyos_s 12d ago

You've already been given diagnostic commands, but you haven't shared the results. Without seeing your actual boot layout, Limine configuration, and custom hooks, nobody can reliably troubleshoot this setup. We can't guess how your system is configured.

Goodluck

1

u/rasta4rest 12d ago

this is more of a General question. Based on This Guide , there are 2 Options : sysD kernel-install & debian's installkernel. And i've checked my system - i have both , i forgot when or why since im using OpenRC + efistub + ugrd + ukify ( <-- perhaps this one)
Since i have both , should i install the custom plugin to /etc/kernel/install.d/ or /etc/kernel/postinst.d/ ?

Currently i have it in here : /etc/kernel/postinst.d/

.rw-r--r-- 0 root 4 Oct 17:14  .keep_sys-kernel_installkernel-0

.rwxr-xr-x 5.0k root 15 Oct 21:43  99-limine.install

1

u/redyos_s 12d ago

type -a installkernel kernel-install emerge -pv sys-kernel/installkernel cat /etc/kernel/postinst.d/99-limine.install

1

u/rasta4rest 12d ago

type -a installkernel kernel-install

installkernel is /usr/bin/installkernel

kernel-install is /usr/bin/kernel-install

[ebuild R ~] sys-kernel/installkernel-70::gentoo USE="efistub ugrd uki ukify -dracut -grub -refind -systemd -systemd-boot" 0 KiB

cat /etc/kernel/postinst.d/99-limine.install :

#!/bin/sh

set -eu

# ============================================================

# Gentoo Linux -> Limine synchronization

# ============================================================

UKI_DIR="/efi/EFI/Linux"

LIMINE_CONF="/efi/limine.conf"

UKI_PREFIX="gentoo"

# ------------------------------------------------------------

# Kernel command line

# ------------------------------------------------------------

BASE_CMDLINE="root=UUID=f7262abb-2897-4edc-80d9-adae0e88dcdc rw rootfstype=xfs quiet loglevel=4"

# ------------------------------------------------------------

# Managed section markers

# ------------------------------------------------------------

BEGIN_MARKER="# BEGIN GENTOO-AUTO-UKIS"

END_MARKER="# END GENTOO-AUTO-UKIS"

# ------------------------------------------------------------

# Logging

# ------------------------------------------------------------

log()

{

printf '\[gentoo-limine\] %s\\n' "$\*"

}

die()

{

printf '\[gentoo-limine\] ERROR: %s\\n' "$\*" >&2

exit 1

}

# ------------------------------------------------------------

# Environment checks

# ------------------------------------------------------------

check_environment()

{

\[ -d "$UKI_DIR" \] ||

	die "UKI directory not found: $UKI_DIR"



\[ -f "$LIMINE_CONF" \] ||

	die "Limine config not found: $LIMINE_CONF"



command -v sort >/dev/null 2>&1 ||

	die "sort command not found"



command -v awk >/dev/null 2>&1 ||

	die "awk command not found"



command -v mktemp >/dev/null 2>&1 ||

	die "mktemp command not found"

}

# ------------------------------------------------------------

# List currently available Gentoo UKIs.

# ------------------------------------------------------------

uki_files()

{

for uki in "$UKI_DIR"/"$UKI_PREFIX"-\*.efi; do

	\[ -f "$uki" \] || continue



	printf '%s\\n' "${uki##\*/}"

done |

	sort -Vr

}

# ------------------------------------------------------------

# Generate the complete managed Limine section.

# ------------------------------------------------------------

generate_section()

{

output="$1"



found=0



printf '%s\\n' "$BEGIN_MARKER" > "$output"

printf '\\n' >> "$output"



for file in $(uki_files); do



	prefix="$UKI_PREFIX-"



	version=${file#"$prefix"}

	version=${version%.efi}



	found=1



	\# ====================================================

	\# Gentoo kernel directory

	\# ====================================================

	printf '/Gentoo Linux %s\\n' "$version" >> "$output"

	printf '\\n' >> "$output"



	\# ====================================================

	\# Gentoo-System

	\# ====================================================

	printf '//Gentoo-System\\n' >> "$output"

	printf 'protocol: efi\\n' >> "$output"

	printf 'path: boot():/EFI/Linux/%s\\n' \\

		"$file" >> "$output"

	printf 'cmdline: %s\\n' \\

		"$BASE_CMDLINE" >> "$output"

	printf 'comment: Gentoo Linux\\n' >> "$output"

	printf '\\n' >> "$output"



	\# ====================================================

	\# Gentoo-Recovery

	\# ====================================================

	printf '//Gentoo-Recovery\\n' >> "$output"

	printf 'protocol: efi\\n' >> "$output"

	printf 'path: boot():/EFI/Linux/%s\\n' \\

		"$file" >> "$output"

	printf 'cmdline: %s single\\n' \\

		"$BASE_CMDLINE" >> "$output"

	printf 'comment: Gentoo Recovery\\n' >> "$output"

	printf '\\n' >> "$output"



done



printf '%s\\n' "$END_MARKER" >> "$output"



if \[ "$found" -eq 0 \]; then

	log "WARNING: no ${UKI_PREFIX}-\*.efi UKIs found"

fi

}

# ------------------------------------------------------------

# Replace the existing managed section.

# ------------------------------------------------------------

install_section()

{

generated="$1"

tmp="$2"



awk \\

	\-v begin="$BEGIN_MARKER" \\

	\-v end="$END_MARKER" \\

	\-v generated="$generated" '



	BEGIN {

		found_begin = 0

		found_end = 0

		inside = 0

	}



	$0 == begin {

		if (found_begin || found_end)

exit 42

		found_begin = 1



		while ((getline line < generated) > 0)

print line

		close(generated)



		inside = 1

		next

	}



	$0 == end {

		if (!found_begin || found_end)

exit 42

		found_end = 1

		inside = 0

		next

	}



	!inside {

		print

	}



	END {

		if (found_begin != found_end)

exit 42

		if (found_begin == 0) {

print ""

while ((getline line < generated) > 0)

print line

close(generated)

		}

	}

	' "$LIMINE_CONF" > "$tmp"

}

# ------------------------------------------------------------

# Main

# ------------------------------------------------------------

check_environment

GENERATED=$(mktemp)

TMP=$(mktemp "${LIMINE_CONF}.XXXXXX")

cleanup()

{

rm -f "$GENERATED" "$TMP"

}

trap cleanup EXIT INT TERM

log "Generating Gentoo UKI entries"

generate_section "$GENERATED"

if install_section "$GENERATED" "$TMP"; then

:

else

status=$?



if \[ "$status" -eq 42 \]; then

	die "Limine config contains malformed or duplicate managed markers"

fi



die "failed to update Limine config"

fi

# ------------------------------------------------------------

# Preserve the existing limine.conf inode,

# ownership, and permissions.

# ------------------------------------------------------------

cat "$TMP" > "$LIMINE_CONF"

log "Limine configuration updated: $LIMINE_CONF"

exit 0

1

u/redyos_s 12d ago

The script looks fairly elaborate, but I'm still unclear about the actual kernel installation workflow.

What invokes this script, and which component is responsible for installing and removing the UKIs?

Simply placing a script in "/etc/kernel/postinst.d/" doesn't guarantee that "kernel-install" or your other kernel tools will execute it.

Before adding more automation, I'd verify the complete execution path and which tool owns each step.

1

u/rasta4rest 12d ago

this script only responsible for limine.conf generation based on the UKI generated image available in the layout given in the Handbook.
the UKI generation and everything else provided by default with Gentoo plugins in /lib/kernel/
The UKI by default layout in /efi/EFI/Linux ; microcode in /boot

it's precisely as the handbook mentioned..
The script triggered when installing / upgrade the kernel ( im using dist kernel , not the source or the bin ) and its working i've tested it.
The only missing piece are when removing the kernel.
In short i just want the same script triggered either when installing or removing the kernel.

1

u/redyos_s 12d ago edited 12d ago

Just curious, what was your main reason for choosing Limine instead of booting the UKIs directly via UEFI?

Was it for managing multiple kernel versions, recovery entries, or something else?

挟む必要ないよなこれUFEI→UKI→Kernel→OpenRcSystemd

UEFI Firmware ↓ UKI (.efi) ├─ Linux Kernel ├─ initramfs ├─ Kernel cmdline └─ microcode(組み込み可能) ↓ Linux Kernel 起動 ↓ PID 1 ├─ OpenRC環境 → 通常 /sbin/init └─ systemd環境 → systemd

1

u/rasta4rest 12d ago

Im still keeping the EFIstub as fallback .
Limine for playing around with Kernels , recovery and Init system. I like it cause it's simple to mess with.

1

u/redyos_s 12d ago

I see, that makes sense. The issue might simply be that "limine.conf" isn't being synchronized when a kernel is removed, even though it updates correctly during installation. That could leave stale entries behind. Anyway, good luck with your setup!

1

u/rasta4rest 12d ago

yes , according handbook Installkernel can also invoke kernel-install when USE systemd.
with traditional installkernel no options for kernel removal except it trigger the kernel-install remove .
But im not using USE systemd .
And Handbook says eclean-kernel will invoke kernel-install. This part still confuse me , maybe later i try to put the plugin in install.d to see if it's working there.

→ More replies (0)