df7015680b3d4acf44abaad943351db4f3ce1797
[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 .Pp
168 .It Ic cd Op Ar directory
169 Change working directory to
170 .Ar directory .
171 Default is $base.
172 .Pp
173 .It Ic echo Oo Fl n Oc Op Ar message
174 Displays text on the screen.
175 A new line will be printed unless
176 .Fl n
177 is specified.
178 .Pp
179 .It Ic heap
180 Displays memory usage statistics.
181 For debugging purposes only.
182 .Pp
183 .It Ic help Op Ar topic Op Ar subtopic
184 Shows help messages read from
185 .Pa loader.help .
186 The special
187 .Ar topic
188 .Cm index
189 will list all topics available.
190 .Pp
191 .It Ic include Ar
192 Process script files.
193 Each file, in turn, is completely read into memory,
194 and then each of its lines is passed to the command line interpreter.
195 If any error is returned by the interpreter, the include
196 command aborts immediately, without reading any other files, and
197 returns an error itself.
198 .Pp
199 .It Ic load Oo Fl t Ar type Oc Ar file Op Ar argument ...
200 Loads a kernel, kernel loadable module (kld), or file of opaque
201 contents tagged as being of the type
202 .Ar type .
203 Kernel and modules can be either in a.out or
204 .Tn ELF
205 format.
206 Any arguments passed after the name of the file to be loaded
207 will be passed as arguments to that file.
208 Currently, argument passing does not work for the kernel.
209 .Pp
210 .It Ic loadall
211 Load the kernel and all modules specified by MODULE_load variables.
212 .Pp
213 .It Ic local Op Ar local_variable ...
214 Displays the specified variable's value, or all local variables and their
215 values if
216 .Ar local_variable
217 is not specified.
218 .Pp
219 .It Ic ls Oo Fl l Oc Op Ar path
220 Displays a listing of files in the directory
221 .Ar path ,
222 or the root directory if
223 .Ar path
224 is not specified.
225 If
226 .Fl l
227 is specified, file sizes will be shown too.
228 .Pp
229 .It Ic lsdev Op Fl v
230 Lists all devices.
231 A
232 .Sq *
233 prefix indicates a disk slice or partition from which it may be
234 possible to load modules.
235 If
236 .Fl v
237 is specified, more details,
238 like disk slice or partition size and position, are printed.
239 .Pp
240 .It Ic lsmod Op Fl v
241 Displays loaded modules.
242 If
243 .Fl v
244 is specified, more details are shown.
245 .Pp
246 .It Ic lunset Ar local_variable
247 Unset a local variable.
248 Discards the value and removes the variable.
249 .Pp
250 .It Ic lunsetif Ar local_variable env_variable
251 Unset
252 .Ar local_variable
253 if
254 .Ar env_variable
255 is true, i.e.\& set to 1 or
256 .Ql YES .
257 .Pp
258 .It Ic menu
259 Run menu system.
260 .Pp
261 .It Ic menuadd Ar command_line
262 Add script line for the current menu item.
263 .Pp
264 .It Ic menuclear
265 Clear all menu items.
266 .Pp
267 .It Ic menuitem Ar key description
268 Start a new menu item.
269 When running the menu system, a line with
270 .Ar key
271 and
272 .Ar description
273 is displayed, and an item is chosen by pressing
274 .Ar key .
275 .Pp
276 .It Ic more Ar
277 Display the files specified, with a pause at each
278 .Va LINES
279 displayed.
280 .Pp
281 .It Ic optcd Op Ar directory
282 Change the working directory to
283 .Ar directory .
284 Default is $base.
285 Ignore errors.
286 This command is like
287 .Ic cd ,
288 but ignores errors when changing the directory.
289 .Pp
290 .It Ic optinclude Ar
291 Process script files.
292 Ignore errors.
293 This command is like
294 .Ic include ,
295 but ignores errors while executing commands in included files.
296 .Pp
297 .It Ic pnpscan Op Fl v
298 Scans for Plug-and-Play devices.
299 This is not functional at present.
300 .Pp
301 .It Ic pwd
302 Prints the working directory.
303 .Pp
304 .It Ic read Oo Fl t Ar seconds Oc Oo Fl p Ar prompt Oc Op Ar env_variable
305 Reads a line of input from the terminal, storing it in
306 .Ar env_variable
307 if specified.
308 A timeout can be specified with
309 .Fl t ,
310 though it will be canceled at the first key pressed.
311 A prompt may also be displayed through the
312 .Fl p
313 flag.
314 .Pp
315 .It Ic reboot
316 Immediately reboots the system.
317 .Pp
318 .It Ic set Ar env_variable
319 .It Ic set Ar env_variable Ns = Ns Ar value
320 Set
321 .Nm Ns 's
322 environment variables.
323 .Pp
324 .It Ic show Op Ar env_variable
325 Displays the specified kernel environment variable's value,
326 or all variables and their values if
327 .Ar env_variable
328 is not specified.
329 .Pp
330 .It Ic unload
331 Removes all modules from memory.
332 .Pp
333 .It Ic unset Ar env_variable
334 Removes
335 .Ar env_variable
336 from the environment.
337 .Pp
338 .It Ic \&?
339 Lists most available commands with a short help text for each.
340 .El
341 .Ss ENVIRONMENT VARIABLES AND LOCAL VARIABLES
342 The
343 .Nm
344 has actually two different kinds of variables.
345 There are
346 kernel environment variables, which are visible to the kernel when it is run,
347 and a separate space of local variables used by
348 .Nm ,
349 which are not available to the kernel.
350 .Pp
351 Environment variables can be set and unset through the
352 .Ic set
353 and
354 .Ic unset
355 builtins, and can have their values interactively examined through the
356 use of the
357 .Ic show
358 builtin.
359 .Pp
360 Notice that these environment variables are not inherited by any shell
361 after the system has been booted, but can be examined by
362 .Xr kenv 1 .
363 .Pp
364 A few variables are set automatically by
365 .Nm .
366 Others can affect the behavior of either
367 .Nm
368 or the kernel at boot.
369 Some options may require a value,
370 while others define behavior just by being set.
371 Both types of variables are described below.
372 .Bl -tag -width indent
373 .It Va acpi_load
374 Unset this to disable automatic loading of the ACPI module.
375 .It Va autoboot_delay
376 Number of seconds
377 .Ic autoboot
378 will wait before booting.
379 If this variable is not defined,
380 .Ic autoboot
381 will default to 10 seconds.
382 .Pp
383 If set to
384 .Dq NO ,
385 no
386 .Ic autoboot
387 will be automatically attempted after processing
388 .Pa dloader.rc ,
389 though explicit
390 .Ic autoboot Ns 's
391 will be processed normally, defaulting to 10 seconds delay.
392 .It Va boot_askname
393 Instructs the kernel to prompt the user for the name of the root device
394 when the kernel is booted.
395 .It Va boot_ddb
396 Instructs the kernel to start in the DDB debugger, rather than
397 proceeding to initialize when booted.
398 .It Va boot_gdb
399 Selects gdb-remote mode for the kernel debugger by default.
400 .It Va boot_single
401 Prevents the kernel from initiating a multi-user startup; instead single-user
402 mode will be entered when the kernel has finished device probing.
403 .It Va boot_userconfig
404 Requests that the kernel's interactive device configuration program
405 be run when the kernel is booted.
406 .It Va boot_verbose
407 Setting this variable causes extra debugging information to be printed
408 by the kernel during and after the boot phase.
409 .It Va bootfile
410 List of semicolon-separated search path for bootable kernels.
411 The default is
412 .Dq Li kernel;kernel.old .
413 .It Va console
414 Defines the current console.
415 .It Va currdev
416 Selects the default device.
417 Syntax for devices is odd.
418 .It Va ehci_load
419 Unset this to disable automatic loading of the EHCI module.
420 .It Va init_path
421 Sets the list of binaries which the kernel will try to run as the initial
422 process.
423 The first matching binary is used.
424 The default list is
425 .Dq Li /sbin/init:/sbin/oinit:/sbin/init.bak .
426 .It Va LINES
427 Define the number of lines on the screen, to be used by the pager.
428 .It Va module_path
429 Sets the list of directories which will be searched for modules named in a
430 .Nm load
431 command or implicitly required by a dependency.
432 The default value for this variable is
433 .Dq Li ;modules ,
434 which first searches the current working directory and then
435 .Pa modules .
436 .It Va num_ide_disks
437 Sets the number of IDE disks as a workaround for some problems in
438 finding the root disk at boot.
439 This has been deprecated in favor of
440 .Va root_disk_unit .
441 .It Va prompt
442 Value of
443 .Nm Ns 's
444 prompt.
445 Defaults to
446 .Dq Li OK .
447 .It Va root_disk_unit
448 If the code which detects the disk unit number for the root disk is
449 confused, e.g.\& by a mix of
450 .Tn SCSI
451 and
452 .Tn IDE
453 disks, or
454 .Tn IDE
455 disks with
456 gaps in the sequence (e.g.\& no primary slave), the unit number can
457 be forced by setting this variable.
458 .It Va rootdev
459 By default the value of
460 .Va currdev
461 is used to set the root file system
462 when the kernel is booted.
463 This can be overridden by setting
464 .Va rootdev
465 explicitly.
466 .It Va dumpdev
467 The name of a device where the kernel can save a crash dump in case
468 of a panic.
469 This automatically sets the
470 .Va kern.dumpdev
471 .Xr sysctl 3
472 .Tn MIB
473 variable.
474 .El
475 .Pp
476 Other variables are used to override kernel tunable parameters.
477 The following
478 .Nm
479 tunables are available:
480 .Bl -tag -width indent
481 .It Va hw.irq.X.dest
482 Set irqX's destination to the given
483 .Tn CPUID ,
484 which starts from 0.
485 If the specified value is larger than the last
486 .Tn CPUID ,
487 then the first
488 .Tn CPUID
489 will be used.
490 This variable should not be used if
491 .Tn IO/APIC
492 support is not compiled into kernel.
493 .It Va hw.physmem
494 Limit the amount of physical memory the system will use.
495 By default the size is in bytes, but the
496 .Cm k , K , m , M , g
497 and
498 .Cm G
499 suffixes
500 are also accepted and indicate kilobytes, megabytes and gigabytes
501 respectively.
502 An invalid suffix will result in the variable being ignored by the
503 kernel.
504 .It Va hw.usb.hack_defer_exploration
505 The USB keyboard will sometimes not attach properly unless you set this
506 variable to 0.
507 .It Va kern.emergency_intr_enable
508 Setting this to 1 enables emergency interrupt polling.
509 All interrupt handlers are executed periodically.
510 This mode is very expensive and should
511 only be used to get a system accessible when interrupt routing is
512 otherwise broken.
513 It is primarily used by kernel developers to debug new systems.
514 .It Va kern.emergency_intr_freq
515 Set the polling rate for the emergency interrupt polling code.
516 The default is 10 (hz) to dissuade casual use.
517 If you are doing real work
518 with emergency interrupt polling mode enabled, it is recommended
519 that you use a frequency between 100hz and 300hz.
520 .It Va kern.maxusers
521 Set the size of a number of statically allocated system tables; see
522 .Xr tuning 7
523 for a description of how to select an appropriate value for this tunable.
524 When set, this tunable replaces the value declared in the kernel
525 compile-time configuration file.
526 .It Va kern.ipc.nmbclusters
527 Set the number of mbuf clusters to be allocated.
528 The value cannot be set below the default
529 determined when the kernel was compiled.
530 Modifies
531 .Va NMBCLUSTERS .
532 .It Va kern.mmxopt
533 Toggles the mmx optimizations for the bcopy/copyin/copyout routines
534 .It Va kern.vm.kmem.size
535 Sets the size of kernel memory (bytes).
536 This overrides the value determined when the kernel was compiled.
537 .It Va kern.maxswzone
538 Limits the amount of
539 .Tn KVM
540 to be used to hold swap
541 meta information, which directly governs the
542 maximum amount of swap the system can support.
543 This value is specified in bytes of KVA space
544 and defaults to around 70MBytes.
545 Care should be taken
546 to not reduce this value such that the actual
547 amount of configured swap exceeds \(12 the
548 kernel-supported swap.
549 The default 70MB allows
550 the kernel to support a maximum of (approximately)
551 14GB of configured swap.
552 Only mess around with
553 this parameter if you need to greatly extend the
554 .Tn KVM
555 reservation for other resources such as the
556 buffer cache or
557 .Va NMBCLUSTERS .
558 Modifies
559 .Va VM_SWZONE_SIZE_MAX .
560 .It Va kern.maxbcache
561 Limits the amount of KVM reserved for use by the
562 buffer cache, specified in bytes.
563 The default maximum is 200MB.
564 This parameter is used to
565 prevent the buffer cache from eating too much
566 .Tn KVM
567 in large-memory machine configurations.
568 Only mess around with this parameter if you need to
569 greatly extend the
570 .Tn KVM
571 reservation for other resources
572 such as the swap zone or
573 .Va NMBCLUSTERS .
574 Note that
575 the NBUF parameter will override this limit.
576 Modifies
577 .Va VM_BCACHE_SIZE_MAX .
578 .It Va machdep.disable_mtrrs
579 Disable the use of
580 .Sy i686
581 .Tn MTRRs
582 (x86 only).
583 .It Va net.inet.tcp.tcbhashsize
584 Overrides the compile-time set value of
585 .Va TCBHASHSIZE
586 or the preset default of 512.
587 Must be a power of 2.
588 .It Va vfs.root.mountfrom
589 Specify root file system.
590 A semicolon separated list of file systems to try
591 as the kernel root file system.
592 File system format is file system type and disk store,
593 separated by colon.
594 This variable needs to be set when using a boot-only partition, which is
595 typically mounted on root file system as
596 .Pa /boot .
597 .Pp
598 One file system example:
599 .Dl hammer:da8s1a
600 .Pp
601 One file system
602 .Nm HAMMER
603 multi volume example:
604 .Dl hammer:da8s1a:da9s1a
605 .Pp
606 Several file systems, boot list, example:
607 .Dl ufs:da0s1a;hammer:ad1s1d
608 .Pp
609 Each file system in the list will be tried in the order specified
610 until the mount succeeds.
611 If all fail, the
612 .Ql mountroot>
613 prompt is displayed for manual entry.
614 .Pp
615 You may not specify devtab labels here but you can specify paths available to
616 .Xr devfs 5
617 such as:
618 .Dl hammer:serno/L41JYE0G.s1d
619 .El
620 .Sh FILES
621 .Bl -tag -width /boot/defaults/dloader.menu -compact
622 .It Pa /boot/boot.conf
623 .Nm
624 bootstrapping script.
625 Deprecated.
626 .It Pa /boot/loader
627 .Nm
628 itself.
629 .It Pa /boot/defaults/dloader.menu
630 .Nm
631 menu setup commands -- do not change this file.
632 .It Pa /boot/defaults/loader.conf
633 .Nm
634 configuration file, see
635 .Xr loader.conf 5
636 -- do not change this file.
637 .It Pa /boot/dloader.menu
638 .Nm
639 menu setup commands.
640 .It Pa /boot/dloader.rc
641 .Nm
642 bootstrapping script.
643 .It Pa /boot/loader.conf
644 .It Pa /boot/loader.conf.local
645 .Nm
646 configuration files, see
647 .Xr loader.conf 5 .
648 .It Pa /boot/loader.help
649 help messages, used by the
650 .Ic help
651 command.
652 .El
653 .Sh EXAMPLES
654 Boot in single user mode:
655 .Pp
656 .Dl loadall
657 .Dl boot -s
658 .Pp
659 Load kernel's user configuration file.
660 Notice that a kernel must be loaded before any other
661 .Ic load
662 command is attempted.
663 .Bd -literal -offset indent
664 load kernel
665 load -t userconfig_script kernel.conf
666 .Ed
667 .Pp
668 Load the kernel, a splash screen, and then autoboot in five seconds.
669 .Bd -literal -offset indent
670 load kernel
671 load splash_bmp
672 load -t splash_image_data chuckrulez.bmp
673 autoboot 5
674 .Ed
675 .Pp
676 Set the disk unit of the root device to 2, and then boot.
677 This would be needed in a system with two IDE disks,
678 with the second IDE disk hardwired to
679 .Pa ad2
680 instead of
681 .Pa ad1 .
682 .Bd -literal -offset indent
683 set root_disk_unit=2
684 boot kernel
685 .Ed
686 .Sh SEE ALSO
687 .Xr libstand 3 ,
688 .Xr loader.conf 5 ,
689 .Xr tuning 7 ,
690 .Xr boot 8 ,
691 .Xr btxld 8 ,
692 .Xr pxeboot 8 ,
693 .Xr pxeboot_tftp 8 ,
694 .Xr sysctl 8
695 .Sh HISTORY
696 The
697 .Nm
698 first appeared in
699 .Fx 3.1 .
700 .Nm dloader
701 was introduced and
702 .Tn FORTH
703 removed in
704 .Dx 2.7 .
705 .Sh AUTHORS
706 .An -nosplit
707 The
708 .Nm
709 was written by
710 .An Michael Smith Aq msmith@FreeBSD.org .
711 .Pp
712 .Nm dloader
713 was written by
714 .An Matthew Dillon Aq dillon@backplane.com .