8547 update mandoc to 1.14.3
[unleashed.git] / usr / src / man / man5 / loader.5
blobb65ab25ed9add91276e1a464a9cfd416b4890046
1 .\" Copyright (c) 1999 Daniel C. Sobral
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .Dd Apr 20, 2017
26 .Dt LOADER 5
27 .Os
28 .Sh NAME
29 .Nm loader
30 .Nd kernel bootstrapping final stage
31 .Sh DESCRIPTION
32 The
33 .Nm
34 is the final stage of
35 .Nm illumos Ns 's
36 kernel bootstrapping process.
37 The actual name for the stage depends on the platform.
38 On IA32 (i386) architectures with BIOS firmware, it is a
39 .Pa BTX
40 client and named
41 .Nm zfsloader .
42 It is linked statically to libstand and usually located in the directory
43 .Pa /boot .
44 .Pp
45 .Nm
46 supports booting from
47 .Cm ZFS ,
48 .Cm UFS ,
49 .Cm PCFS ,
50 .Cm HSFS
51 and
52 .Cm NFS
53 file systems.
54 Additionally,
55 .Nm
56 can load files from the
57 .Cm TFTP
58 file service.
59 The NFS and TFTP based boot is enabled via
60 .Xr pxeboot 5 .
61 The
62 .Nm
63 also does support uncompressing gzip files while reading.
64 The uncompression will happen automatically if the compressed file is stored
65 without .gz suffix or if the file is accessed by leaving out the .gz suffix from
66 the name.
67 If the file is referred by full name, including .gz suffix, then the file
68 content is read as is and the uncompression is not performed.
69 .Pp
70 .Nm
71 provides a scripting language that can be used to
72 automate tasks, do pre-configuration or assist in recovery
73 procedures.
74 This scripting language is roughly divided in
75 two main components.
76 The smaller one is a set of commands
77 designed for direct use by the casual user, called "builtin
78 commands" for historical reasons.
79 The main drive behind these commands is user-friendliness.
80 The bigger component is an
81 .Tn ANS
82 Forth compatible Forth interpreter based on FICL, by
83 .An John Sadler .
84 .Pp
85 During initialization,
86 .Nm
87 will probe for a console and set the
88 .Va console
89 variable, or set it to serial console
90 .Pq Do Li ttya Dc - Dq Li ttyd
91 if the previous boot stage used that.
92 If multiple consoles are selected, they will be listed separated by commas.
93 Then, devices are probed,
94 .Va currdev
95 and
96 .Va loaddev
97 are set, and
98 .Va COLUMNS ,
99 .Va LINES ,
101 .Va ISADIR
102 are set.
103 Next,
104 .Tn FICL
105 is initialized, the builtin words are added to its vocabulary.
106 The inner interpreter
108 will use with
109 .Tn FICL
110 is then set to
111 .Ic interpret ,
112 which is
113 .Tn FICL Ns 's
114 default.
115 After that,
116 .Pa /boot/loader.rc
117 is processed if available.
118 These files are processed through the
119 .Ic include
120 command, which reads all of them into memory before processing them,
121 making disk changes possible.
123 At this point, if an
124 .Ic autoboot
125 has not been tried, and if
126 .Va autoboot_delay
127 is not set to
128 .Dq Li NO
129 (not case sensitive), then an
130 .Ic autoboot
131 will be tried.
132 If the system gets past this point,
133 .Va prompt
134 will be set and
136 will engage interactive mode.
137 Please note that historically even when
138 .Va autoboot_delay
139 is set to
140 .Dq Li 0
141 user will be able to interrupt autoboot process by pressing some key
142 on the console while kernel and modules are being loaded.
143 In some
144 cases such behaviour may be undesirable, to prevent it set
145 .Va autoboot_delay
147 .Dq Li -1 ,
148 in this case
150 will engage interactive mode only if
151 .Ic autoboot
152 has failed.
153 .Ss Builtin Commands
155 .Nm ,
156 builtin commands take parameters from the command line.
157 If an error condition occurs, an exception will be generated,
158 which can be intercepted using
159 .Tn ANS
160 Forth exception handling
161 words.
162 If not intercepted, an error message will be displayed and
163 the interpreter's state will be reset, emptying the stack and restoring
164 interpreting mode.
166 The builtin commands available are:
168 .Bl -tag -width Ds -compact
169 .It Ic autoboot Op Ar seconds Op Ar prompt
170 Proceeds to bootstrap the system after a number of seconds, if not
171 interrupted by the user.
172 Displays a countdown prompt
173 warning the user the system is about to be booted,
174 unless interrupted by a key press.
175 The kernel will be loaded first if necessary.
176 Defaults to 10 seconds.
178 .It Ic bcachestat
179 Displays statistics about disk cache usage.
180 For debugging only.
182 .It Ic boot
183 .It Ic boot Ar kernelname Op Cm ...
184 .It Ic boot Fl flag Cm ...
185 Immediately proceeds to bootstrap the system, loading the kernel
186 if necessary.
187 Any flags or arguments are passed to the kernel, but they
188 must precede the kernel name, if a kernel name is provided.
190 .Em WARNING :
191 The behavior of this builtin is changed if
192 .Xr loader.4th 5
193 is loaded.
195 .It Ic chain Ar device
196 Chain load another boot loader from the specified device.
197 Device can be either disk name or partition.
199 .It Ic echo Xo
200 .Op Fl n
201 .Op Aq message
203 Displays text on the screen.
204 A new line will be printed unless
205 .Fl n
206 is specified.
208 .It Ic heap
209 Displays memory usage statistics.
210 For debugging purposes only.
212 .It Ic help Op topic Op subtopic
213 Shows help messages read from
214 .Pa /boot/loader.help .
215 The special topic
216 .Em index
217 will list the topics available.
219 .It Ic include Ar file Op Ar
220 Process script files.
221 Each file, in turn, is completely read into memory,
222 and then each of its lines is passed to the command line interpreter.
223 If any error is returned by the interpreter, the include
224 command aborts immediately, without reading any other files, and
225 returns an error itself (see
226 .Sx ERRORS ) .
228 .It Ic load Xo
229 .Op Fl t Ar type
230 .Ar file Cm ...
232 Loads a kernel or file of opaque contents tagged as being of the type
233 .Ar type .
234 Kernel and modules can be either in a.out or ELF format.
235 Any arguments passed after the name of the file to be loaded
236 will be passed as arguments to that file.
238 .It Ic ls Xo
239 .Op Fl l
240 .Op Ar path
242 Displays a listing of files in the directory
243 .Ar path ,
244 or the root directory if
245 .Ar path
246 is not specified.
248 .Fl l
249 is specified, file sizes will be shown too.
251 .It Ic lsdev Op Fl v
252 Lists all of the devices from which it may be possible to load modules.
254 .Fl v
255 is specified, more details are printed.
257 .It Ic lsmod Op Fl v
258 Displays loaded modules.
260 .Fl v
261 is specified, more details are shown.
263 .It Ic more Ar file Op Ar
264 Display the files specified, with a pause at each
265 .Va LINES
266 displayed.
268 .It Ic read Xo
269 .Op Fl t Ar seconds
270 .Op Fl p Ar prompt
271 .Op Va variable
273 Reads a line of input from the terminal, storing it in
274 .Va variable
275 if specified.
276 A timeout can be specified with
277 .Fl t ,
278 though it will be canceled at the first key pressed.
279 A prompt may also be displayed through the
280 .Fl p
281 flag.
283 .It Ic reboot
284 Immediately reboots the system.
286 .It Ic set Ar variable
287 .It Ic set Ar variable Ns = Ns Ar value
288 Set loader's environment variables.
290 .It Ic show Op Va variable
291 Displays the specified variable's value, or all variables and their
292 values if
293 .Va variable
294 is not specified.
296 .It Ic unload
297 Remove all modules from memory.
299 .It Ic unset Va variable
300 Removes
301 .Va variable
302 from the environment.
304 .It Ic \&?
305 Lists available commands.
307 .Ss Builtin Environment Variables
310 has actually two different kinds of
311 .Sq environment
312 variables.
313 There are ANS Forth's
314 .Em environmental queries ,
315 and a separate space of environment variables used by builtins, which
316 are not directly available to Forth words.
317 It is the latter type that this section covers.
319 Environment variables can be set and unset through the
320 .Ic set
322 .Ic unset
323 builtins, and can have their values interactively examined through the
324 use of the
325 .Ic show
326 builtin.
327 Their values can also be accessed as described in
328 .Sx BUILTIN PARSER .
330 Notice that these environment variables are not inherited by any shell
331 after the system has been booted.
333 A few variables are set automatically by
334 .Nm .
335 Others can affect the behavior of either
337 or the kernel at boot.
338 Some options may require a value,
339 while others define behavior just by being set.
340 Both types of builtin variables are described below.
341 .Bl -tag -width bootfile
342 .It Va autoboot_delay
343 Number of seconds
344 .Ic autoboot
345 will wait before booting.
346 If this variable is not defined,
347 .Ic autoboot
348 will default to 10 seconds.
350 If set to
351 .Dq Li NO ,
353 .Ic autoboot
354 will be automatically attempted after processing
355 .Pa /boot/loader.rc ,
356 though explicit
357 .Ic autoboot Ns 's
358 will be processed normally, defaulting to 10 seconds delay.
360 If set to
361 .Dq Li 0 ,
362 no delay will be inserted, but user still will be able to interrupt
363 .Ic autoboot
364 process and escape into the interactive mode by pressing some key
365 on the console while kernel and
366 modules are being loaded.
368 If set to
369 .Dq Li -1 ,
370 no delay will be inserted and
372 will engage interactive mode only if
373 .Ic autoboot
374 has failed for some reason.
375 .It Va boot_ask
376 Will set
377 .Xr kernel 1M
378 .Fl a
379 option.
380 .It Va boot_debug
381 Will set
382 .Xr kernel 1M
383 .Fl d
384 option.
385 .It Va boot_kmdb
386 Will set
387 .Xr kernel 1M
388 .Fl k
389 option.
390 .It Va boot_reconfigure
391 Will set
392 .Xr kernel 1M
393 .Fl r
394 option.
395 .It Va boot_single
396 Will set
397 .Xr kernel 1M
398 .Fl s
399 option.
400 .It Va boot_verbose
401 Will set
402 .Xr kernel 1M
403 .Fl v
404 option.
405 .It Va boot-args
406 Will set custom arguments for the kernel.
407 If set in
409 configuration, the
411 startup will parse the
412 .Va boot-args
413 value to set boot prefixed variables listed above, any unrecognized options
414 are added to kernel command line verbatim.
415 .It Va bootfile
416 The name of the kernel.
417 .It Va console
418 Defines the current console or consoles.
419 Multiple consoles may be specified.
420 In that case, the first listed console will become the default console for
422 .Xr kernel 1M .
423 .It Va currdev
424 Selects the default device.
425 Syntax for devices is odd.
426 .It Va interpret
427 Has the value
428 .Dq Li ok
429 if the Forth's current state is interpreting.
430 .It Va LINES
431 Define the number of lines on the screen, to be used by the pager.
432 .It Va module_path
433 Sets the list of directories which will be searched for modules
434 named in a load command or implicitly required by a dependency.
435 The default value for this variable is
436 .Dq Li /platform/i86pc/${ISADIR}
437 .It Va prompt
438 Value of
439 .Nm Ns 's
440 prompt.
441 Defaults to
442 .Dq Li "${interpret}" .
443 If variable
444 .Va prompt
445 is unset, the default prompt is
446 .Ql > .
447 .It Va os_console
448 If set, the value is used to set
449 .Xr kernel 1M
450 .Va console
451 property.
454 Other variables are used for loader or to set kernel properties or for
455 informational purposes.
456 .Ss Builtin Parser
457 When a builtin command is executed, the rest of the line is taken
458 by it as arguments, and it is processed by a special parser which
459 is not used for regular Forth commands.
461 This special parser applies the following rules to the parsed text:
462 .Bl -enum
464 All backslash characters are preprocessed.
465 .Bl -bullet
467 \eb , \ef , \er , \en and \et are processed as in C.
469 \es is converted to a space.
471 \ev is converted to
472 .Tn ASCII
475 \ez is just skipped.
476 Useful for things like
477 .Dq \e0xf\ez\e0xf .
479 \e0xN and \e0xNN are replaced by the hex N or NN.
481 \eNNN is replaced by the octal NNN
482 .Tn ASCII
483 character.
485 \e" , \e' and \e$ will escape these characters, preventing them from
486 receiving special treatment in Step 2, described below.
488 \e\e will be replaced with a single \e .
490 In any other occurrence, backslash will just be removed.
493 Every string between non-escaped quotes or double-quotes will be treated
494 as a single word for the purposes of the remaining steps.
496 Replace any
497 .Li $VARIABLE
499 .Li ${VARIABLE}
500 with the value of the environment variable
501 .Va VARIABLE .
503 Space-delimited arguments are passed to the called builtin command.
504 Spaces can also be escaped through the use of \e\e .
507 An exception to this parsing rule exists, and is described in
508 .Sx Builtins And FORTH .
509 .Ss Builtins And FORTH
510 All builtin words are state-smart, immediate words.
511 If interpreted, they behave exactly as described previously.
512 If they are compiled, though,
513 they extract their arguments from the stack instead of the command line.
515 If compiled, the builtin words expect to find, at execution time, the
516 following parameters on the stack:
517 .D1 Ar addrN lenN ... addr2 len2 addr1 len1 N
518 where
519 .Ar addrX lenX
520 are strings which will compose the command line that will be parsed
521 into the builtin's arguments.
522 Internally, these strings are concatenated in from 1 to N,
523 with a space put between each one.
525 If no arguments are passed, a 0
526 .Em must
527 be passed, even if the builtin accepts no arguments.
529 While this behavior has benefits, it has its trade-offs.
530 If the execution token of a builtin is acquired (through
531 .Ic '
533 .Ic ['] ) ,
534 and then passed to
535 .Ic catch
537 .Ic execute ,
538 the builtin behavior will depend on the system state
539 .Bf Em
540 at the time
541 .Ic catch
543 .Ic execute
544 is processed!
546 This is particularly annoying for programs that want or need to
547 handle exceptions.
548 In this case, the use of a proxy is recommended.
549 For example:
550 .Dl : (boot) boot ;
551 .Ss FICL
552 .Tn FICL
553 is a Forth interpreter written in C, in the form of a forth
554 virtual machine library that can be called by C functions and vice
555 versa.
558 .Nm ,
559 each line read interactively is then fed to
560 .Tn FICL ,
561 which may call
563 back to execute the builtin words.
564 The builtin
565 .Ic include
566 will also feed
567 .Tn FICL ,
568 one line at a time.
570 The words available to
571 .Tn FICL
572 can be classified into four groups.
574 .Tn ANS
575 Forth standard words, extra
576 .Tn FICL
577 words, extra
579 words, and the builtin commands;
580 the latter were already described.
582 .Tn ANS
583 Forth standard words are listed in the
584 .Sx STANDARDS
585 section.
586 The words falling in the two other groups are described in the
587 following subsections.
588 .Ss FICL Extra Words
589 .Bl -tag -width wid-set-super
590 .It Ic .env
591 .It Ic .ver
592 .It Ic -roll
593 .It Ic 2constant
594 .It Ic >name
595 .It Ic body>
596 .It Ic compare
597 This is the STRING word set's
598 .Ic compare .
599 .It Ic compile-only
600 .It Ic endif
601 .It Ic forget-wid
602 .It Ic parse-word
603 .It Ic sliteral
604 This is the STRING word set's
605 .Ic sliteral .
606 .It Ic wid-set-super
607 .It Ic w@
608 .It Ic w!
609 .It Ic x.
610 .It Ic empty
611 .It Ic cell-
612 .It Ic -rot
614 .Ss Loader Extra Words
615 .Bl -tag -width XXXXXXXX
616 .It Ic \&$ Pq --
617 Evaluates the remainder of the input buffer, after having printed it first.
618 .It Ic \&% Pq --
619 Evaluates the remainder of the input buffer under a
620 .Ic catch
621 exception guard.
622 .It Ic .#
623 Works like
624 .Ic \&.
625 but without outputting a trailing space.
626 .It Ic fclose Pq Ar fd --
627 Closes a file.
628 .It Ic fkey Pq Ar fd -- char
629 Reads a single character from a file.
630 .It Ic fload Pq Ar fd --
631 Processes a file
632 .Em fd .
633 .It Ic fopen Pq Ar addr len mode Li -- Ar fd
634 Opens a file.
635 Returns a file descriptor, or \-1 in case of failure.
637 .Ar mode
638 parameter selects whether the file is to be opened for read access, write
639 access, or both.
640 The constants
641 .Dv O_RDONLY , O_WRONLY ,
643 .Dv O_RDWR
644 are defined in
645 .Pa /boot/forth/support.4th ,
646 indicating read only, write only, and read-write access, respectively.
647 .It Xo
648 .Ic fread
649 .Pq Ar fd addr len -- len'
651 Tries to read
652 .Em len
653 bytes from file
654 .Em fd
655 into buffer
656 .Em addr .
657 Returns the actual number of bytes read, or -1 in case of error or end of
658 file.
659 .It Ic heap? Pq -- Ar cells
660 Return the space remaining in the dictionary heap, in cells.
661 This is not related to the heap used by dynamic memory allocation words.
662 .It Ic inb Pq Ar port -- char
663 Reads a byte from a port.
664 .It Ic key Pq -- Ar char
665 Reads a single character from the console.
666 .It Ic key? Pq -- Ar flag
667 Returns
668 .Ic true
669 if there is a character available to be read from the console.
670 .It Ic ms Pq Ar u --
671 Waits
672 .Em u
673 microseconds.
674 .It Ic outb Pq Ar port char --
675 Writes a byte to a port.
676 .It Ic seconds Pq -- Ar u
677 Returns the number of seconds since midnight.
678 .It Ic tib> Pq -- Ar addr len
679 Returns the remainder of the input buffer as a string on the stack.
681 .Ss Loader Defined Environmental Queries
682 .Bl -tag -width Ds
683 .It arch-i386
684 .Ic TRUE
685 if the architecture is IA32.
686 .It loader_version
688 version.
690 .Ss Errors
691 The following values are thrown by
692 .Nm :
693 .Bl -tag -width XXXXX -offset indent
694 .It 100
695 Any type of error in the processing of a builtin.
696 .It -1
697 .Ic Abort
698 executed.
699 .It -2
700 .Ic Abort"
701 executed.
702 .It -56
703 .Ic Quit
704 executed.
705 .It -256
706 Out of interpreting text.
707 .It -257
708 Need more text to succeed -- will finish on next run.
709 .It -258
710 .Ic Bye
711 executed.
712 .It -259
713 Unspecified error.
715 .Sh FILES
716 .Bl -tag -width /boot/defaults/loader.conf -compact
717 .It Pa /boot/defaults/loader.conf
718 .It Pa /boot/conf.d/*
719 .It Pa /boot/loader.conf
720 .It Pa /boot/loader.conf.local
722 configuration files, as described in
723 .Xr loader.conf 5 .
724 .It Pa /boot/loader.help
725 Loaded by
726 .Ic help .
727 Contains the help messages.
728 .It Pa /boot/loader.rc
730 bootstrapping script.
731 .It Pa /boot/forth/loader.4th
732 Extra builtin-like words.
733 .It Pa /boot/forth/support.4th
734 .Pa loader.conf
735 processing words.
736 .It Pa /boot/zfsloader
738 itself.
740 .Sh EXAMPLES
741 Boot in single user mode:
743 .Dl boot -s
745 Load the kernel, a boot_archive, and then autoboot in five seconds.
746 Notice that a kernel must be loaded before any other
747 .Ic load
748 command is attempted.
749 .Bd -literal -offset indent
750 load /platform/i86pc/kernel/amd64/unix
751 load -t rootfs /platform/i86pc/amd64/boot_archive
752 autoboot 5
754 .Sh SEE ALSO
755 .Xr boot 1M ,
756 .Xr btxld 1onbld ,
757 .Xr loader.conf 5
758 .Sh STANDARDS
759 For the purposes of ANS Forth compliance, loader is an
760 .Bf Em
761 ANS Forth System with Environmental Restrictions, Providing
763 .Bf Li
764 .No .( ,
765 .No :noname ,
766 .No ?do ,
767 parse, pick, roll, refill, to, value, \e, false, true,
768 .No <> ,
769 .No 0<> ,
770 compile\&, , erase, nip, tuck
772 .Em and
773 .Li marker
774 .Bf Em
775 from the Core Extensions word set, Providing the Exception Extensions
776 word set, Providing the Locals Extensions word set, Providing the
777 Memory-Allocation Extensions word set, Providing
779 .Bf Li
780 \&.s,
781 bye, forget, see, words,
782 \&[if],
783 \&[else]
785 .Em and
786 .Li [then]
787 .Bf Em
788 from the Programming-Tools extension word set, Providing the
789 Search-Order extensions word set.