diff options
| author | Kyle Evans <kevans@FreeBSD.org> | 2026-06-04 13:57:16 +0000 |
|---|---|---|
| committer | Kyle Evans <kevans@FreeBSD.org> | 2026-06-10 04:00:49 +0000 |
| commit | bddfcbd9bbc68fe11ce53954b7f82584cd5ee40b (patch) | |
| tree | b5c977bb4b6d3dfb2e55a09992c677a219686fc2 /stand/lua/core.lua | |
| parent | f25b4d986c949b3e0c0e20fe5cbcc42f0f004243 (diff) | |
lualoader: add be-list and be-switch commands
This is useful for driving BE changes from the loader command prompt,
rather than having to use the menu. Note that the active carousel in
the boot environment carousel doesn't currently reflect a switch in
boot environments done this way- I'm considering this only a minor bug,
as you probably can't or won't go back to the menu if you're using these
commands.
Reviewed by: imp (previous version)
(cherry picked from commit c7ff706b31c22f10c2403869c46b443448da3e08)
Diffstat (limited to 'stand/lua/core.lua')
| -rw-r--r-- | stand/lua/core.lua | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/stand/lua/core.lua b/stand/lua/core.lua index 4091f446e1f1..16825d560094 100644 --- a/stand/lua/core.lua +++ b/stand/lua/core.lua @@ -312,6 +312,21 @@ function core.bootenvFilter(func) return oldf end +function core.bootenvIter() + local envs = core.bootenvList() + + if #envs ~= 0 then + local root = "zfs:" .. loader.getenv("zfs_be_root") .. "/" + + for idx, bespec in ipairs(envs) do + bespec = bespec:gsub("^" .. root, "") + envs[idx] = bespec + end + end + + return next, envs, nil +end + function core.bootenvList() local bootenv_count = tonumber(loader.getenv(bootenv_list .. "_count")) local bootenvs = {} @@ -565,6 +580,34 @@ function core.nextConsoleChoice() end end +function core.switchBE(env) + -- This branch will most likely be taken by the switch-be CLI command, + -- not by the menu. We could do some more validation that it's a valid + -- BE and let the user fully specify a zfs:be/dataset to avoid the + -- validation, but this isn't done at the moment. + if not env:match("^zfs:") then + local root = loader.getenv("zfs_be_root") + + if not root then + print("ZFS BE root not available -- no action taken") + return + end + + if not env:match("^" .. root) then + env = "zfs:" .. root .. "/" .. env + else + env = "zfs:" .. env + end + end + + loader.setenv("vfs.root.mountfrom", env) + loader.setenv("currdev", env .. ":") + config.reload() + if loader.getenv("kernelname") ~= nil then + loader.perform("unload") + end +end + -- The graphical-enabled loaders have unicode drawing character support. The -- text-only ones do not. We check the old and new bindings for term_drawrect as -- a proxy for unicode support, which will work on older boot loaders as well |
