xref: /freebsd/stand/man/loader.efi.8 (revision cfec995c87f39e59c80554b85625b4aaa8ddf8db)
1.\"
2.\" SPDX-License-Identifier: BSD-2-Clause
3.\"
4.\" Copyright (c) 2019-2022 Netflix, Inc
5.\" Copyright (c) 2022 Mateusz Piotrowski <0mp@FreeBSD.org>
6.\" Copyright 2022 The FreeBSD Foundation
7.\"
8.\" Part of this documentation was written by
9.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
10.\" from the FreeBSD Foundation.
11.\"
12.\" Redistribution and use in source and binary forms, with or without
13.\" modification, are permitted provided that the following conditions
14.\" are met:
15.\" 1. Redistributions of source code must retain the above copyright
16.\"    notice, this list of conditions and the following disclaimer.
17.\" 2. Redistributions in binary form must reproduce the above copyright
18.\"    notice, this list of conditions and the following disclaimer in the
19.\"    documentation and/or other materials provided with the distribution.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.Dd April 11, 2026
34.Dt LOADER.EFI 8
35.Os
36.Sh NAME
37.Nm loader.efi
38.Nd UEFI kernel loader
39.Sh DESCRIPTION
40On UEFI systems,
41.Nm
42loads the kernel.
43.Pp
44.Nm
45is invoked directly from the EFI System Partition (ESP)
46on systems installed using
47.Xr bsdinstall 8 ,
48when installed as the default EFI boot program as described in
49.Xr uefi 8
50or when configured as an EFI boot entry with
51.Xr efibootmgr 8 .
52.Pp
53On systems upgraded from FreeBSD 10 or earlier, the EFI System Partition (ESP)
54can be too small to accommodate
55.Nm .
56In such cases,
57.Xr boot1.efi 8
58may be retained as the firmware boot program. It
59will chain-load the current
60.Pa /boot/loader.efi ,
61which is updated during the
62.Cm installworld
63process.
64.Xr boot1.efi 8
65is deprecated for new installations.
66.Ss Console Considerations
67The UEFI firmware provides a generic console.
68In
69.Nm
70this is selected by specifying
71.Dq efi
72using the
73.Dv console
74variable.
75.Nm
76examines the
77.Dv 8be4df61-93ca-11d2-aa0d-00e098032b8c-ConOut
78UEFI environment variable to guess what the
79.Dq efi
80console points to.
81.Nm
82will output its prompts and menus to all the places specified by ConOut.
83However, the
84.Fx
85kernel has a limitation when more than one console is present.
86The kernel outputs to all configured consoles.
87Only the primary console will get the log messages from the
88.Xr rc 8
89system, and prompts for things like
90.Xr geli 8
91passwords.
92If
93.Nm
94finds a video device first, then
95.Nm
96tells the kernel to use the video console as primary.
97Likewise, if a serial device is first in the
98.Dv ConOut
99list, the serial port will be the primary console.
100.Pp
101If there is no
102.Dv ConOut
103variable, both serial and video are attempted.
104.Nm
105uses the
106.Dq efi
107console for the video (which may or may not work) and
108.Dq comconsole
109for the serial on
110.Dv COM1
111at the default baud rate.
112The kernel will use a dual console, with the video console
113primary if a UEFI graphics device is detected, or the serial console
114as primary if not.
115.Pp
116On x86 platforms, if you wish to redirect the loader's output to a serial port
117when the UEFI firmware doesn't support it, or to a serial port that isn't the
118one the UEFI firmware redirects its output to, set
119.Dv console
120to
121.Dq comconsole .
122The default port is
123.Dv COM1
124with an I/O address of 0x3f8.
125.Dv comconsole_port
126is used to set this to a different port address.
127.Dv comconsole_speed
128is used to set the of the serial port (the default is 9600).
129If you have
130.Dv console
131set to
132.Dq efi,comconsole
133you will get output on both the EFI console and the serial port.
134If this causes a doubling of characters, set
135.Dv console
136to
137.Dq efi ,
138since your UEFI firmware is redirecting to the serial port already.
139.Pp
140If your UEFI firmware redirects the serial port, you may need to tell the kernel
141which address to use.
142EFI uses ACPI's UID to identify the serial port, but
143.Nm
144does not have an ACPI parser, so it cannot convert that to an I/O port.
145The
146.Fx
147kernel initializes its consoles before it can decode ACPI resources.
148The
149.Fx
150kernel will look at the
151.Dv hw.uart.console
152variable to set its serial console.
153Its format should be described in
154.Xr uart 4
155but is not.
156Set it to
157.Dq io:0x3f8,br:115200
158with the proper port address.
159PCI or memory mapped ports are beyond the scope of this man page.
160.Pp
161The serial ports are assigned as follows on IBM PC compatible systems:
162.Bl -column -offset indent ".Sy Windows Name" ".Sy I/O Port Address" ".Sy Typical FreeBSD device"
163.It Sy Windows Name Ta Sy I/O Port Address Ta Sy Typical FreeBSD device
164.It COM1 Ta 0x3f8 Ta Pa /dev/uart0
165.It COM2 Ta 0x2f8 Ta Pa /dev/uart1
166.It COM3 Ta 0x3e8 Ta Pa /dev/uart2
167.It COM4 Ta 0x2e8 Ta Pa /dev/uart3
168.El
169.Pp
170Though
171.Dv COM3
172and
173.Dv COM4
174can vary.
175.Pp
176.Ss Primary Console
177The primary console is set using the boot flags.
178These command line arguments set corresponding flags for the kernel.
179These flags can be controlled by setting loader environment variables
180to
181.Dq yes
182or
183.Dq no .
184Boot flags may be set on the command line to the boot command.
185Inside the kernel, the RB_ flags are used to control behavior, sometimes
186in architecturally specific ways and are included to aid in discovery
187of any behavior not covered in this document.
188.Bl -column -offset indent ".Sy boot flag" ".Sy loader variable" ".Sy Kernel RB_ flag"
189.It Sy boot flag Ta Sy loader variable Ta Sy Kernel RB_ flag
190.It Fl a Ta Dv boot_askme Ta Va RB_ASKNAME
191.It Fl c Ta Dv boot_cdrom Ta Va RB_CDROM
192.It Fl d Ta Dv boot_ddb Ta Va RB_KDB
193.It Fl r Ta Dv boot_dfltroot Ta Va RB_DFLTROOT
194.It Fl D Ta Dv boot_multiple Ta Va RB_MULTIPLE
195.It Fl m Ta Dv boot_mute Ta Va RB_MUTE
196.It Fl g Ta Dv boot_gdb Ta Va RB_GDB
197.It Fl h Ta Dv boot_serial Ta Va RB_SERIAL
198.It Fl p Ta Dv boot_pause Ta Va RB_PAUSE
199.It Fl P Ta Dv boot_probe Ta Va RB_PROBE
200.It Fl s Ta Dv boot_single Ta Va RB_SINGLE
201.It Fl v Ta Dv boot_verbose Ta Va RB_VERBOSE
202.El
203.Pp
204And the following flags determine the primary console:
205.Bl -column -offset xxx "Flags" "RB_SERIAL | RB_MULTIPLE" "Kernel Consoles" "Primary Console"
206.It Sy Flags Ta Sy Kernel Flags Ta Sy Kernel Consoles Ta Sy Primary Console
207.It none Ta 0 Ta Video Ta Video
208.It Fl h Ta RB_SERIAL Ta Serial Ta Serial
209.It Fl D Ta RB_MULTIPLE Ta Serial, Video Ta Video
210.It Fl Dh Ta RB_SERIAL | RB_MULTIPLE Ta Serial, Video Ta Serial
211.El
212.Pp
213.Nm
214does not implement the probe
215.Fl P
216functionality where we use the video console if a keyboard is connected and a
217serial console otherwise.
218.Ss Additional Environment Variables
219.Nm
220loads some extra variables early in startup from
221.Pa /efi/freebsd/loader.env
222from the EFI partition.
223Only simple variables can be set here.
224It can be useful to specify the root filesystem:
225.Bd -literal -offset indent
226rootdev=disk0s1a
227.Ed
228.Ss Staging Slop
229The kernel must parse the firmware memory map tables to know what memory
230it can use.
231Since it must allocate memory to do this,
232.Nm
233ensures there's extra memory available, called
234.Dq slop ,
235after everything it loads
236.Po
237the kernel, modules and metadata
238.Pc
239for the kernel to bootstrap the memory allocator.
240.Pp
241By default, amd64 reserves 8MB.
242The
243.Ic staging_slop
244command allows for tuning the slop size.
245It takes a single argument, the size of the slop in bytes.
246.Ss amd64 Nocopy
247.Nm
248will load the kernel into memory that is 2MB aligned below 4GB.
249It cannot load to a fixed address because the UEFI firmware may reserve
250arbitrary memory for its use at runtime.
251Prior to
252.Fx 13.1 ,
253kernels retained the old BIOS-boot protocol of loading at exactly 2MB.
254Such kernels must be copied from their loaded location to 2MB prior
255starting them up.
256The
257.Ic copy_staging
258command is used to enable this copying for older kernels.
259It takes a single argument
260which can be one of
261.Bl -tag -width disable
262.It Ar disable
263Force-disable copying staging area to
264.Ad 2M .
265.It Ar enable
266Force-enable copying staging area to
267.Ad 2M .
268.It Ar auto
269Selects the behaviour based on the kernel's capability of boostraping
270from non-2M physical base.
271The kernel reports this capability by exporting the symbol
272.Va kernphys .
273.El
274.Pp
275Arm64 loaders have operated in the
276.Sq nocopy
277mode from their inception, so there is no
278.Ic copy_staging
279command on that platform.
280Riscv, 32-bit arm and arm64 have always loaded at any
281.Ad 2MB
282aligned location, so do not provide
283.Ic copy_staging .
284.Pp
285.Bd -ragged -offset indent
286.Sy Note.
287BIOS loaders on i386 and amd64 put the staging area starting
288at the physical address
289.Ad 2M ,
290then enable paging with identical mapping for the low
291.Ad 1G .
292The initial port of
293.Nm
294followed the same scheme for handing control to the kernel,
295since it avoided modifications for the loader/kernel hand-off protocol,
296and for the kernel page table bootstrap.
297.Pp
298This approach is incompatible with the UEFI specification,
299and as a practical matter, caused troubles on many boards,
300because UEFI firmware is free to use any memory for its own needs.
301Applications like
302.Nm
303must only use memory explicitly allocated using boot interfaces.
304The original way also potentially destroyed UEFI runtime interfaces data.
305.Pp
306Eventually,
307.Nm
308and the kernel were improved to avoid this problem.
309.Ed
310.Ss amd64 Faults
311Because it executes in x86 protected mode, the amd64 version of
312.Nm
313is susceptible to CPU faults due to programmer mistakes and
314memory corruption.
315To make debugging such faults easier, amd64
316.Nm
317can provide detailed reporting of the CPU state at the time
318of the fault.
319.Pp
320The
321.Ic grab_faults
322command installs a handler for faults directly in the IDT,
323avoiding the use of the UEFI debugging interface
324.Fn EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback .
325That interface is left available for advanced debuggers in
326the UEFI environment.
327The
328.Ic ungrab_faults
329command tries to deinstall the fault handler, returning TSS and IDT
330CPU tables to their pre-installation state.
331The
332.Ic fault
333command produces a fault in the
334.Nm
335environment for testing purposes, by executing the
336.Ic ud2
337processor instruction.
338.Sh FILES
339.Bl -tag -width "/boot/loader.efi"
340.It Pa /boot/loader.efi
341The location of the UEFI kernel loader within the system.
342.El
343.Ss EFI System Partition
344.Nm
345is installed on the ESP (EFI System Partition) in one of the following locations:
346.Bl -tag -width "efi/freebsd/loader.efi"
347.It Pa efi/boot/bootXXX.efi
348The default location for any EFI loader
349.Po see
350.Xr uefi 8
351for values to replace
352.Ql XXX
353with
354.Pc .
355.It Pa efi/freebsd/loader.efi
356The location reserved specifically for the
357.Fx
358EFI loader.
359.El
360.Pp
361The default location for the ESP mount point is documented in
362.Xr hier 7 .
363.Sh EXAMPLES
364.Ss Updating loader.efi on the ESP
365The following example shows how to install a new
366.Nm
367on the ESP.
368The exact placement is complicated due to the diversity of
369installations, setups and situations.
370In this section, paths that are all lower case are Unix paths.
371Paths that are all upper case are relative to the ESP mount point,
372though they may appear as lower case on your system because the
373FAT filesystem of the ESP is case insensitive.
374.Pp
375Locate the ESP, which has its own partition type of
376.Dq efi :
377.Bd -literal -offset indent
378# gpart show nda0
379=>        40  7501476448  nda0  GPT  (3.5T)
380          40      614400     1  efi  (300M)
381      614440  7500862048     2  freebsd-zfs  (3.5T)
382.Ed
383.Pp
384The name of the ESP on this system is
385.Pa nda0p1 .
386By default, this will be mounted on
387.Pa /boot/efi .
388To check:
389.Bd -literal -offset indent
390# mount | grep nda0p1
391/dev/nda0p1 on /boot/efi (msdosfs, local)
392.Ed
393.Pp
394If it's not mounted, you will need to mount it:
395.Bd -literal -offset indent
396# mount -t msdosfs /dev/nda0p1 /boot/efi
397.Ed
398.Pp
399.Xr efibootmgr 8
400reports what we booted from.
401.Bd -literal -offset indent
402# efibootmgr -v
403Boot to FW : false
404BootCurrent: 0001
405Timeout    : 2 seconds
406BootOrder  : 0000, 0001, 0003, 0004, 0005, 0006, 0001, 0008, 000A, 000B, 000C, 000E, 0007
407\&...
408+Boot0001* FreeBSD ZPOOL HD(1,GPT,b5d0f86b-265d-1e1b-18aa-0ed55e1e73bd,0x28,0x96000)/File(\eEFI\eFREEBSD\eLOADER.EFI)
409                            nda0p1:/EFI/FREEBSD/LOADER.EFI /boot/efi//EFI/FREEBSD/LOADER.EFI
410\&...
411.Ed
412.Pp
413Often there are several options, depending on the BIOS.
414The entry that we booted with is marked with a
415.Sq +
416at the start of the line, as shown above.
417So in this case, this firmware is using
418.Pa /EFI/FREEBSD/LOADER.EFI
419from the ESP.
420Often times it will be the UEFI
421.Dq default
422loader, which varies by architecture.
423.Bl -column -offset indent "Architecture" "Default Path"
424.It Sy Architecture Ta Sy Default Path
425.It amd64 Ta Pa /EFI/BOOT/BOOTX64.EFI
426.It arm Ta Pa /EFI/BOOT/BOOTARM.EFI
427.It arm64 Ta Pa /EFI/BOOT/BOOTAA64.EFI
428.It i386 Ta Pa /EFI/BOOT/BOOTIA32.EFI
429.It riscv Ta Pa /EFI/BOOT/BOOTRISCV64.EFI
430.El
431.Pp
432However, care must be taken: some multiple-boot environments rely on a special
433.Pa bootXXX.efi
434to function.
435Before updating a
436.Pa bootXXX.efi
437file, make sure it is the FreeBSD boot loader before updating it:
438.Bd -literal -offset indent
439# strings /boot/efi/EFI/BOOT/BOOTX64.EFI | grep FreeBSD | grep EFI
440FreeBSD/amd64 EFI loader, Revision 3.0
441.Ed
442.Pp
443.Xr bsdinstall 8
444copies
445.Pa loader.efi
446to the default name if there wasn't one there before.
447Check to see if they are copies before updating (with X64 substituted using the
448above table):
449.Bd -literal -offset indent
450# cmp /boot/efi/EFI/FREEBSD/LOADER.EFI /boot/efi/EFI/BOOT/BOOTX64.EFI
451.Ed
452.Pp
453Copy the loader:
454.Bd -literal -offset indent
455# cp /boot/loader.efi /boot/efi/EFI/FREEBSD/LOADER.EFI
456.Ed
457.Pp
458replacing the all caps part of the example with the proper path.
459.Pp
460If ESP path was
461.Pa /FREEBSD/LOADER.EFI
462and LOADER.EFI and BOOTX64.EFI were identical in the cmp step,
463copy the loader to the default location:
464.Bd -literal -offset indent
465# cp /boot/loader.efi /boot/efi/EFI/BOOT/BOOTX64.EFI
466.Ed
467.Pp
468Finally, if you mounted the ESP, you may wish to unmount it.
469.Bd -literal -offset indent
470# umount /boot/efi
471.Ed
472.Sh SEE ALSO
473.Xr loader 8 ,
474.Xr uefi 8
475.Sh BUGS
476Non-x86 serial console handling is even more confusing and less well documented.
477.Pp
478Sometimes when the serial port speed isn't set, 9600 is used.
479Other times the result is typically 115200 since the speed remains unchanged
480from the default.
481.Pp
482U-Boot implements a subset of the UEFI standard.
483Some versions do not support fetching loader variables, so
484.Pa efibootmgr
485may not work.
486In addition,
487.Pa efibootmgr
488is not supported on armv7 or riscv.
489In these instances, the user has to understand what was booted to update
490it properly (and in most cases, it will be the FreeBSD path and the UEFI default
491so just copy loader.efi there if there are loaders there).
492Typically in these embedded situations, there is only one .efi file (loader.efi
493or a copy of loader.efi).
494The path to this file is typically the default removable path above.
495.Pp
496Managing booting multiple OSes on UEFI varies greatly, so extra caution is required
497when updating the UEFI default loader.
498.Pp
499