Merge branch 'vendor/LDNS'
[dragonfly.git] / sys / boot / common / loader.8
1 .\"
2 .\" Copyright (c) 1999 Daniel C. Sobral
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD: src/sys/boot/common/loader.8,v 1.57 2003/06/29 20:57:55 brueffer Exp $
27 .\"
28 .Dd October 6, 2010
29 .Dt LOADER 8
30 .Os
31 .Sh NAME
32 .Nm loader
33 .Nd kernel bootstrapping final stage
34 .Sh DESCRIPTION
35 The program called
36 .Nm
37 is the final stage of
38 .Dx Ns 's
39 kernel bootstrapping process.
40 It is implemented as a
41 .Tn BTX
42 client and is linked statically to
43 .Xr libstand 3
44 and located in the
45 .Pa /boot
46 or
47 .Pa /
48 directory.
49 .Pp
50 If a
51 .Pa /boot
52 directory exist on the boot file system, then
53 .Dq /boot/
54 is prepended to all relative file names used by
55 .Nm .
56 This makes it possible to locate all files used by
57 .Nm
58 in either
59 .Pa /
60 or
61 .Pa /boot
62 directory on the boot file system.
63 If boot and root are the same file system, then files used by
64 .Nm
65 are located in
66 .Pa /boot .
67 If boot and root are different file systems, then files used by
68 .Nm
69 are located in
70 .Pa /
71 on the boot file system, which is mounted as
72 .Pa /boot
73 on the root file system when the kernel is running.
74 .Pp
75 During initialization,
76 .Nm
77 will probe for a console and set the
78 .Va console
79 variable, or set it to serial console
80 .Pq Dq comconsole
81 if the previous boot stage used that.
82 Then, devices are probed,
83 .Va currdev
84 and
85 .Va loaddev
86 are set, and
87 .Va LINES
88 is set to 24.
89 After that,
90 .Pa dloader.rc
91 is processed if available, and, failing that,
92 .Pa boot.conf
93 is read for historical reasons.
94 These files are processed through the
95 .Ic include
96 command, which reads all of them into memory before processing them,
97 making disk changes possible.
98 .Pp
99 At this point, if an
100 .Ic autoboot
101 has not been tried, and if
102 .Va autoboot_delay
103 is not set to
104 .Dq NO
105 (not case sensitive), then an
106 .Ic autoboot
107 will be tried.
108 If the system gets past this point,
109 .Va prompt
110 will be set and
111 .Nm
112 will engage interactive mode.
113 .Sh BUILTIN COMMANDS
114 In
115 .Nm ,
116 builtin commands take parameters from the command line.
117 .Pp
118 The builtin commands available are:
119 .Pp
120 .Bl -tag -width indent -compact
121 .It Ar variable Ns = Ns Ar value
122 Assign
123 .Ar value
124 to
125 .Ar variable .
126 The value is always assigned to a local variable
127 .Ar variable .
128 If
129 .Ar variable
130 is in the list of known kernel environment variables or is a kernel tunable,
131 the value is also assigned to the kernel environment variable of the
132 given name.
133 Local variables are unset if
134 .Ar value
135 is empty.
136 Kernel environment variables may have empty values.
137 .Pp
138 In other words, the assignment above will set a local variable and
139 if it is applicable, also assign
140 .Ar value
141 to the kernel environment variable, even if
142 .Ar value
143 is empty.
144 See also
145 .Sx ENVIRONMENT VARIABLES AND LOCAL VARIABLES .
146 .Pp
147 .It Ic autoboot Op Ar delay Op Ar prompt
148 Proceeds to bootstrap the system after a number of seconds, if not
149 interrupted by the user.
150 Displays a countdown prompt
151 warning the user the system is about to be booted,
152 unless interrupted by a key press.
153 The kernel will be loaded first if necessary.
154 Defaults to 10 seconds.
155 .Pp
156 .It Ic bcachestat
157 Displays statistics about disk cache usage.
158 For depuration only.
159 .Pp
160 .It Ic boot Oo Fl Ns Ar flag ... Oc Op Ar kernelname
161 Immediately proceeds to bootstrap the system, loading the kernel
162 if necessary.
163 Any flags or arguments are passed to the kernel, but they
164 must precede the kernel name, if a kernel name is provided.
165 Flags are described in
166 .Xr boot 8 .
167 See also
168 .Va boot_*
169 and
170 .Va kernel_options
171 variables.
172 .Pp
173 .It Ic cd Op Ar directory
174 Change working directory to
175 .Ar directory .
176 Default is $base.
177 .Pp
178 .It Ic echo Oo Fl n Oc Op Ar message
179 Displays text on the screen.
180 A new line will be printed unless
181 .Fl n
182 is specified.
183 .Pp
184 .It Ic else
185 Conditional if/else/endif.
186 .Pp
187 .It Ic elseifexists Ar path
188 Conditional
189 .Ar path
190 exists, i.e.\& file/dir present.
191 .Pp
192 .It Ic endif
193 Conditional if/else/endif.
194 .Pp
195 .It Ic heap
196 Displays memory usage statistics.
197 For debugging purposes only.
198 .Pp
199 .It Ic help Op Ar topic Op Ar subtopic
200 Shows help messages read from
201 .Pa loader.help .
202 The special
203 .Ar topic
204 .Cm index
205 will list all topics available.
206 .Pp
207 .It Ic ifexists Ar path
208 Conditional
209 Ar path
210 exists, i.e.\& file/dir present.
211 .Pp
212 .It Ic ifset Ar env_variable
213 Conditional
214 .Ar env_variable
215 exists.
216 .Pp
217 .It Ic include Ar
218 Process script files.
219 Each file, in turn, is completely read into memory,
220 and then each of its lines is passed to the command line interpreter.
221 If any error is returned by the interpreter, the include
222 command aborts immediately, without reading any other files, and
223 returns an error itself.
224 .Pp
225 .It Ic load Oo Fl t Ar type Oc Ar file Op Ar argument ...
226 Loads a kernel, kernel loadable module (kld), or file of opaque
227 contents tagged as being of the type
228 .Ar type .
229 Kernel and modules can be either in a.out or
230 .Tn ELF
231 format.
232 Any arguments passed after the name of the file to be loaded
233 will be passed as arguments to that file.
234 Currently, argument passing does not work for the kernel.
235 .Pp
236 .It Ic loadall
237 Load the kernel and all modules specified by MODULE_load variables.
238 .Pp
239 .It Ic local Op Ar local_variable ...
240 Displays the specified variable's value, or all local variables and their
241 values if
242 .Ar local_variable
243 is not specified.
244 .Pp
245 .It Ic ls Oo Fl l Oc Op Ar path
246 Displays a listing of files in the directory
247 .Ar path ,
248 or the root directory if
249 .Ar path
250 is not specified.
251 If
252 .Fl l
253 is specified, file sizes will be shown too.
254 .Pp
255 .It Ic lsdev Op Fl v
256 Lists all devices.
257 A
258 .Sq *
259 prefix indicates a disk slice or partition from which it may be
260 possible to load modules.
261 If
262 .Fl v
263 is specified, more details,
264 like disk slice or partition size and position, are printed.
265 .Pp
266 .It Ic lsmod Op Fl v
267 Displays loaded modules.
268 If
269 .Fl v
270 is specified, more details are shown.
271 .Pp
272 .It Ic lunset Ar local_variable
273 Unset a local variable.
274 Discards the value and removes the variable.
275 .Pp
276 .It Ic lunsetif Ar local_variable env_variable
277 Unset
278 .Ar local_variable
279 if
280 .Ar env_variable
281 is true, i.e.\& set to 1 or
282 .Ql YES .
283 .Pp
284 .It Ic menu
285 Run menu system.
286 .Pp
287 .It Ic menuadd Ar command_line
288 Add script line for the current menu item.
289 .Pp
290 .It Ic menuclear
291 Clear all menu items.
292 .Pp
293 .It Ic menuitem Ar key description
294 Start a new menu item.
295 When running the menu system, a line with
296 .Ar key
297 and
298 .Ar description
299 is displayed, and an item is chosen by pressing
300 .Ar key .
301 .Pp
302 .It Ic more Ar
303 Display the files specified, with a pause at each
304 .Va LINES
305 displayed.
306 .Pp
307 .It Ic optcd Op Ar directory
308 Change the working directory to
309 .Ar directory .
310 Default is $base.
311 Ignore errors.
312 This command is like
313 .Ic cd ,
314 but ignores errors when changing the directory.
315 .Pp
316 .It Ic optinclude Ar
317 Process script files.
318 Ignore errors.
319 This command is like
320 .Ic include ,
321 but ignores errors while executing commands in included files.
322 .Pp
323 .It Ic pnpscan Op Fl v
324 Scans for Plug-and-Play devices.
325 This is not functional at present.
326 .Pp
327 .It Ic pwd
328 Prints the working directory.
329 .Pp
330 .It Ic read Oo Fl t Ar seconds Oc Oo Fl p Ar prompt Oc Op Ar env_variable
331 Reads a line of input from the terminal, storing it in
332 .Ar env_variable
333 if specified.
334 A timeout can be specified with
335 .Fl t ,
336 though it will be canceled at the first key pressed.
337 A prompt may also be displayed through the
338 .Fl p
339 flag.
340 .Pp
341 .It Ic reboot
342 Immediately reboots the system.
343 .Pp
344 .It Ic set Ar env_variable
345 .It Ic set Ar env_variable Ns = Ns Ar value
346 Set
347 .Nm Ns 's
348 environment variables.
349 .Pp
350 .It Ic show Op Ar env_variable
351 Displays the specified kernel environment variable's value,
352 or all variables and their values if
353 .Ar env_variable
354 is not specified.
355 .Pp
356 .It Ic unload
357 Removes all modules from memory.
358 .Pp
359 .It Ic unset Ar env_variable
360 Removes
361 .Ar env_variable
362 from the environment.
363 .Pp
364 .It Ic \&?
365 Lists most available commands with a short help text for each.
366 .El
367 .Ss ENVIRONMENT VARIABLES AND LOCAL VARIABLES
368 The
369 .Nm
370 has actually two different kinds of variables.
371 There are
372 kernel environment variables, which are visible to the kernel when it is run,
373 and a separate space of local variables used by
374 .Nm ,
375 which are not available to the kernel.
376 .Pp
377 Environment variables can be set and unset through the
378 .Ic set
379 and
380 .Ic unset
381 builtins, and can have their values interactively examined through the
382 use of the
383 .Ic show
384 builtin.
385 .Pp
386 Notice that these environment variables are not inherited by any shell
387 after the system has been booted, but can be examined by
388 .Xr kenv 1 .
389 .Pp
390 A few variables are set automatically by
391 .Nm .
392 Others can affect the behavior of either
393 .Nm
394 or the kernel at boot.
395 Some options may require a value,
396 while others define behavior just by being set.
397 Both types of variables are described below.
398 .Bl -tag -width indent
399 .It Va acpi_load
400 Unset this to disable automatic loading of the ACPI module.
401 .It Va autoboot_delay
402 Number of seconds
403 .Ic autoboot
404 and
405 .Ic menu
406 will wait before booting.
407 Default value is 10 seconds.
408 .Pp
409 If set to
410 .Dq NO ,
411 no
412 .Ic autoboot
413 will be automatically attempted after processing
414 .Pa dloader.rc ,
415 though explicit
416 .Ic autoboot Ns 's
417 will be processed normally, defaulting to 10 seconds delay.
418 .It Va boot_askname
419 Instructs the kernel to prompt the user for the name of the root device
420 when the kernel is booted.
421 .It Va boot_ddb
422 Instructs the kernel to start in the DDB debugger, rather than
423 proceeding to initialize when booted.
424 .It Va boot_gdb
425 Selects gdb-remote mode for the kernel debugger by default.
426 .It Va boot_single
427 Prevents the kernel from initiating a multi-user startup; instead single-user
428 mode will be entered when the kernel has finished device probing.
429 .It Va boot_userconfig
430 Requests that the kernel's interactive device configuration program
431 be run when the kernel is booted.
432 .It Va boot_verbose
433 Setting this variable causes extra debugging information to be printed
434 by the kernel during and after the boot phase.
435 .It Va bootfile
436 List of semicolon-separated search path for bootable kernels.
437 The default is
438 .Dq Li kernel .
439 .It Va console
440 Defines the current console.
441 .It Va currdev
442 Selects the default device.
443 Syntax for devices is odd.
444 .It Va default_kernel
445 Selects default kernel loaded by
446 .Ic menu
447 command.
448 .It Va ehci_load
449 Unset this to disable automatic loading of the EHCI module.
450 .It Va init_path
451 Sets the list of binaries which the kernel will try to run as the initial
452 process.
453 The first matching binary is used.
454 The default list is
455 .Dq Li /sbin/init:/sbin/oinit:/sbin/init.bak .
456 .It Va kernel_options
457 Set kernel boot flags.
458 See also
459 .Ic boot
460 command.
461 .It Va LINES
462 Define the number of lines on the screen, to be used by the pager.
463 .It Va module_path
464 Sets the list of directories which will be searched for modules named in a
465 .Nm load
466 command or implicitly required by a dependency.
467 The default value for this variable is
468 .Dq Li ;modules ,
469 which first searches the current working directory and then
470 .Pa modules .
471 .It Va num_ide_disks
472 Sets the number of IDE disks as a workaround for some problems in
473 finding the root disk at boot.
474 This has been deprecated in favor of
475 .Va root_disk_unit .
476 .It Va prompt
477 Value of
478 .Nm Ns 's
479 prompt.
480 Defaults to
481 .Dq Li OK .
482 .It Va root_disk_unit
483 If the code which detects the disk unit number for the root disk is
484 confused, e.g.\& by a mix of
485 .Tn SCSI
486 and
487 .Tn IDE
488 disks, or
489 .Tn IDE
490 disks with
491 gaps in the sequence (e.g.\& no primary slave), the unit number can
492 be forced by setting this variable.
493 .It Va rootdev
494 By default the value of
495 .Va currdev
496 is used to set the root file system
497 when the kernel is booted.
498 This can be overridden by setting
499 .Va rootdev
500 explicitly.
501 .It Va dumpdev
502 The name of a device where the kernel can save a crash dump in case
503 of a panic.
504 This automatically sets the
505 .Va kern.dumpdev
506 .Xr sysctl 3
507 .Tn MIB
508 variable.
509 .El
510 .Pp
511 Other variables are used to override kernel tunable parameters.
512 The following
513 .Nm
514 tunables are available:
515 .Bl -tag -width indent
516 .It Va hw.irq.X.dest
517 Set irqX's destination to the given
518 .Tn CPUID ,
519 which starts from 0.
520 If the specified value is larger than the last
521 .Tn CPUID ,
522 then the first
523 .Tn CPUID
524 will be used.
525 This variable should not be used if
526 .Tn IO/APIC
527 support is not compiled into kernel.
528 .It Va hw.physmem
529 Limit the amount of physical memory the system will use.
530 By default the size is in bytes, but the
531 .Cm k , K , m , M , g
532 and
533 .Cm G
534 suffixes
535 are also accepted and indicate kilobytes, megabytes and gigabytes
536 respectively.
537 An invalid suffix will result in the variable being ignored by the
538 kernel.
539 .It Va hw.usb.hack_defer_exploration
540 The USB keyboard will sometimes not attach properly unless you set this
541 variable to 0.
542 .It Va kern.emergency_intr_enable
543 Setting this to 1 enables emergency interrupt polling.
544 All interrupt handlers are executed periodically.
545 This mode is very expensive and should
546 only be used to get a system accessible when interrupt routing is
547 otherwise broken.
548 It is primarily used by kernel developers to debug new systems.
549 .It Va kern.emergency_intr_freq
550 Set the polling rate for the emergency interrupt polling code.
551 The default is 10 (hz) to dissuade casual use.
552 If you are doing real work
553 with emergency interrupt polling mode enabled, it is recommended
554 that you use a frequency between 100hz and 300hz.
555 .It Va kern.maxusers
556 Set the size of a number of statically allocated system tables; see
557 .Xr tuning 7
558 for a description of how to select an appropriate value for this tunable.
559 When set, this tunable replaces the value declared in the kernel
560 compile-time configuration file.
561 .It Va kern.ipc.nmbclusters
562 Set the number of mbuf clusters to be allocated.
563 The value cannot be set below the default
564 determined when the kernel was compiled.
565 Modifies
566 .Va NMBCLUSTERS .
567 .It Va kern.mmxopt
568 Toggles the mmx optimizations for the bcopy/copyin/copyout routines
569 .It Va kern.vm.kmem.size
570 Sets the size of kernel memory (bytes).
571 This overrides the value determined when the kernel was compiled.
572 .It Va kern.maxswzone
573 Limits the amount of
574 .Tn KVM
575 to be used to hold swap
576 meta information, which directly governs the
577 maximum amount of swap the system can support.
578 This value is specified in bytes of KVA space
579 and defaults to around 70MBytes.
580 Care should be taken
581 to not reduce this value such that the actual
582 amount of configured swap exceeds \(12 the
583 kernel-supported swap.
584 The default 70MB allows
585 the kernel to support a maximum of (approximately)
586 14GB of configured swap.
587 Only mess around with
588 this parameter if you need to greatly extend the
589 .Tn KVM
590 reservation for other resources such as the
591 buffer cache or
592 .Va NMBCLUSTERS .
593 Modifies
594 .Va VM_SWZONE_SIZE_MAX .
595 .It Va kern.maxbcache
596 Limits the amount of KVM reserved for use by the
597 buffer cache, specified in bytes.
598 The default maximum is 200MB.
599 This parameter is used to
600 prevent the buffer cache from eating too much
601 .Tn KVM
602 in large-memory machine configurations.
603 Only mess around with this parameter if you need to
604 greatly extend the
605 .Tn KVM
606 reservation for other resources
607 such as the swap zone or
608 .Va NMBCLUSTERS .
609 Note that
610 the NBUF parameter will override this limit.
611 Modifies
612 .Va VM_BCACHE_SIZE_MAX .
613 .It Va machdep.disable_mtrrs
614 Disable the use of
615 .Sy i686
616 .Tn MTRRs
617 (x86 only).
618 .It Va net.inet.tcp.tcbhashsize
619 Overrides the compile-time set value of
620 .Va TCBHASHSIZE
621 or the preset default of 512.
622 Must be a power of 2.
623 .It Va vfs.root.mountfrom
624 Specify root file system.
625 A semicolon separated list of file systems to try
626 as the kernel root file system.
627 File system format is file system type and disk store,
628 separated by colon.
629 This variable needs to be set when using a boot-only partition, which is
630 typically mounted on root file system as
631 .Pa /boot .
632 .Pp
633 One file system example:
634 .Dl hammer:da8s1a
635 .Pp
636 One file system
637 .Nm HAMMER
638 multi volume example:
639 .Dl hammer:da8s1a:da9s1a
640 .Pp
641 Several file systems, boot list, example:
642 .Dl ufs:da0s1a;hammer:ad1s1d
643 .Pp
644 Each file system in the list will be tried in the order specified
645 until the mount succeeds.
646 If all fail, the
647 .Ql mountroot>
648 prompt is displayed for manual entry.
649 .Pp
650 You may not specify devtab labels here but you can specify paths available to
651 .Xr devfs 5
652 such as:
653 .Dl hammer:serno/L41JYE0G.s1d
654 .El
655 .Sh FILES
656 .Bl -tag -width /boot/defaults/dloader.menu -compact
657 .It Pa /boot/boot.conf
658 .Nm
659 bootstrapping script.
660 Deprecated.
661 .It Pa /boot/loader
662 .Nm
663 itself.
664 .It Pa /boot/defaults/dloader.menu
665 .Nm
666 menu setup commands -- do not change this file.
667 .It Pa /boot/defaults/loader.conf
668 .Nm
669 configuration file, see
670 .Xr loader.conf 5
671 -- do not change this file.
672 .It Pa /boot/dloader.menu
673 .Nm
674 menu setup commands.
675 .It Pa /boot/dloader.rc
676 .Nm
677 bootstrapping script.
678 .It Pa /boot/loader.conf
679 .It Pa /boot/loader.conf.local
680 .Nm
681 configuration files, see
682 .Xr loader.conf 5 .
683 .It Pa /boot/loader.help
684 help messages, used by the
685 .Ic help
686 command.
687 .El
688 .Sh EXAMPLES
689 Boot in single user mode:
690 .Pp
691 .Dl loadall
692 .Dl boot -s
693 .Pp
694 Load kernel's user configuration file.
695 Notice that a kernel must be loaded before any other
696 .Ic load
697 command is attempted.
698 .Bd -literal -offset indent
699 load kernel
700 load -t userconfig_script kernel.conf
701 .Ed
702 .Pp
703 Load the kernel, a splash screen, and then autoboot in five seconds.
704 .Bd -literal -offset indent
705 load kernel
706 load splash_bmp
707 load -t splash_image_data chuckrulez.bmp
708 autoboot 5
709 .Ed
710 .Pp
711 Set the disk unit of the root device to 2, and then boot.
712 This would be needed in a system with two IDE disks,
713 with the second IDE disk hardwired to
714 .Pa ad2
715 instead of
716 .Pa ad1 .
717 .Bd -literal -offset indent
718 set root_disk_unit=2
719 boot kernel
720 .Ed
721 .Sh SEE ALSO
722 .Xr libstand 3 ,
723 .Xr loader.conf 5 ,
724 .Xr tuning 7 ,
725 .Xr boot 8 ,
726 .Xr btxld 8 ,
727 .Xr pxeboot 8 ,
728 .Xr pxeboot_tftp 8 ,
729 .Xr sysctl 8
730 .Sh HISTORY
731 The
732 .Nm
733 first appeared in
734 .Fx 3.1 .
735 .Nm dloader
736 was introduced and
737 .Tn FORTH
738 removed in
739 .Dx 2.7 .
740 .Sh AUTHORS
741 .An -nosplit
742 The
743 .Nm
744 was written by
745 .An Michael Smith Aq msmith@FreeBSD.org .
746 .Pp
747 .Nm dloader
748 was written by
749 .An Matthew Dillon Aq dillon@backplane.com .