Loading Kernels w/wo ZFS.KO? Customizing Loader?

A simple Question haunts Me:
Standard Installation of FreeBSD 14.2 with Root on ZFS (on a Single Disk) uses a Regular BootLoader «/boot/loader_lua» (zfsloader & loader are actually Hard Links to the same File). Its operability is Proved by the fact that when you Change the Menu Item in "/boot/lua/menu.lua", these Changes will be displayed on the Next reboot — this is in order to remove the Question of which loader is running in the System under study. System has 2+ Kernels:
1. First with Integrated ZFS («options ZFS», WITHOUT_MODULES+="crypto cryptodev aesni opensolaris zfs", No «/boot/${kernel}/zfs.ko» File provided)
2. and other is GENERIC, that Needs This ↑ Modules to Boot.
After Install «/boot/loader.conf» looks like Default:
PHP:
security.bsd.allow_destructive_dtrace=0
kern.geom.label.disk_ident.enable="0"
kern.geom.label.gptid.enable="0"
cryptodev_load="YES"
zfs_load="YES"
When loading the First Kernel (Kernel_ZFS), Errors are thrown: Loading configured Modules... «can't find 'cryptodev'»/«can't find 'zfs'». If build with ZFS.KO & CryptoDev.KO, However, They will be loaded without Errors, but They are not needed because They are already compiled into the Kernel (kldstat does not show them). This is Not Critical, but Is Wrong. When loading the GENERIC Kernel, EveryThing is Fine, because the configuration file «/boot/loader.conf» is designed specifically for It.
So, the Question is How do I Instruct the Loader not to Try to Load «ZFS.KO» if It is Not Present in the Selected from Menu Kernel?
I am Not going to Сhange the Regular Files from the Standard Distribution Package, as this is associated with a number of Problems in the Future.
Files «/boot/loader.conf.d/*.conf» are Processed by Loader_Lua, but Files «/boot/loader.conf.d/*.lua» are Ignored, so I Try to Put there two Files:
«/boot/loader.conf.d/Custom.conf»
PHP:
#cryptodev_load="No"    # With This Lines GENERIC does Not Boot!
#zfs_load="No"          # With This Lines GENERIC does Not Boot!
dofile("/boot/loader.conf.d/Custom.lua")
and «/boot/loader.conf.d/Custom.lua»
PHP:
loader.setenv("cryptodev_load", "NO")
loader.setenv("zfs_load", "NO")
loader.setenv("speaker_load", "Yes")    -- Just for Test with «kldstat» after Booting…
--loader.prompt()        -- This Causes Error!
It seems, They Do Not Work at All, or Execute Before «*_load» Variables are Initialized…
If I Choose «GENERIC Kernel», than Press «Escape» During Menu CountDown, I See:
PHP:
Type '?' for a list of Commands, 'help' for more detalied Help.
OK echo "${kernel}" "${cryptodev_load}" "${zfs_load}" "${speaker_load}" "${loader_delay}" "${autoboot_delay}"
kernel YES YES 4 NO                            ← "${kernel}" Must Be «kernel.GENERIC» Here!
OK dofile("/boot/loader.conf.d/Custom.lua")    ← Try to Call in «InterActive Mode» & got No Errors Here.
OK echo "${kernel}" "${cryptodev_load}" "${zfs_load}" "${speaker_load}" "${loader_delay}" "${autoboot_delay}"
kernel NO NO Yes 4 NO                          ← "${kernel}" still Must Be «kernel.GENERIC» Here!
OK autoboot
Loading kernel...
/boot/kernel.GENERIC/kernel    text=0x…        ← The Kernel, Choosen from Menu before, not from "${kernel}" Variable?
Loading configured modules...
/boot/kernel.GENERIC/cryptodev.ko    text=0x…  ← With All Modules, DisAbled by My Lua-Script?
/boot/kernel.GENERIC/zfs.ko    text=0x…        ← and WithOut EnAbled «speaker_load»? WTF?
/etc/hostid size=0x25
/boot/entropy size=0x1000
Hit [Enter] to boot immediately, or any other Key for Command Prompt.
Booting [/boot/lernel.GENERIC/kernel] in 3 Seconds...
 
Later I Tried to Inject some Hooks to Catch Events in Lua-Code with «/boot/loader.conf.d/Custom.lua»:
PHP:
--local core = require("core")          ← Not Sure, It is Needed?
local hook = require("hook")
--local loader = require("loader")      ← Not Sure, It is Needed?

hook.register("config.loaded", function()
    print("Custom Hook: config.loaded")
    loader.setenv("cryptodev_load", "NO")
    loader.setenv("zfs_load", "NO")
    loader.setenv("speaker_load", "YES")
end)

hook.register("config.reloaded", function()
    print("Custom Hook: config.reloaded")
    loader.setenv("cryptodev_load", "NO")
    loader.setenv("zfs_load", "NO")
    loader.setenv("speaker_load", "YES")
end)

hook.register("kernel.loaded", function()
    print("Custom Hook: kernel.loaded")
    loader.setenv("cryptodev_load", "NO")
    loader.setenv("zfs_load", "NO")
    loader.setenv("speaker_load", "YES")
end)
But This does Not Work too…
 
Back
Top