xref: /freebsd/stand/man/loader_lua.8 (revision 11f49259c88ed4c110eefe89fa3862ef419b4150)
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
43*11f49259SWarner Losh.Xr libsa 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.
5667f5810eSJens SchweikhardtThe bigger component is the Lua interpreter.
579e1dc7beSWarner Losh.Pp
589e1dc7beSWarner LoshDuring initialization,
599e1dc7beSWarner Losh.Nm
608e458a43SJens Schweikhardtprobes for a console and sets the
619e1dc7beSWarner Losh.Va console
628e458a43SJens Schweikhardtvariable, or sets it to serial console
639e1dc7beSWarner Losh.Pq Dq Li comconsole
649e1dc7beSWarner Loshif the previous boot stage used that.
6567f5810eSJens SchweikhardtIf multiple consoles are selected, they are 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
828e458a43SJens Schweikhardthas not been attempted, and if
839e1dc7beSWarner Losh.Va autoboot_delay
849e1dc7beSWarner Loshis not set to
859e1dc7beSWarner Losh.Dq Li NO
868e458a43SJens Schweikhardt(case insensitive), then an
879e1dc7beSWarner Losh.Ic autoboot
8867f5810eSJens Schweikhardtis attempted.
899e1dc7beSWarner LoshIf the system gets past this point,
909e1dc7beSWarner Losh.Va prompt
9167f5810eSJens Schweikhardtis set and
929e1dc7beSWarner Losh.Nm
9367f5810eSJens Schweikhardtenters interactive mode.
9467f5810eSJens SchweikhardtPlease note that, historically, even when
959e1dc7beSWarner Losh.Va autoboot_delay
969e1dc7beSWarner Loshis set to
9767f5810eSJens Schweikhardt.Dq Li 0 ,
9867f5810eSJens Schweikhardtthe user can interrupt the autoboot process by pressing a key
9967f5810eSJens Schweikhardton the console while the kernel and modules are being loaded.
10067f5810eSJens SchweikhardtTo prevent this set
1019e1dc7beSWarner Losh.Va autoboot_delay
1029e1dc7beSWarner Loshto
10367f5810eSJens Schweikhardt.Dq Li -1 .
10467f5810eSJens SchweikhardtIn this case
1059e1dc7beSWarner Losh.Nm
10667f5810eSJens Schweikhardtenters interactive mode only if
1079e1dc7beSWarner Losh.Ic autoboot
1089e1dc7beSWarner Loshhas failed.
1099e1dc7beSWarner Losh.Sh BUILTIN COMMANDS
1109e1dc7beSWarner LoshIn
1119e1dc7beSWarner Losh.Nm ,
1129e1dc7beSWarner Loshbuiltin commands take parameters from the command line.
1139e1dc7beSWarner LoshPresently,
1149e1dc7beSWarner Loshthe only way to call them from a script is by using
1159e1dc7beSWarner Losh.Pa evaluate
1169e1dc7beSWarner Loshon a string.
11767f5810eSJens SchweikhardtIf an error condition occurs, an exception is generated,
1189e1dc7beSWarner Loshwhich can be intercepted using Lua exception handling.
11967f5810eSJens SchweikhardtIf not intercepted, an error message is displayed and
12067f5810eSJens Schweikhardtthe interpreter's state is reset, emptying the stack and restoring
1219e1dc7beSWarner Loshinterpreting mode.
1229e1dc7beSWarner Losh.Pp
1239e1dc7beSWarner LoshThe commands are described in the
1249e1dc7beSWarner Losh.Xr loader_simp 8
1259e1dc7beSWarner Losh.Dq BUILTIN COMMANDS
1269e1dc7beSWarner Loshsection.
1279e1dc7beSWarner Losh.Ss BUILTIN ENVIRONMENT VARIABLES
1289e1dc7beSWarner LoshThe environment variables common to all interpreters are described in the
1299e1dc7beSWarner Losh.Xr loader_simp 8
1309e1dc7beSWarner Losh.Dq BUILTIN ENVIRONMENT VARIABLES
1319e1dc7beSWarner Loshsection.
1329e1dc7beSWarner Losh.Ss BUILTIN PARSER
1339e1dc7beSWarner LoshWhen a builtin command is executed, the rest of the line is taken
1348e458a43SJens Schweikhardtas arguments, and it is processed by a special parser which
1359e1dc7beSWarner Loshis not used for regular Lua commands.
1369e1dc7beSWarner Losh.Sh SECURITY
1379e1dc7beSWarner LoshAccess to the
1389e1dc7beSWarner Losh.Nm
1399e1dc7beSWarner Loshcommand line provides several ways of compromising system security,
1409e1dc7beSWarner Loshincluding, but not limited to:
1419e1dc7beSWarner Losh.Pp
1429e1dc7beSWarner Losh.Bl -bullet
1439e1dc7beSWarner Losh.It
1449e1dc7beSWarner LoshBooting from removable storage, by setting the
1459e1dc7beSWarner Losh.Va currdev
1469e1dc7beSWarner Loshor
1479e1dc7beSWarner Losh.Va loaddev
1489e1dc7beSWarner Loshvariables
1499e1dc7beSWarner Losh.It
1508e458a43SJens SchweikhardtExecuting a binary of choice, by setting the
1519e1dc7beSWarner Losh.Va init_path
1529e1dc7beSWarner Loshor
1539e1dc7beSWarner Losh.Va init_script
1549e1dc7beSWarner Loshvariables
1559e1dc7beSWarner Losh.It
1569e1dc7beSWarner LoshOverriding ACPI DSDT to inject arbitrary code into the ACPI subsystem
1579e1dc7beSWarner Losh.El
1589e1dc7beSWarner Losh.Pp
1599e1dc7beSWarner LoshOne can prevent unauthorized access
1609e1dc7beSWarner Loshto the
1619e1dc7beSWarner Losh.Nm
1629e1dc7beSWarner Loshcommand line by setting the
1639e1dc7beSWarner Losh.Va password ,
1649e1dc7beSWarner Loshor setting
1659e1dc7beSWarner Losh.Va autoboot_delay
1669e1dc7beSWarner Loshto -1.
1679e1dc7beSWarner LoshSee
1689e1dc7beSWarner Losh.Xr loader.conf 5
1699e1dc7beSWarner Loshfor details.
1709e1dc7beSWarner LoshIn order for this to be effective, one should also configure the firmware
1719e1dc7beSWarner Losh(BIOS or UEFI) to prevent booting from unauthorized devices.
1729e1dc7beSWarner Losh.Sh MD
1739e1dc7beSWarner LoshMemory disk (MD) can be used when the
1749e1dc7beSWarner Losh.Nm
1759e1dc7beSWarner Loshwas compiled with
1769e1dc7beSWarner Losh.Va MD_IMAGE_SIZE .
1779e1dc7beSWarner LoshThe size of the memory disk is determined by
1789e1dc7beSWarner Losh.Va MD_IMAGE_SIZE .
1799e1dc7beSWarner LoshIf MD available, a file system can be embedded into the
1809e1dc7beSWarner Losh.Nm
1819e1dc7beSWarner Loshwith
1829e1dc7beSWarner Losh.Pa /sys/tools/embed_mfs.sh .
1838e458a43SJens SchweikhardtThen, MD is probed and set to
1849e1dc7beSWarner Losh.Va currdev
1859e1dc7beSWarner Loshduring initialization.
1869e1dc7beSWarner Losh.Pp
1879e1dc7beSWarner LoshCurrently, MD is only supported in
1889e1dc7beSWarner Losh.Xr loader.efi 8 .
1899e1dc7beSWarner Losh.Sh FILES
1909e1dc7beSWarner Losh.Bl -tag -width /usr/share/examples/bootforth/ -compact
1919e1dc7beSWarner Losh.It Pa /boot/loader
1929e1dc7beSWarner Losh.Nm
1939e1dc7beSWarner Loshitself.
1949e1dc7beSWarner Losh.It Pa /boot/defaults/loader.conf
1959e1dc7beSWarner Losh.It Pa /boot/lua/loader.lua
1969e1dc7beSWarner LoshLoader init
1979e1dc7beSWarner Losh.It Pa /boot/loader.conf
1989e1dc7beSWarner Losh.It Pa /boot/loader.conf.local
1999e1dc7beSWarner Losh.Nm
2009e1dc7beSWarner Loshconfiguration files, as described in
2019e1dc7beSWarner Losh.Xr loader.conf 5 .
2029e1dc7beSWarner Losh.Sh EXAMPLES
2039e1dc7beSWarner LoshBoot in single user mode:
2049e1dc7beSWarner Losh.Pp
2059e1dc7beSWarner Losh.Dl boot -s
2069e1dc7beSWarner Losh.Pp
2079e1dc7beSWarner LoshLoad the kernel, a splash screen, and then autoboot in five seconds.
2089e1dc7beSWarner LoshNotice that a kernel must be loaded before any other
2099e1dc7beSWarner Losh.Ic load
2109e1dc7beSWarner Loshcommand is attempted.
2119e1dc7beSWarner Losh.Bd -literal -offset indent
2129e1dc7beSWarner Loshload kernel
2139e1dc7beSWarner Loshload splash_bmp
2149e1dc7beSWarner Loshload -t splash_image_data /boot/chuckrulez.bmp
2159e1dc7beSWarner Loshautoboot 5
2169e1dc7beSWarner Losh.Ed
2179e1dc7beSWarner Losh.Pp
2189e1dc7beSWarner LoshSet the disk unit of the root device to 2, and then boot.
2199e1dc7beSWarner LoshThis would be needed in a system with two IDE disks,
2209e1dc7beSWarner Loshwith the second IDE disk hardwired to ada2 instead of ada1.
2219e1dc7beSWarner Losh.Bd -literal -offset indent
2229e1dc7beSWarner Loshset root_disk_unit=2
2239e1dc7beSWarner Loshboot /boot/kernel/kernel
2249e1dc7beSWarner Losh.Ed
2259e1dc7beSWarner Losh.Pp
2269e1dc7beSWarner LoshSet the default device used for loading a kernel from a ZFS filesystem:
2279e1dc7beSWarner Losh.Bd -literal -offset indent
2289e1dc7beSWarner Loshset currdev=zfs:tank/ROOT/knowngood:
2299e1dc7beSWarner Losh.Ed
2309e1dc7beSWarner Losh.Pp
2319e1dc7beSWarner Losh.Sh ERRORS
2329e1dc7beSWarner LoshThe following values are thrown by
2339e1dc7beSWarner Losh.Nm :
2349e1dc7beSWarner Losh.Bl -tag -width XXXXX -offset indent
2359e1dc7beSWarner Losh.It 100
2369e1dc7beSWarner LoshAny type of error in the processing of a builtin.
2379e1dc7beSWarner Losh.It -1
2389e1dc7beSWarner Losh.Ic Abort
2399e1dc7beSWarner Loshexecuted.
2409e1dc7beSWarner Losh.It -2
2419e1dc7beSWarner Losh.Ic Abort"
2429e1dc7beSWarner Loshexecuted.
2439e1dc7beSWarner Losh.It -56
2449e1dc7beSWarner Losh.Ic Quit
2459e1dc7beSWarner Loshexecuted.
2469e1dc7beSWarner Losh.It -256
2479e1dc7beSWarner LoshOut of interpreting text.
2489e1dc7beSWarner Losh.It -257
2499e1dc7beSWarner LoshNeed more text to succeed -- will finish on next run.
2509e1dc7beSWarner Losh.It -258
2519e1dc7beSWarner Losh.Ic Bye
2529e1dc7beSWarner Loshexecuted.
2539e1dc7beSWarner Losh.It -259
2549e1dc7beSWarner LoshUnspecified error.
2559e1dc7beSWarner Losh.El
2569e1dc7beSWarner Losh.Sh SEE ALSO
257*11f49259SWarner Losh.Xr libsa 3 ,
2589e1dc7beSWarner Losh.Xr loader.conf 5 ,
2599e1dc7beSWarner Losh.Xr tuning 7 ,
2609e1dc7beSWarner Losh.Xr boot 8 ,
2619e1dc7beSWarner Losh.Xr btxld 8
2629e1dc7beSWarner Losh.Sh HISTORY
2639e1dc7beSWarner LoshThe
2649e1dc7beSWarner Losh.Nm
2659e1dc7beSWarner Loshfirst appeared in
2669aa29457SWarner Losh.Fx 12.0 .
267