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.Dd September 29, 2021 269e1dc7beSWarner Losh.Dt LOADER_LUA 8 279e1dc7beSWarner Losh.Os 289e1dc7beSWarner Losh.Sh NAME 299e1dc7beSWarner Losh.Nm loader_lua 309e1dc7beSWarner Losh.Nd kernel bootstrapping final stage 319e1dc7beSWarner Losh.Sh DESCRIPTION 329e1dc7beSWarner LoshThe program called 339e1dc7beSWarner Losh.Nm 349e1dc7beSWarner Loshis the final stage of 359e1dc7beSWarner Losh.Fx Ns 's 369e1dc7beSWarner Loshkernel bootstrapping process. 379e1dc7beSWarner LoshOn IA32 (i386) architectures, it is a 389e1dc7beSWarner Losh.Pa BTX 399e1dc7beSWarner Loshclient. 409e1dc7beSWarner LoshIt is linked statically to 4111f49259SWarner Losh.Xr libsa 3 429e1dc7beSWarner Loshand usually located in the directory 439e1dc7beSWarner Losh.Pa /boot . 449e1dc7beSWarner Losh.Pp 459e1dc7beSWarner LoshIt provides a scripting language that can be used to 469e1dc7beSWarner Loshautomate tasks, do pre-configuration or assist in recovery 479e1dc7beSWarner Loshprocedures. 489e1dc7beSWarner LoshThis scripting language is roughly divided in 499e1dc7beSWarner Loshtwo main components. 509e1dc7beSWarner LoshThe smaller one is a set of commands 519e1dc7beSWarner Loshdesigned for direct use by the casual user, called "builtin 529e1dc7beSWarner Loshcommands" for historical reasons. 539e1dc7beSWarner LoshThe main drive behind these commands is user-friendliness. 5467f5810eSJens SchweikhardtThe bigger component is the Lua interpreter. 559e1dc7beSWarner Losh.Pp 569e1dc7beSWarner LoshDuring initialization, 579e1dc7beSWarner Losh.Nm 588e458a43SJens Schweikhardtprobes for a console and sets the 599e1dc7beSWarner Losh.Va console 608e458a43SJens Schweikhardtvariable, or sets it to serial console 619e1dc7beSWarner Losh.Pq Dq Li comconsole 629e1dc7beSWarner Loshif the previous boot stage used that. 6367f5810eSJens SchweikhardtIf multiple consoles are selected, they are listed separated by spaces. 649e1dc7beSWarner LoshThen, devices are probed, 659e1dc7beSWarner Losh.Va currdev 669e1dc7beSWarner Loshand 679e1dc7beSWarner Losh.Va loaddev 689e1dc7beSWarner Loshare set, and 699e1dc7beSWarner Losh.Va LINES 709e1dc7beSWarner Loshis set to 24. 719e1dc7beSWarner LoshNext, Lua is initialized, and 729e1dc7beSWarner Losh.Pa /boot/lua/loader.lua 739e1dc7beSWarner Loshis processed if it exists. 749e1dc7beSWarner LoshAfter that, 759e1dc7beSWarner Losh.Pa /boot/loader.conf 769e1dc7beSWarner Loshis processed if available. 779e1dc7beSWarner Losh.Pp 789e1dc7beSWarner LoshAt this point, if an 799e1dc7beSWarner Losh.Ic autoboot 808e458a43SJens Schweikhardthas not been attempted, and if 819e1dc7beSWarner Losh.Va autoboot_delay 829e1dc7beSWarner Loshis not set to 839e1dc7beSWarner Losh.Dq Li NO 848e458a43SJens Schweikhardt(case insensitive), then an 859e1dc7beSWarner Losh.Ic autoboot 8667f5810eSJens Schweikhardtis attempted. 879e1dc7beSWarner LoshIf the system gets past this point, 889e1dc7beSWarner Losh.Va prompt 8967f5810eSJens Schweikhardtis set and 909e1dc7beSWarner Losh.Nm 9167f5810eSJens Schweikhardtenters interactive mode. 9267f5810eSJens SchweikhardtPlease note that, historically, even when 939e1dc7beSWarner Losh.Va autoboot_delay 949e1dc7beSWarner Loshis set to 9567f5810eSJens Schweikhardt.Dq Li 0 , 9667f5810eSJens Schweikhardtthe user can interrupt the autoboot process by pressing a key 9767f5810eSJens Schweikhardton the console while the kernel and modules are being loaded. 9867f5810eSJens SchweikhardtTo prevent this set 999e1dc7beSWarner Losh.Va autoboot_delay 1009e1dc7beSWarner Loshto 10167f5810eSJens Schweikhardt.Dq Li -1 . 10267f5810eSJens SchweikhardtIn this case 1039e1dc7beSWarner Losh.Nm 10467f5810eSJens Schweikhardtenters interactive mode only if 1059e1dc7beSWarner Losh.Ic autoboot 1069e1dc7beSWarner Loshhas failed. 1079e1dc7beSWarner Losh.Sh BUILTIN COMMANDS 1089e1dc7beSWarner LoshIn 1099e1dc7beSWarner Losh.Nm , 1109e1dc7beSWarner Loshbuiltin commands take parameters from the command line. 1119e1dc7beSWarner LoshPresently, 1129e1dc7beSWarner Loshthe only way to call them from a script is by using 1139e1dc7beSWarner Losh.Pa evaluate 1149e1dc7beSWarner Loshon a string. 11567f5810eSJens SchweikhardtIf an error condition occurs, an exception is generated, 1169e1dc7beSWarner Loshwhich can be intercepted using Lua exception handling. 11767f5810eSJens SchweikhardtIf not intercepted, an error message is displayed and 11867f5810eSJens Schweikhardtthe interpreter's state is reset, emptying the stack and restoring 1199e1dc7beSWarner Loshinterpreting mode. 1209e1dc7beSWarner Losh.Pp 1219e1dc7beSWarner LoshThe commands are described in the 1229e1dc7beSWarner Losh.Xr loader_simp 8 1239e1dc7beSWarner Losh.Dq BUILTIN COMMANDS 1249e1dc7beSWarner Loshsection. 1259e1dc7beSWarner Losh.Ss BUILTIN ENVIRONMENT VARIABLES 1269e1dc7beSWarner LoshThe environment variables common to all interpreters are described in the 1279e1dc7beSWarner Losh.Xr loader_simp 8 1289e1dc7beSWarner Losh.Dq BUILTIN ENVIRONMENT VARIABLES 1299e1dc7beSWarner Loshsection. 1309e1dc7beSWarner Losh.Ss BUILTIN PARSER 1319e1dc7beSWarner LoshWhen a builtin command is executed, the rest of the line is taken 1328e458a43SJens Schweikhardtas arguments, and it is processed by a special parser which 1339e1dc7beSWarner Loshis not used for regular Lua commands. 1349e1dc7beSWarner Losh.Sh SECURITY 1359e1dc7beSWarner LoshAccess to the 1369e1dc7beSWarner Losh.Nm 1379e1dc7beSWarner Loshcommand line provides several ways of compromising system security, 1389e1dc7beSWarner Loshincluding, but not limited to: 1399e1dc7beSWarner Losh.Pp 1409e1dc7beSWarner Losh.Bl -bullet 1419e1dc7beSWarner Losh.It 1429e1dc7beSWarner LoshBooting from removable storage, by setting the 1439e1dc7beSWarner Losh.Va currdev 1449e1dc7beSWarner Loshor 1459e1dc7beSWarner Losh.Va loaddev 1469e1dc7beSWarner Loshvariables 1479e1dc7beSWarner Losh.It 1488e458a43SJens SchweikhardtExecuting a binary of choice, by setting the 1499e1dc7beSWarner Losh.Va init_path 1509e1dc7beSWarner Loshor 1519e1dc7beSWarner Losh.Va init_script 1529e1dc7beSWarner Loshvariables 1539e1dc7beSWarner Losh.It 1549e1dc7beSWarner LoshOverriding ACPI DSDT to inject arbitrary code into the ACPI subsystem 1559e1dc7beSWarner Losh.El 1569e1dc7beSWarner Losh.Pp 1579e1dc7beSWarner LoshOne can prevent unauthorized access 1589e1dc7beSWarner Loshto the 1599e1dc7beSWarner Losh.Nm 1609e1dc7beSWarner Loshcommand line by setting the 1619e1dc7beSWarner Losh.Va password , 1629e1dc7beSWarner Loshor setting 1639e1dc7beSWarner Losh.Va autoboot_delay 1649e1dc7beSWarner Loshto -1. 1659e1dc7beSWarner LoshSee 1669e1dc7beSWarner Losh.Xr loader.conf 5 1679e1dc7beSWarner Loshfor details. 1689e1dc7beSWarner LoshIn order for this to be effective, one should also configure the firmware 1699e1dc7beSWarner Losh(BIOS or UEFI) to prevent booting from unauthorized devices. 1709e1dc7beSWarner Losh.Sh MD 1719e1dc7beSWarner LoshMemory disk (MD) can be used when the 1729e1dc7beSWarner Losh.Nm 1739e1dc7beSWarner Loshwas compiled with 1749e1dc7beSWarner Losh.Va MD_IMAGE_SIZE . 1759e1dc7beSWarner LoshThe size of the memory disk is determined by 1769e1dc7beSWarner Losh.Va MD_IMAGE_SIZE . 1779e1dc7beSWarner LoshIf MD available, a file system can be embedded into the 1789e1dc7beSWarner Losh.Nm 1799e1dc7beSWarner Loshwith 1809e1dc7beSWarner Losh.Pa /sys/tools/embed_mfs.sh . 1818e458a43SJens SchweikhardtThen, MD is probed and set to 1829e1dc7beSWarner Losh.Va currdev 1839e1dc7beSWarner Loshduring initialization. 1849e1dc7beSWarner Losh.Pp 1859e1dc7beSWarner LoshCurrently, MD is only supported in 1869e1dc7beSWarner Losh.Xr loader.efi 8 . 1879e1dc7beSWarner Losh.Sh FILES 1889e1dc7beSWarner Losh.Bl -tag -width /usr/share/examples/bootforth/ -compact 1899e1dc7beSWarner Losh.It Pa /boot/loader 1909e1dc7beSWarner Losh.Nm 1919e1dc7beSWarner Loshitself. 1929e1dc7beSWarner Losh.It Pa /boot/defaults/loader.conf 1939e1dc7beSWarner Losh.It Pa /boot/lua/loader.lua 1949e1dc7beSWarner LoshLoader init 1959e1dc7beSWarner Losh.It Pa /boot/loader.conf 1969e1dc7beSWarner Losh.It Pa /boot/loader.conf.local 1979e1dc7beSWarner Losh.Nm 1989e1dc7beSWarner Loshconfiguration files, as described in 1999e1dc7beSWarner Losh.Xr loader.conf 5 . 200*643fc698SGraham Percival.El 2019e1dc7beSWarner Losh.Sh EXAMPLES 2029e1dc7beSWarner LoshBoot in single user mode: 2039e1dc7beSWarner Losh.Pp 2049e1dc7beSWarner Losh.Dl boot -s 2059e1dc7beSWarner Losh.Pp 2069e1dc7beSWarner LoshLoad the kernel, a splash screen, and then autoboot in five seconds. 2079e1dc7beSWarner LoshNotice that a kernel must be loaded before any other 2089e1dc7beSWarner Losh.Ic load 2099e1dc7beSWarner Loshcommand is attempted. 2109e1dc7beSWarner Losh.Bd -literal -offset indent 2119e1dc7beSWarner Loshload kernel 2129e1dc7beSWarner Loshload splash_bmp 2139e1dc7beSWarner Loshload -t splash_image_data /boot/chuckrulez.bmp 2149e1dc7beSWarner Loshautoboot 5 2159e1dc7beSWarner Losh.Ed 2169e1dc7beSWarner Losh.Pp 2179e1dc7beSWarner LoshSet the disk unit of the root device to 2, and then boot. 2189e1dc7beSWarner LoshThis would be needed in a system with two IDE disks, 2199e1dc7beSWarner Loshwith the second IDE disk hardwired to ada2 instead of ada1. 2209e1dc7beSWarner Losh.Bd -literal -offset indent 2219e1dc7beSWarner Loshset root_disk_unit=2 2229e1dc7beSWarner Loshboot /boot/kernel/kernel 2239e1dc7beSWarner Losh.Ed 2249e1dc7beSWarner Losh.Pp 2259e1dc7beSWarner LoshSet the default device used for loading a kernel from a ZFS filesystem: 2269e1dc7beSWarner Losh.Bd -literal -offset indent 2279e1dc7beSWarner Loshset currdev=zfs:tank/ROOT/knowngood: 2289e1dc7beSWarner Losh.Ed 2299e1dc7beSWarner Losh.Pp 2309e1dc7beSWarner Losh.Sh ERRORS 2319e1dc7beSWarner LoshThe following values are thrown by 2329e1dc7beSWarner Losh.Nm : 2339e1dc7beSWarner Losh.Bl -tag -width XXXXX -offset indent 2349e1dc7beSWarner Losh.It 100 2359e1dc7beSWarner LoshAny type of error in the processing of a builtin. 2369e1dc7beSWarner Losh.It -1 2379e1dc7beSWarner Losh.Ic Abort 2389e1dc7beSWarner Loshexecuted. 2399e1dc7beSWarner Losh.It -2 2409e1dc7beSWarner Losh.Ic Abort" 2419e1dc7beSWarner Loshexecuted. 2429e1dc7beSWarner Losh.It -56 2439e1dc7beSWarner Losh.Ic Quit 2449e1dc7beSWarner Loshexecuted. 2459e1dc7beSWarner Losh.It -256 2469e1dc7beSWarner LoshOut of interpreting text. 2479e1dc7beSWarner Losh.It -257 2489e1dc7beSWarner LoshNeed more text to succeed -- will finish on next run. 2499e1dc7beSWarner Losh.It -258 2509e1dc7beSWarner Losh.Ic Bye 2519e1dc7beSWarner Loshexecuted. 2529e1dc7beSWarner Losh.It -259 2539e1dc7beSWarner LoshUnspecified error. 2549e1dc7beSWarner Losh.El 2559e1dc7beSWarner Losh.Sh SEE ALSO 25611f49259SWarner Losh.Xr libsa 3 , 2579e1dc7beSWarner Losh.Xr loader.conf 5 , 2589e1dc7beSWarner Losh.Xr tuning 7 , 2599e1dc7beSWarner Losh.Xr boot 8 , 2609e1dc7beSWarner Losh.Xr btxld 8 2619e1dc7beSWarner Losh.Sh HISTORY 2629e1dc7beSWarner LoshThe 2639e1dc7beSWarner Losh.Nm 2649e1dc7beSWarner Loshfirst appeared in 2659aa29457SWarner Losh.Fx 12.0 . 266