LOADER(8) | MidnightBSD System Manager's Manual | LOADER(8) |
loader
— kernel
bootstrapping final stage
The program called loader
is the final
stage of FreeBSD's kernel bootstrapping process. On
IA32 (i386) architectures, it is a BTX client. It is
linked statically to
libstand(3) and usually
located in the directory /boot.
It provides a scripting language that can be used to automate tasks, do pre-configuration or assist in recovery procedures. This scripting language is roughly divided in two main components. The smaller one is a set of commands designed for direct use by the casual user, called "builtin commands" for historical reasons. The main drive behind these commands is user-friendliness. The bigger component is an ANS Forth compatible Forth interpreter based on FICL, by John Sadler.
During initialization, loader
will probe
for a console and set the console variable, or set it
to serial console (“comconsole
”) if
the previous boot stage used that. If multiple consoles are selected, they
will be listed separated by spaces. Then, devices are probed,
currdev and loaddev are set, and
LINES is set to 24. Next, FICL is initialized, the
builtin words are added to its vocabulary, and
/boot/loader.4th is processed if it exists. No disk
switching is possible while that file is being read. The inner interpreter
loader
will use with FICL is then set to
interpret
, which is FICL's default. After that,
/boot/loader.rc is processed if available. These
files are processed through the include
command,
which reads all of them into memory before processing them, making disk
changes possible.
At this point, if an autoboot
has not been
tried, and if autoboot_delay is not set to
“NO
” (not case sensitive), then an
autoboot
will be tried. If the system gets past this
point, prompt will be set and
loader
will engage interactive mode. Please note
that historically even when autoboot_delay is set to
“0
” user will be able to interrupt
autoboot process by pressing some key on the console while kernel and
modules are being loaded. In some cases such behaviour may be undesirable,
to prevent it set autoboot_delay to
“-1
”, in this case
loader
will engage interactive mode only if
autoboot
has failed.
In loader
, builtin commands take
parameters from the command line. Presently, the only way to call them from
a script is by using evaluate on a string. If an
error condition occurs, an exception will be generated, which can be
intercepted using ANS Forth exception handling words. If not intercepted, an
error message will be displayed and the interpreter's state will be reset,
emptying the stack and restoring interpreting mode.
The builtin commands available are:
autoboot
[seconds [prompt]]bcachestat
boot
boot
kernelname [...
]boot
-flag
...
WARNING: The behavior of this builtin is changed if loader.4th(8) is loaded.
echo
[-n
] [⟨message⟩]-n
is specified.
heap
help
[topic [subtopic]]include
file [file ...]load
[-t
type]
file ...
md_image
type to make the
kernel create a file-backed
md(4) disk. This is useful
for booting from a temporary rootfs. Currently, argument passing does not
work for the kernel.
load_geli
[-n
keyno]
prov filels
[-l
] [path]-l
is specified, file sizes will be shown too.
lsdev
[-v
]-v
is specified, more
details are printed, including ZFS pool information in a format that
resembles zpool
status
output.
lsmod
[-v
]-v
is specified, more
details are shown.
lszfs
filesystemmore
file [file ...]pnpscan
[-v
]read
[-t
seconds]
[-p
prompt]
[variable]-t
, though it will be canceled at the first
key pressed. A prompt may also be displayed through the
-p
flag.
reboot
set
variableset
variable=valueshow
[variable]unload
unset
variable?
The loader
has actually two different
kinds of ‘environment’ variables. There are ANS Forth's
environmental
queries, and a separate space of environment variables used by
builtins, which are not directly available to Forth words. It is the latter
type that this section covers.
Environment variables can be set and unset through the
set
and unset
builtins, and
can have their values interactively examined through the use of the
show
builtin. Their values can also be accessed as
described in BUILTIN PARSER.
Notice that these environment variables are not inherited by any shell after the system has been booted.
A few variables are set automatically by
loader
. Others can affect the behavior of either
loader
or the kernel at boot. Some options may
require a value, while others define behavior just by being set. Both types
of builtin variables are described below.
autoboot
will wait before
booting. Configuration options are described in
loader.conf(5).kernel
”.loader
was compiled. Changes to the
comconsole_speed variable take effect
immediately.loader
. Setting the
comconsole_port variable automatically set
hw.uart.console environment variable to provide a
hint to kernel for location of the console. Loader console is changed
immediately after variable comconsole_port is
set.'bus:device:function[:bar]'
, where
all members must be numeric, with possible 0x
prefix to indicate a hexadecimal value. The bar
member is optional and assumed to be 0x10 if omitted. The bar must decode
i/o space. Setting the variable comconsole_pcidev
automatically sets the variable comconsole_port to
the base of the selected bar, and hint
hw.uart.console. Loader console is changed
immediately after variable comconsole_pcidev is
set.loader_device:
zfs:dataset:
disk0p2:
zfs:zroot/ROOT/default:
/sbin/init:/sbin/oinit:/sbin/init.bak:/rescue/init
”.OK
” if the Forth's
current state is interpreting./boot/kernel;/boot/modules
”.loader
's prompt. Defaults to
“${interpret}
”. If variable
prompt is unset, the default prompt is
‘>
’.Other variables are used to override kernel tunable parameters. The following tunables are available:
k
,
K
, m
,
M
, g
and
G
suffixes are also accepted and indicate
kilobytes, megabytes and gigabytes respectively. An invalid suffix will
result in the variable being ignored by the kernel.NSFBUFS
. Not all
architectures use such buffers; see
sendfile(2) for
details.Note that swap metadata can be fragmented, which means that the system can run out of space before it reaches the theoretical limit. Therefore, care should be taken to not configure more swap than approximately half of the theoretical maximum.
Running out of space for swap metadata can leave the system in
an unrecoverable state. Therefore, you should only change this parameter
if you need to greatly extend the KVM reservation for other resources
such as the buffer cache or kern.ipc.nmbclusters.
Modifies kernel option VM_SWZONE_SIZE_MAX
.
VM_BCACHE_SIZE_MAX
.MSGBUF_SIZE
.TCBHASHSIZE
or the preset default of 512. Must be
a power of 2.VM_KMEM_SIZE
.VM_KMEM_SIZE_MIN
and
VM_KMEM_SIZE_MAX
.loader
supports the following format for
specifying ZFS filesystems which can be used wherever
loader(8) refers to a
device specification:
zfs:pool/filesystem:
where pool/filesystem is a ZFS filesystem name as described in zfs(8).
If /etc/fstab does not have an entry for
the root filesystem and vfs.root.mountfrom is not set,
but currdev refers to a ZFS filesystem, then
loader
will instruct kernel to use that filesystem
as the root filesystem.
When a builtin command is executed, the rest of the line is taken by it as arguments, and it is processed by a special parser which is not used for regular Forth commands.
This special parser applies the following rules to the parsed text:
$VARIABLE
or
${VARIABLE}
with the value of the environment
variable VARIABLE.An exception to this parsing rule exists, and is described in BUILTINS AND FORTH.
All builtin words are state-smart, immediate words. If interpreted, they behave exactly as described previously. If they are compiled, though, they extract their arguments from the stack instead of the command line.
If compiled, the builtin words expect to find, at execution time, the following parameters on the stack:
If no arguments are passed, a 0 must be passed, even if the builtin accepts no arguments.
While this behavior has benefits, it has its trade-offs. If the
execution token of a builtin is acquired (through '
or [']
), and then passed to
catch
or execute
, the
builtin behavior will depend on the system state
catch
or
execute
is processed!: (boot) boot
FICL is a Forth interpreter written in C, in the form of a forth virtual machine library that can be called by C functions and vice versa.
In loader
, each line read interactively is
then fed to FICL, which may call loader
back to
execute the builtin words. The builtin include
will
also feed FICL, one line at a time.
The words available to FICL can be classified into four groups. The ANS Forth standard words, extra FICL words, extra FreeBSD words, and the builtin commands; the latter were already described. The ANS Forth standard words are listed in the STANDARDS section. The words falling in the two other groups are described in the following subsections.
.env
.ver
-roll
2constant
>name
body>
compare
compare
.compile-only
endif
forget-wid
parse-word
sliteral
sliteral
.wid-set-super
w@
w!
x.
empty
cell-
-rot
$
(--)%
(--)catch
exception guard..#
fclose
(fd --)fkey
(fd -- char)fload
(fd --)fopen
(addr len mode --
fd)O_RDONLY
, O_WRONLY
, and
O_RDWR
are defined in
/boot/support.4th, indicating read only, write
only, and read-write access, respectively.fread
(fd addr len -- len')heap?
(-- cells)inb
(port -- char)key
(-- char)key?
(-- flag)true
if there is a character available to
be read from the console.ms
(u --)outb
(port char --)seconds
(-- u)tib>
(-- addr len)trace!
(flag --)catch
.TRUE
if the
architecture is IA32.loader
version.Access to the loader
command line provides
several ways of compromising system security, including, but not limited
to:
One can prevent unauthorized access to the
loader
command line by setting the
password, or setting
autoboot_delay to -1. See
loader.conf(5) for
details. In order for this to be effective, one should also configure the
firmware (BIOS or UEFI) to prevent booting from unauthorized devices.
Memory disk (MD) can be used when the
loader
was compiled with
MD_IMAGE_SIZE. The size of the memory disk is
determined by MD_IMAGE_SIZE. If MD available, a file
system can be embedded into the loader
with
/sys/tools/embed_mfs.sh. Then, MD will be probed and
be set to currdev during initialization.
Currently, MD is only supported in loader.efi(8).
loader
itself.loader
configuration files, as described in
loader.conf(5).loader
bootstrapping script.help
. Contains the help messages.Boot in single user mode:
boot -s
Load the kernel, a splash screen, and then autoboot in five
seconds. Notice that a kernel must be loaded before any other
load
command is attempted.
load kernel load splash_bmp load -t splash_image_data /boot/chuckrulez.bmp autoboot 5
Set the disk unit of the root device to 2, and then boot. This would be needed in a system with two IDE disks, with the second IDE disk hardwired to ada2 instead of ada1.
set root_disk_unit=2 boot /boot/kernel/kernel
Set the default device used for loading a kernel from a ZFS filesystem:
set currdev=zfs:tank/ROOT/knowngood:
The following values are thrown by
loader
:
For the purposes of ANS Forth compliance, loader is an
marker
[then]
The loader
first appeared in
FreeBSD 3.1.
The loader
was written by
Michael Smith
⟨msmith@FreeBSD.org⟩.
FICL was written by John Sadler ⟨john_sadler@alum.mit.edu⟩.
The expect
and
accept
words will read from the input buffer instead
of the console. The latter will be fixed, but the former will not.
October 8, 2021 | midnightbsd-3.1 |