loader: rename zfsloader to loader
[unleashed.git] / share / man / man5 / loader.5
blobb954897adc30cad06e05be186aea7317d6e88e80
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 July 24, 2018
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 loader .
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.
253 In addition to disks and partitions, ZFS pools are also listed.
255 .Fl v
256 is specified, more details are printed.
257 For ZFS pools the output resembles
258 .Nm zpool Cm status
259 output.
261 .It Ic lsmod Op Fl v
262 Displays loaded modules.
264 .Fl v
265 is specified, more details are shown.
267 .It Ic lszfs Ar filesystem
268 A ZFS extended command that can be used to explore the ZFS filesystem
269 hierarchy in a pool.
270 Lists the immediate children of the
271 .Ar filesystem .
272 The filesystem hierarchy is rooted at a filesystem with the same name
273 as the pool.
275 .It Ic more Ar file Op Ar
276 Display the files specified, with a pause at each
277 .Va LINES
278 displayed.
280 .It Ic read Xo
281 .Op Fl t Ar seconds
282 .Op Fl p Ar prompt
283 .Op Va variable
285 Reads a line of input from the terminal, storing it in
286 .Va variable
287 if specified.
288 A timeout can be specified with
289 .Fl t ,
290 though it will be canceled at the first key pressed.
291 A prompt may also be displayed through the
292 .Fl p
293 flag.
295 .It Ic reboot
296 Immediately reboots the system.
298 .It Ic set Ar variable
299 .It Ic set Ar variable Ns = Ns Ar value
300 Set loader's environment variables.
302 .It Ic show Op Va variable
303 Displays the specified variable's value, or all variables and their
304 values if
305 .Va variable
306 is not specified.
308 .It Ic unload
309 Remove all modules from memory.
311 .It Ic unset Va variable
312 Removes
313 .Va variable
314 from the environment.
316 .It Ic \&?
317 Lists available commands.
319 .Ss ZFS Features
321 supports the following format for specifying ZFS filesystems which
322 can be used wherever
324 refers to a device specification:
326 .Ar zfs:pool/filesystem:
328 where
329 .Pa pool/filesystem
330 is a ZFS filesystem name as described in
331 .Xr zfs 1M .
332 .Ss Builtin Environment Variables
335 has actually two different kinds of
336 .Sq environment
337 variables.
338 There are ANS Forth's
339 .Em environmental queries ,
340 and a separate space of environment variables used by builtins, which
341 are not directly available to Forth words.
342 It is the latter type that this section covers.
344 Environment variables can be set and unset through the
345 .Ic set
347 .Ic unset
348 builtins, and can have their values interactively examined through the
349 use of the
350 .Ic show
351 builtin.
352 Their values can also be accessed as described in
353 .Sx BUILTIN PARSER .
355 Notice that these environment variables are not inherited by any shell
356 after the system has been booted.
358 A few variables are set automatically by
359 .Nm .
360 Others can affect the behavior of either
362 or the kernel at boot.
363 Some options may require a value,
364 while others define behavior just by being set.
365 Both types of builtin variables are described below.
366 .Bl -tag -width bootfile
367 .It Va autoboot_delay
368 Number of seconds
369 .Ic autoboot
370 will wait before booting.
371 If this variable is not defined,
372 .Ic autoboot
373 will default to 10 seconds.
375 If set to
376 .Dq Li NO ,
378 .Ic autoboot
379 will be automatically attempted after processing
380 .Pa /boot/loader.rc ,
381 though explicit
382 .Ic autoboot Ns 's
383 will be processed normally, defaulting to 10 seconds delay.
385 If set to
386 .Dq Li 0 ,
387 no delay will be inserted, but user still will be able to interrupt
388 .Ic autoboot
389 process and escape into the interactive mode by pressing some key
390 on the console while kernel and
391 modules are being loaded.
393 If set to
394 .Dq Li -1 ,
395 no delay will be inserted and
397 will engage interactive mode only if
398 .Ic autoboot
399 has failed for some reason.
400 .It Va boot_ask
401 Will set
402 .Xr kernel 8
403 .Fl a
404 option.
405 .It Va boot_debug
406 Will set
407 .Xr kernel 8
408 .Fl d
409 option.
410 .It Va boot_kmdb
411 Will set
412 .Xr kernel 8
413 .Fl k
414 option.
415 .It Va boot_reconfigure
416 Will set
417 .Xr kernel 8
418 .Fl r
419 option.
420 .It Va boot_single
421 Will set
422 .Xr kernel 8
423 .Fl s
424 option.
425 .It Va boot_verbose
426 Will set
427 .Xr kernel 8
428 .Fl v
429 option.
430 .It Va boot-args
431 Will set custom arguments for the kernel.
432 If set in
434 configuration, the
436 startup will parse the
437 .Va boot-args
438 value to set boot prefixed variables listed above, any unrecognized options
439 are added to kernel command line verbatim.
440 .It Va bootfile
441 The name of the kernel.
442 .It Va console
443 Defines the current console or consoles.
444 Multiple consoles may be specified.
445 In that case, the first listed console will become the default console for
447 .Xr kernel 8 .
448 .It Va currdev
449 Selects the default device.
450 Syntax for devices is odd.
451 .It Va interpret
452 Has the value
453 .Dq Li ok
454 if the Forth's current state is interpreting.
455 .It Va LINES
456 Define the number of lines on the screen, to be used by the pager.
457 .It Va module_path
458 Sets the list of directories which will be searched for modules
459 named in a load command or implicitly required by a dependency.
460 The default value for this variable is
461 .Dq Li /platform/i86pc/${ISADIR}
462 .It Va prompt
463 Value of
464 .Nm Ns 's
465 prompt.
466 Defaults to
467 .Dq Li "${interpret}" .
468 If variable
469 .Va prompt
470 is unset, the default prompt is
471 .Ql > .
472 .It Va os_console
473 If set, the value is used to set
474 .Xr kernel 8
475 .Va console
476 property.
479 Other variables are used for loader or to set kernel properties or for
480 informational purposes.
481 .Ss Builtin Parser
482 When a builtin command is executed, the rest of the line is taken
483 by it as arguments, and it is processed by a special parser which
484 is not used for regular Forth commands.
486 This special parser applies the following rules to the parsed text:
487 .Bl -enum
489 All backslash characters are preprocessed.
490 .Bl -bullet
492 \eb , \ef , \er , \en and \et are processed as in C.
494 \es is converted to a space.
496 \ev is converted to
497 .Tn ASCII
500 \ez is just skipped.
501 Useful for things like
502 .Dq \e0xf\ez\e0xf .
504 \e0xN and \e0xNN are replaced by the hex N or NN.
506 \eNNN is replaced by the octal NNN
507 .Tn ASCII
508 character.
510 \e" , \e' and \e$ will escape these characters, preventing them from
511 receiving special treatment in Step 2, described below.
513 \e\e will be replaced with a single \e .
515 In any other occurrence, backslash will just be removed.
518 Every string between non-escaped quotes or double-quotes will be treated
519 as a single word for the purposes of the remaining steps.
521 Replace any
522 .Li $VARIABLE
524 .Li ${VARIABLE}
525 with the value of the environment variable
526 .Va VARIABLE .
528 Space-delimited arguments are passed to the called builtin command.
529 Spaces can also be escaped through the use of \e\e .
532 An exception to this parsing rule exists, and is described in
533 .Sx Builtins And FORTH .
534 .Ss Builtins And FORTH
535 All builtin words are state-smart, immediate words.
536 If interpreted, they behave exactly as described previously.
537 If they are compiled, though,
538 they extract their arguments from the stack instead of the command line.
540 If compiled, the builtin words expect to find, at execution time, the
541 following parameters on the stack:
542 .D1 Ar addrN lenN ... addr2 len2 addr1 len1 N
543 where
544 .Ar addrX lenX
545 are strings which will compose the command line that will be parsed
546 into the builtin's arguments.
547 Internally, these strings are concatenated in from 1 to N,
548 with a space put between each one.
550 If no arguments are passed, a 0
551 .Em must
552 be passed, even if the builtin accepts no arguments.
554 While this behavior has benefits, it has its trade-offs.
555 If the execution token of a builtin is acquired (through
556 .Ic '
558 .Ic ['] ) ,
559 and then passed to
560 .Ic catch
562 .Ic execute ,
563 the builtin behavior will depend on the system state
564 .Bf Em
565 at the time
566 .Ic catch
568 .Ic execute
569 is processed!
571 This is particularly annoying for programs that want or need to
572 handle exceptions.
573 In this case, the use of a proxy is recommended.
574 For example:
575 .Dl : (boot) boot ;
576 .Ss FICL
577 .Tn FICL
578 is a Forth interpreter written in C, in the form of a forth
579 virtual machine library that can be called by C functions and vice
580 versa.
583 .Nm ,
584 each line read interactively is then fed to
585 .Tn FICL ,
586 which may call
588 back to execute the builtin words.
589 The builtin
590 .Ic include
591 will also feed
592 .Tn FICL ,
593 one line at a time.
595 The words available to
596 .Tn FICL
597 can be classified into four groups.
599 .Tn ANS
600 Forth standard words, extra
601 .Tn FICL
602 words, extra
604 words, and the builtin commands;
605 the latter were already described.
607 .Tn ANS
608 Forth standard words are listed in the
609 .Sx STANDARDS
610 section.
611 The words falling in the two other groups are described in the
612 following subsections.
613 .Ss FICL Extra Words
614 .Bl -tag -width wid-set-super
615 .It Ic .env
616 .It Ic .ver
617 .It Ic -roll
618 .It Ic 2constant
619 .It Ic >name
620 .It Ic body>
621 .It Ic compare
622 This is the STRING word set's
623 .Ic compare .
624 .It Ic compile-only
625 .It Ic endif
626 .It Ic forget-wid
627 .It Ic parse-word
628 .It Ic sliteral
629 This is the STRING word set's
630 .Ic sliteral .
631 .It Ic wid-set-super
632 .It Ic w@
633 .It Ic w!
634 .It Ic x.
635 .It Ic empty
636 .It Ic cell-
637 .It Ic -rot
639 .Ss Loader Extra Words
640 .Bl -tag -width XXXXXXXX
641 .It Ic \&$ Pq --
642 Evaluates the remainder of the input buffer, after having printed it first.
643 .It Ic \&% Pq --
644 Evaluates the remainder of the input buffer under a
645 .Ic catch
646 exception guard.
647 .It Ic .#
648 Works like
649 .Ic "."
650 but without outputting a trailing space.
651 .It Ic fclose Pq Ar fd --
652 Closes a file.
653 .It Ic fkey Pq Ar fd -- char
654 Reads a single character from a file.
655 .It Ic fload Pq Ar fd --
656 Processes a file
657 .Em fd .
658 .It Ic fopen Pq Ar addr len mode Li -- Ar fd
659 Opens a file.
660 Returns a file descriptor, or \-1 in case of failure.
662 .Ar mode
663 parameter selects whether the file is to be opened for read access, write
664 access, or both.
665 The constants
666 .Dv O_RDONLY , O_WRONLY ,
668 .Dv O_RDWR
669 are defined in
670 .Pa /boot/forth/support.4th ,
671 indicating read only, write only, and read-write access, respectively.
672 .It Xo
673 .Ic fread
674 .Pq Ar fd addr len -- len'
676 Tries to read
677 .Em len
678 bytes from file
679 .Em fd
680 into buffer
681 .Em addr .
682 Returns the actual number of bytes read, or -1 in case of error or end of
683 file.
684 .It Ic heap? Pq -- Ar cells
685 Return the space remaining in the dictionary heap, in cells.
686 This is not related to the heap used by dynamic memory allocation words.
687 .It Ic inb Pq Ar port -- char
688 Reads a byte from a port.
689 .It Ic key Pq -- Ar char
690 Reads a single character from the console.
691 .It Ic key? Pq -- Ar flag
692 Returns
693 .Ic true
694 if there is a character available to be read from the console.
695 .It Ic ms Pq Ar u --
696 Waits
697 .Em u
698 microseconds.
699 .It Ic outb Pq Ar port char --
700 Writes a byte to a port.
701 .It Ic seconds Pq -- Ar u
702 Returns the number of seconds since midnight.
703 .It Ic tib> Pq -- Ar addr len
704 Returns the remainder of the input buffer as a string on the stack.
706 .Ss Loader Defined Environmental Queries
707 .Bl -tag -width Ds
708 .It arch-i386
709 .Ic TRUE
710 if the architecture is IA32.
711 .It loader_version
713 version.
715 .Ss Errors
716 The following values are thrown by
717 .Nm :
718 .Bl -tag -width XXXXX -offset indent
719 .It 100
720 Any type of error in the processing of a builtin.
721 .It -1
722 .Ic Abort
723 executed.
724 .It -2
725 .Ic Abort"
726 executed.
727 .It -56
728 .Ic Quit
729 executed.
730 .It -256
731 Out of interpreting text.
732 .It -257
733 Need more text to succeed -- will finish on next run.
734 .It -258
735 .Ic Bye
736 executed.
737 .It -259
738 Unspecified error.
740 .Sh FILES
741 .Bl -tag -width /boot/defaults/loader.conf -compact
742 .It Pa /boot/defaults/loader.conf
743 .It Pa /boot/conf.d/*
744 .It Pa /boot/loader.conf
745 .It Pa /boot/loader.conf.local
747 configuration files, as described in
748 .Xr loader.conf 4 .
749 .It Pa /boot/loader.help
750 Loaded by
751 .Ic help .
752 Contains the help messages.
753 .It Pa /boot/loader.rc
755 bootstrapping script.
756 .It Pa /boot/forth/loader.4th
757 Extra builtin-like words.
758 .It Pa /boot/forth/support.4th
759 .Pa loader.conf
760 processing words.
761 .It Pa /boot/loader
763 itself.
765 .Sh EXAMPLES
766 Boot in single user mode:
768 .Dl boot -s
770 Load the kernel, a boot_archive, and then autoboot in five seconds.
771 Notice that a kernel must be loaded before any other
772 .Ic load
773 command is attempted.
774 .Bd -literal -offset indent
775 load /platform/i86pc/kernel/amd64/unix
776 load -t rootfs /platform/i86pc/amd64/boot_archive
777 autoboot 5
780 Set the default device used for loading a kernel from a ZFS filesystem:
781 .Bd -literal -offset indent
782 set currdev=zfs:rpool/ROOT/knowngood:
784 .Sh NOTES
785 Although setting the
786 .Va currdev
787 as shown in the example above is supported, it is advisable to use loader
788 beadm command or boot environment menu instead.
789 The reason is, the beadm or menu selection will also instruct loader to clean up
790 the currently set configuration and load configuration from the new boot
791 environment.
792 .Sh SEE ALSO
793 .Xr boot 8 ,
794 .Xr loader.conf 4
795 .Sh STANDARDS
796 For the purposes of ANS Forth compliance, loader is an
797 .Bf Em
798 ANS Forth System with Environmental Restrictions, Providing
800 .Bf Li
801 .No .( ,
802 .No :noname ,
803 .No ?do ,
804 parse, pick, roll, refill, to, value, \e, false, true,
805 .No <> ,
806 .No 0<> ,
807 compile\&, , erase, nip, tuck
809 .Em and
810 .Li marker
811 .Bf Em
812 from the Core Extensions word set, Providing the Exception Extensions
813 word set, Providing the Locals Extensions word set, Providing the
814 Memory-Allocation Extensions word set, Providing
816 .Bf Li
817 \&.s,
818 bye, forget, see, words,
819 \&[if],
820 \&[else]
822 .Em and
823 .Li [then]
824 .Bf Em
825 from the Programming-Tools extension word set, Providing the
826 Search-Order extensions word set.