aboutsummaryrefslogtreecommitdiff
path: root/stand/lua/core.lua
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2026-06-04 13:57:16 +0000
committerKyle Evans <kevans@FreeBSD.org>2026-06-10 04:00:39 +0000
commitf77062f506f7bc752316da35e8d7da9a1ddb0d91 (patch)
treed65ff012b9a663c2c74f0b0d24ae1f3d79bf2b07 /stand/lua/core.lua
parent76720b010873f350b94231c5380e2d19b8839795 (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.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/stand/lua/core.lua b/stand/lua/core.lua
index c276f61e5904..687376cbc40f 100644
--- a/stand/lua/core.lua
+++ b/stand/lua/core.lua
@@ -314,6 +314,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 = {}
@@ -567,6 +582,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