xref: /freebsd/stand/man/loader_lua.8 (revision 9aa29457d55e4c9c4eac72785886eff756fef22c)
19e1dc7beSWarner Losh.\" Copyright (c) 1999 Daniel C. Sobral
29e1dc7beSWarner Losh.\" All rights reserved.
39e1dc7beSWarner Losh.\"
49e1dc7beSWarner Losh.\" Redistribution and use in source and binary forms, with or without
59e1dc7beSWarner Losh.\" modification, are permitted provided that the following conditions
69e1dc7beSWarner Losh.\" are met:
79e1dc7beSWarner Losh.\" 1. Redistributions of source code must retain the above copyright
89e1dc7beSWarner Losh.\"    notice, this list of conditions and the following disclaimer.
99e1dc7beSWarner Losh.\" 2. Redistributions in binary form must reproduce the above copyright
109e1dc7beSWarner Losh.\"    notice, this list of conditions and the following disclaimer in the
119e1dc7beSWarner Losh.\"    documentation and/or other materials provided with the distribution.
129e1dc7beSWarner Losh.\"
139e1dc7beSWarner Losh.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
149e1dc7beSWarner Losh.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
159e1dc7beSWarner Losh.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
169e1dc7beSWarner Losh.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
179e1dc7beSWarner Losh.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
189e1dc7beSWarner Losh.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199e1dc7beSWarner Losh.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
209e1dc7beSWarner Losh.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
219e1dc7beSWarner Losh.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
229e1dc7beSWarner Losh.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
239e1dc7beSWarner Losh.\" SUCH DAMAGE.
249e1dc7beSWarner Losh.\"
259e1dc7beSWarner Losh.\" $FreeBSD$
269e1dc7beSWarner Losh.\"
279e1dc7beSWarner Losh.Dd September 29, 2021
289e1dc7beSWarner Losh.Dt LOADER_LUA 8
299e1dc7beSWarner Losh.Os
309e1dc7beSWarner Losh.Sh NAME
319e1dc7beSWarner Losh.Nm loader_lua
329e1dc7beSWarner Losh.Nd kernel bootstrapping final stage
339e1dc7beSWarner Losh.Sh DESCRIPTION
349e1dc7beSWarner LoshThe program called
359e1dc7beSWarner Losh.Nm
369e1dc7beSWarner Loshis the final stage of
379e1dc7beSWarner Losh.Fx Ns 's
389e1dc7beSWarner Loshkernel bootstrapping process.
399e1dc7beSWarner LoshOn IA32 (i386) architectures, it is a
409e1dc7beSWarner Losh.Pa BTX
419e1dc7beSWarner Loshclient.
429e1dc7beSWarner LoshIt is linked statically to
439e1dc7beSWarner Losh.Xr libstand 3
449e1dc7beSWarner Loshand usually located in the directory
459e1dc7beSWarner Losh.Pa /boot .
469e1dc7beSWarner Losh.Pp
479e1dc7beSWarner LoshIt provides a scripting language that can be used to
489e1dc7beSWarner Loshautomate tasks, do pre-configuration or assist in recovery
499e1dc7beSWarner Loshprocedures.
509e1dc7beSWarner LoshThis scripting language is roughly divided in
519e1dc7beSWarner Loshtwo main components.
529e1dc7beSWarner LoshThe smaller one is a set of commands
539e1dc7beSWarner Loshdesigned for direct use by the casual user, called "builtin
549e1dc7beSWarner Loshcommands" for historical reasons.
559e1dc7beSWarner LoshThe main drive behind these commands is user-friendliness.
569e1dc7beSWarner LoshThe bigger component is the Lua interpter.
579e1dc7beSWarner Losh.Pp
589e1dc7beSWarner LoshDuring initialization,
599e1dc7beSWarner Losh.Nm
609e1dc7beSWarner Loshwill probe for a console and set the
619e1dc7beSWarner Losh.Va console
629e1dc7beSWarner Loshvariable, or set it to serial console
639e1dc7beSWarner Losh.Pq Dq Li comconsole
649e1dc7beSWarner Loshif the previous boot stage used that.
659e1dc7beSWarner LoshIf multiple consoles are selected, they will be listed separated by spaces.
669e1dc7beSWarner LoshThen, devices are probed,
679e1dc7beSWarner Losh.Va currdev
689e1dc7beSWarner Loshand
699e1dc7beSWarner Losh.Va loaddev
709e1dc7beSWarner Loshare set, and
719e1dc7beSWarner Losh.Va LINES
729e1dc7beSWarner Loshis set to 24.
739e1dc7beSWarner LoshNext, Lua is initialized, and
749e1dc7beSWarner Losh.Pa /boot/lua/loader.lua
759e1dc7beSWarner Loshis processed if it exists.
769e1dc7beSWarner LoshAfter that,
779e1dc7beSWarner Losh.Pa /boot/loader.conf
789e1dc7beSWarner Loshis processed if available.
799e1dc7beSWarner Losh.Pp
809e1dc7beSWarner LoshAt this point, if an
819e1dc7beSWarner Losh.Ic autoboot
829e1dc7beSWarner Loshhas not been tried, and if
839e1dc7beSWarner Losh.Va autoboot_delay
849e1dc7beSWarner Loshis not set to
859e1dc7beSWarner Losh.Dq Li NO
869e1dc7beSWarner Losh(not case sensitive), then an
879e1dc7beSWarner Losh.Ic autoboot
889e1dc7beSWarner Loshwill be tried.
899e1dc7beSWarner LoshIf the system gets past this point,
909e1dc7beSWarner Losh.Va prompt
919e1dc7beSWarner Loshwill be set and
929e1dc7beSWarner Losh.Nm
939e1dc7beSWarner Loshwill engage interactive mode.
949e1dc7beSWarner LoshPlease note that historically even when
959e1dc7beSWarner Losh.Va autoboot_delay
969e1dc7beSWarner Loshis set to
979e1dc7beSWarner Losh.Dq Li 0
989e1dc7beSWarner Loshuser will be able to interrupt autoboot process by pressing some key
999e1dc7beSWarner Loshon the console while kernel and modules are being loaded.
1009e1dc7beSWarner LoshIn some
1019e1dc7beSWarner Loshcases such behaviour may be undesirable, to prevent it set
1029e1dc7beSWarner Losh.Va autoboot_delay
1039e1dc7beSWarner Loshto
1049e1dc7beSWarner Losh.Dq Li -1 ,
1059e1dc7beSWarner Loshin this case
1069e1dc7beSWarner Losh.Nm
1079e1dc7beSWarner Loshwill engage interactive mode only if
1089e1dc7beSWarner Losh.Ic autoboot
1099e1dc7beSWarner Loshhas failed.
1109e1dc7beSWarner Losh.Sh BUILTIN COMMANDS
1119e1dc7beSWarner LoshIn
1129e1dc7beSWarner Losh.Nm ,
1139e1dc7beSWarner Loshbuiltin commands take parameters from the command line.
1149e1dc7beSWarner LoshPresently,
1159e1dc7beSWarner Loshthe only way to call them from a script is by using
1169e1dc7beSWarner Losh.Pa evaluate
1179e1dc7beSWarner Loshon a string.
1189e1dc7beSWarner LoshIf an error condition occurs, an exception will be generated,
1199e1dc7beSWarner Loshwhich can be intercepted using Lua exception handling.
1209e1dc7beSWarner LoshIf not intercepted, an error message will be displayed and
1219e1dc7beSWarner Loshthe interpreter's state will be reset, emptying the stack and restoring
1229e1dc7beSWarner Loshinterpreting mode.
1239e1dc7beSWarner Losh.Pp
1249e1dc7beSWarner LoshThe commands are described in the
1259e1dc7beSWarner Losh.Xr loader_simp 8
1269e1dc7beSWarner Losh.Dq BUILTIN COMMANDS
1279e1dc7beSWarner Loshsection.
1289e1dc7beSWarner Losh.Ss BUILTIN ENVIRONMENT VARIABLES
1299e1dc7beSWarner LoshThe environment variables common to all interpreters are described in the
1309e1dc7beSWarner Losh.Xr loader_simp 8
1319e1dc7beSWarner Losh.Dq BUILTIN ENVIRONMENT VARIABLES
1329e1dc7beSWarner Loshsection.
1339e1dc7beSWarner Losh.Ss BUILTIN PARSER
1349e1dc7beSWarner LoshWhen a builtin command is executed, the rest of the line is taken
1359e1dc7beSWarner Loshby it as arguments, and it is processed by a special parser which
1369e1dc7beSWarner Loshis not used for regular Lua commands.
1379e1dc7beSWarner Losh.Sh SECURITY
1389e1dc7beSWarner LoshAccess to the
1399e1dc7beSWarner Losh.Nm
1409e1dc7beSWarner Loshcommand line provides several ways of compromising system security,
1419e1dc7beSWarner Loshincluding, but not limited to:
1429e1dc7beSWarner Losh.Pp
1439e1dc7beSWarner Losh.Bl -bullet
1449e1dc7beSWarner Losh.It
1459e1dc7beSWarner LoshBooting from removable storage, by setting the
1469e1dc7beSWarner Losh.Va currdev
1479e1dc7beSWarner Loshor
1489e1dc7beSWarner Losh.Va loaddev
1499e1dc7beSWarner Loshvariables
1509e1dc7beSWarner Losh.It
1519e1dc7beSWarner LoshExecuting binary of choice, by setting the
1529e1dc7beSWarner Losh.Va init_path
1539e1dc7beSWarner Loshor
1549e1dc7beSWarner Losh.Va init_script
1559e1dc7beSWarner Loshvariables
1569e1dc7beSWarner Losh.It
1579e1dc7beSWarner LoshOverriding ACPI DSDT to inject arbitrary code into the ACPI subsystem
1589e1dc7beSWarner Losh.El
1599e1dc7beSWarner Losh.Pp
1609e1dc7beSWarner LoshOne can prevent unauthorized access
1619e1dc7beSWarner Loshto the
1629e1dc7beSWarner Losh.Nm
1639e1dc7beSWarner Loshcommand line by setting the
1649e1dc7beSWarner Losh.Va password ,
1659e1dc7beSWarner Loshor setting
1669e1dc7beSWarner Losh.Va autoboot_delay
1679e1dc7beSWarner Loshto -1.
1689e1dc7beSWarner LoshSee
1699e1dc7beSWarner Losh.Xr loader.conf 5
1709e1dc7beSWarner Loshfor details.
1719e1dc7beSWarner LoshIn order for this to be effective, one should also configure the firmware
1729e1dc7beSWarner Losh(BIOS or UEFI) to prevent booting from unauthorized devices.
1739e1dc7beSWarner Losh.Sh MD
1749e1dc7beSWarner LoshMemory disk (MD) can be used when the
1759e1dc7beSWarner Losh.Nm
1769e1dc7beSWarner Loshwas compiled with
1779e1dc7beSWarner Losh.Va MD_IMAGE_SIZE .
1789e1dc7beSWarner LoshThe size of the memory disk is determined by
1799e1dc7beSWarner Losh.Va MD_IMAGE_SIZE .
1809e1dc7beSWarner LoshIf MD available, a file system can be embedded into the
1819e1dc7beSWarner Losh.Nm
1829e1dc7beSWarner Loshwith
1839e1dc7beSWarner Losh.Pa /sys/tools/embed_mfs.sh .
1849e1dc7beSWarner LoshThen, MD will be probed and be set to
1859e1dc7beSWarner Losh.Va currdev
1869e1dc7beSWarner Loshduring initialization.
1879e1dc7beSWarner Losh.Pp
1889e1dc7beSWarner LoshCurrently, MD is only supported in
1899e1dc7beSWarner Losh.Xr loader.efi 8 .
1909e1dc7beSWarner Losh.Sh FILES
1919e1dc7beSWarner Losh.Bl -tag -width /usr/share/examples/bootforth/ -compact
1929e1dc7beSWarner Losh.It Pa /boot/loader
1939e1dc7beSWarner Losh.Nm
1949e1dc7beSWarner Loshitself.
1959e1dc7beSWarner Losh.It Pa /boot/defaults/loader.conf
1969e1dc7beSWarner Losh.It Pa /boot/lua/loader.lua
1979e1dc7beSWarner LoshLoader init
1989e1dc7beSWarner Losh.It Pa /boot/loader.conf
1999e1dc7beSWarner Losh.It Pa /boot/loader.conf.local
2009e1dc7beSWarner Losh.Nm
2019e1dc7beSWarner Loshconfiguration files, as described in
2029e1dc7beSWarner Losh.Xr loader.conf 5 .
2039e1dc7beSWarner Losh.Sh EXAMPLES
2049e1dc7beSWarner LoshBoot in single user mode:
2059e1dc7beSWarner Losh.Pp
2069e1dc7beSWarner Losh.Dl boot -s
2079e1dc7beSWarner Losh.Pp
2089e1dc7beSWarner LoshLoad the kernel, a splash screen, and then autoboot in five seconds.
2099e1dc7beSWarner LoshNotice that a kernel must be loaded before any other
2109e1dc7beSWarner Losh.Ic load
2119e1dc7beSWarner Loshcommand is attempted.
2129e1dc7beSWarner Losh.Bd -literal -offset indent
2139e1dc7beSWarner Loshload kernel
2149e1dc7beSWarner Loshload splash_bmp
2159e1dc7beSWarner Loshload -t splash_image_data /boot/chuckrulez.bmp
2169e1dc7beSWarner Loshautoboot 5
2179e1dc7beSWarner Losh.Ed
2189e1dc7beSWarner Losh.Pp
2199e1dc7beSWarner LoshSet the disk unit of the root device to 2, and then boot.
2209e1dc7beSWarner LoshThis would be needed in a system with two IDE disks,
2219e1dc7beSWarner Loshwith the second IDE disk hardwired to ada2 instead of ada1.
2229e1dc7beSWarner Losh.Bd -literal -offset indent
2239e1dc7beSWarner Loshset root_disk_unit=2
2249e1dc7beSWarner Loshboot /boot/kernel/kernel
2259e1dc7beSWarner Losh.Ed
2269e1dc7beSWarner Losh.Pp
2279e1dc7beSWarner LoshSet the default device used for loading a kernel from a ZFS filesystem:
2289e1dc7beSWarner Losh.Bd -literal -offset indent
2299e1dc7beSWarner Loshset currdev=zfs:tank/ROOT/knowngood:
2309e1dc7beSWarner Losh.Ed
2319e1dc7beSWarner Losh.Pp
2329e1dc7beSWarner Losh.Sh ERRORS
2339e1dc7beSWarner LoshThe following values are thrown by
2349e1dc7beSWarner Losh.Nm :
2359e1dc7beSWarner Losh.Bl -tag -width XXXXX -offset indent
2369e1dc7beSWarner Losh.It 100
2379e1dc7beSWarner LoshAny type of error in the processing of a builtin.
2389e1dc7beSWarner Losh.It -1
2399e1dc7beSWarner Losh.Ic Abort
2409e1dc7beSWarner Loshexecuted.
2419e1dc7beSWarner Losh.It -2
2429e1dc7beSWarner Losh.Ic Abort"
2439e1dc7beSWarner Loshexecuted.
2449e1dc7beSWarner Losh.It -56
2459e1dc7beSWarner Losh.Ic Quit
2469e1dc7beSWarner Loshexecuted.
2479e1dc7beSWarner Losh.It -256
2489e1dc7beSWarner LoshOut of interpreting text.
2499e1dc7beSWarner Losh.It -257
2509e1dc7beSWarner LoshNeed more text to succeed -- will finish on next run.
2519e1dc7beSWarner Losh.It -258
2529e1dc7beSWarner Losh.Ic Bye
2539e1dc7beSWarner Loshexecuted.
2549e1dc7beSWarner Losh.It -259
2559e1dc7beSWarner LoshUnspecified error.
2569e1dc7beSWarner Losh.El
2579e1dc7beSWarner Losh.Sh SEE ALSO
2589e1dc7beSWarner Losh.Xr libstand 3 ,
2599e1dc7beSWarner Losh.Xr loader.conf 5 ,
2609e1dc7beSWarner Losh.Xr tuning 7 ,
2619e1dc7beSWarner Losh.Xr boot 8 ,
2629e1dc7beSWarner Losh.Xr btxld 8
2639e1dc7beSWarner Losh.Sh HISTORY
2649e1dc7beSWarner LoshThe
2659e1dc7beSWarner Losh.Nm
2669e1dc7beSWarner Loshfirst appeared in
267*9aa29457SWarner Losh.Fx 12.0 .
268