Bug 292232 - loader: kernels_autodetect fails on initial load
Summary: loader: kernels_autodetect fails on initial load
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Kyle Evans
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-01-06 23:02 UTC by Lexi Winter
Modified: 2026-01-20 04:21 UTC (History)
1 user (show)

See Also:
kevans: mfc-stable15+
kevans: mfc-stable14+
kevans: mfc-stable13-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lexi Winter freebsd_committer freebsd_triage 2026-01-06 23:02:40 UTC
on a newly installed amd64 system with some local installer/packaging patches:

+ /boot/kernel doesn't exist
+ /boot/kernel.GENERIC contains a kernel
+ no other kernels are installed
+ loader.conf is an empty file

when the loader starts, the beastie menu correctly autodetects "kernel.GENERIC" and the menu shows "Kernel: 6. kernel.GENERIC (1 of 1)", but pressing "1" to boot does not work (nothing happens).

dropping to the loader prompt and running "boot" by hand indicates it's trying to boot /boot/kernel/kernel, not /boot/kernel.GENERIC/kernel.

if i press 6 to change the kernel (which doesn't do anything, since there's only one kernel available), pressing "1" to boot then works correctly.

it seems like something isn't being initialised properly until the user manually switches the kernel at least once.
Comment 1 Kyle Evans freebsd_committer freebsd_triage 2026-01-07 02:20:29 UTC
Wild ass guess, the oversight is probably this (not even remotely tested)

diff --git a/stand/lua/core.lua b/stand/lua/core.lua
index ad417e5f97e5..a006a3d5da26 100644
--- a/stand/lua/core.lua
+++ b/stand/lua/core.lua
@@ -289,6 +289,8 @@ function core.kernelList()
                                kernels[n] = kernels[n + 1]
                        end
                end
+
+               loader.setenv("kernel", kernels[1])
        end
 
        core.cached_kernels = kernels
Comment 2 Lexi Winter freebsd_committer freebsd_triage 2026-01-07 02:56:56 UTC
this does seem to fix the problem, now it boots correctly.  thanks!
Comment 3 commit-hook freebsd_committer freebsd_triage 2026-01-07 18:25:14 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e30086ab4c8778ea70a3b19e83546ce1b4a16492

commit e30086ab4c8778ea70a3b19e83546ce1b4a16492
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2026-01-07 18:20:05 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-01-07 18:20:05 +0000

    lualoader: fix pruning of non-existent default kernel

    Removing the kernel from the list of available kernels is sufficient to
    avoid rendering it in the list, but we need more for booting to actually
    work.  Notably, the 'kernel' loader.conf var was left intact to its
    default value, so if one didn't use the kernel selector in the menu then
    we'd try to boot the nonexistent 'kernel' instead of the new default
    (first autodetected).

    There's room to improve the error messages here, but for now let's just
    make it actually work correctly.

    PR:             292232
    Fixes:  d04415c520b03 ("loader: lua: remove the default kernel [...]")

 stand/lua/core.lua | 6 ++++++
 1 file changed, 6 insertions(+)
Comment 4 commit-hook freebsd_committer freebsd_triage 2026-01-20 04:10:19 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=6dabfd3efefaeb2bc24b8f16e1c5aae8dedc4d0c

commit 6dabfd3efefaeb2bc24b8f16e1c5aae8dedc4d0c
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2026-01-07 18:20:05 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-01-20 04:04:46 +0000

    lualoader: fix pruning of non-existent default kernel

    Removing the kernel from the list of available kernels is sufficient to
    avoid rendering it in the list, but we need more for booting to actually
    work.  Notably, the 'kernel' loader.conf var was left intact to its
    default value, so if one didn't use the kernel selector in the menu then
    we'd try to boot the nonexistent 'kernel' instead of the new default
    (first autodetected).

    There's room to improve the error messages here, but for now let's just
    make it actually work correctly.

    PR:             292232
    Fixes:  d04415c520b03 ("loader: lua: remove the default kernel [...]")
    (cherry picked from commit e30086ab4c8778ea70a3b19e83546ce1b4a16492)

 stand/lua/core.lua | 6 ++++++
 1 file changed, 6 insertions(+)
Comment 5 commit-hook freebsd_committer freebsd_triage 2026-01-20 04:10:23 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=4f0342cf84dbe4fadbfea02e3279aafab36ea848

commit 4f0342cf84dbe4fadbfea02e3279aafab36ea848
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2026-01-07 18:20:05 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-01-20 04:08:11 +0000

    lualoader: fix pruning of non-existent default kernel

    Removing the kernel from the list of available kernels is sufficient to
    avoid rendering it in the list, but we need more for booting to actually
    work.  Notably, the 'kernel' loader.conf var was left intact to its
    default value, so if one didn't use the kernel selector in the menu then
    we'd try to boot the nonexistent 'kernel' instead of the new default
    (first autodetected).

    There's room to improve the error messages here, but for now let's just
    make it actually work correctly.

    PR:             292232
    Fixes:  d04415c520b03 ("loader: lua: remove the default kernel [...]")
    (cherry picked from commit e30086ab4c8778ea70a3b19e83546ce1b4a16492)

 stand/lua/core.lua | 6 ++++++
 1 file changed, 6 insertions(+)