3 AUTHOR: Dan McGhee, Kevin M. Buckley, and Xi Ruoyao
7 LICENSE: GNU Free Documentation License Version 1.2
9 SYNOPSIS: Boot LFS by default in a UEFI Environment using GRUB
11 PRIMARY URI: https://linux.xidian.edu.cn/git/xry111/LFS-book/wiki/lfs-uefi
12 (Markdown formatted, update once the author has built a new LFS version)
15 This hint contains the information to direct the OS Boot Manager to default
16 to the GRUB in a UEFI environment employing EFI Mode. This hint applies to
19 This version, hereafter referred to as "the 2018-04-09 hint", updates Dan
20 McGhee and Kevin M. Buckley's original, dated 2017-02-07.
22 The 2018-04-09 hint saw the UEFI packages built against an LFS 8.2 systemd
23 installation that was already being booted using the existing host system's
26 Where possible, changes to the 2018-04-09 hint have been made so that it
27 should be obvious where the the 2018-04-09 and 2017-02-07 hint's differ.
33 * Base LFS system before or after Ch. 8
34 * Basic understanding of obtaining and building packages
38 DISCLAIMER: The recipes in this hint neither supplant nor supersede the
39 build instructions in a stable version of either the LFS or BLFS books.
40 They merely augment them for newer firmware. If conflicts arise between
41 this hint and the instructions in the book, take the issue to the mailing
42 lists. Additionally, this hint applies to only x86_64 machines packaged
43 with Windows 7 or Windows 8. The recipes here can be used on Mac OS, but
44 have not been investigated at the initial writing of this hint.
46 The 2018-04-09 hint refers to an LFS 8.2 system, built onto an x86_64
47 machine from within a LFS 7.9 host, that had had never had a version of
48 windows installed on it, indeed the host contained one EFI directories
49 below `/boot/efi/EFI/`, namely `boot`, that having been installed by
50 the vendor of the computer.
52 USE OF TERMS: The following is a use of terms in this hint. Further
53 information for and amplification of them can be found in References 1-3.
55 * BIOS Settings: A firmware interface accessed by the keyboard after power
56 is applied. In it a user can change the order and way of how the computer
59 * BIOS System: Firmware with an MBR
61 * EFI Mode: A condition of the booted system in which the EFI partition is
62 mounted and the uefi (efi) variable support in the kernel is working
63 properly. It results from enabling UEFI Mode in BIOS Settings.
65 * EFI Mount Point: A user defined mount point for the EFI Partition. In
66 this hint, and in most distros, it is `/boot/efi`.
68 * EFI Partition: A small partition, usually before any other partitions;
69 i.e., `/dev/sda1` of 200-250 Mb, formatted in FAT32 with the `boot` flag, in
70 parted, or `ef00` (EF00) partition type in gdisk. (NOTE: The `boot` flag has a
71 different function and meaning in MBR partitioned disks.)
73 * efi variables (synonymous: uefi variables): variables through which the
74 operating system can interact with the firmware.
76 * Legacy Boot Option (Legacy Boot): A boot process in BIOS Settings that
77 disables UEFI booting and uses CIM.
79 * GUID Partition Table (GPT): A partitioning scheme that uses UUID's instead
80 of cylinders to identify partitions.
83 PRELIMINARY DISCUSSION: Additional information and more in depth
84 discussion of the following concepts can be found using References 1-3.
86 Booting LFS is no longer as simple as `grub-install /dev/sda`. There are
87 more options and more considerations. With the advent and proliferation of
88 UEFI firmware, a user's knowledge and philosophy of the boot
89 process requires expansion:
91 1. GPT partitioning is different from MBR partitioning. The tool fdisk
92 is not able to manipulate GPT partitions. Parted and gdisk (from
93 gptfdisk) are the tools to use. Each has their pros and cons,
94 supporters and detractors. Either one or both can be used.
95 2. UEFI firmware uses Boot Managers to select Boot Loaders like GRUB or
96 LILO. They, themselves do not boot the machine.
97 3. The Boot Loaders are placed on the EFI partition rather than the
98 MBR. This concept is similar and parallel to the LFS procedures of
99 using a separate `/boot` partition.
100 4. There are additional tools that LFS needs in order to accomplish
101 this mode of booting.
102 5. LFS can be built and booted as the instructions are written up to
103 and including LFS-8.2. To do this on UEFI firmware, the BIOS
104 Settings must be changed to Legacy Options from UEFI Options.
106 One of the hugely discussed issues surrounding UEFI is Secure Boot. It is
107 necessary to understand that the terms "UEFI" and "Secure Boot" are NOT
108 synonymous. UEFI is firmware. Secure Boot is a process of using "keys" to
109 "guarantee" the safety and authenticity of a Boot Loader. NOTE: To use
110 the recipes in this hint, Secure Boot must be disabled in the BIOS Boot
113 Please note that the recommended order for implementing these recipes is a
114 departure from the build order in LFS. The most convenient, and arguably
115 the most practical way, to implement the recipes here is to use them in the
116 build of an LFS System at the end of Ch. 6. Building the BLFS and
117 non-BLFS packages has been tested both inside and outside of the chroot
118 environment. Then, following the book, proceed through Ch. 7, returning to
119 the recipes in Ch. 8. The recipes are presented in that order.
121 The most inconvenient way to implement these recipes is in a completely
122 functional LFS-8.2, or earlier, system. This involves uninstalling
123 `GRUB-2.02`, removing it from its location as a result of `grub-install` and
124 implementing the recipes. Migrating from Legacy Boot to UEFI boot is
125 possible. At the initial writing of this hint, however, it is not
126 included. References 1-3 contain more information on this subject.
128 The last consideration in implementing the recipes here is GRUB's graphical
129 terminal. In UEFI systems, if the GRUB video mode is not initialized, no
130 kernel boot messages will appear until the kernel video takes over. The
131 GRUB package does not supply fonts, and GRUB defaults to `unicode.pf2`.
132 There are two ways to supply this font. The first is to copy `unicode.pf2`
133 from the host system to `/boot/grub` on the LFS system. The second method
134 involves configuring grub to build grub-mkfont, and this creates a build
135 dependency of `FreeType` for GRUB. This hint addresses both situations.
137 Finally, as of the initial writing of this hint, there is no standard for
138 the use of UEFI and the implementation of Secure Boot. These are hugely
139 manufacturer dependent. This hint uses terms used in the original author's
140 hardware. They may be different in other manufacturers' implementations.
141 However, the capabilities to do the boot setup operations contained in this
142 hint will exist on each machine. The terms may differ, and more than one
143 operation might be needed to achieve a desired goal. For example, someone
144 may need to disable Secure Boot and remove Secure Keys.
147 [NOTE] The recipes are written with the assumption that the packages are
148 being built in the chroot environment before the end of Ch. 8. They can be
149 modified, with little difficulty, to be used in a functional system.
152 Before entering the chroot environment, check that the host booted in
157 If this directory exists and is populated, the host booted in EFI Mode.
160 Determine which device is the EFI partition using gdisk or parted,
161 enter the chroot environment, create `/boot/efi` if needed, and
163 mount -vt vfat /dev/sda(x) /boot/efi
165 where sda(x) is the device containing the EFI partition.
169 Install the following BLFS packages, using the instructions in the book:
170 `dosfstools`, `popt` and `pciutils`. Build and install `FreeType`
171 if building grub with `grub-mkfont` enabled.
173 The BLFS 8.2 `FreeType` instructions recommend that it be built after
174 `which` and `libpng` have been installed, so it was, however, as the
175 recommendation for "HarfBuzz" notes that one builds `FreeType` without
176 it first, and then do a re-install, it wasn't thought necessary to do
179 The `libpng` install did include the "apng" patch.
181 The 2017-02-07 hint suggests we need static library of popt. But
182 now `efivar` no longer needs it. So we can just follow BLFS
183 instruction to build these packages.
185 The 2017-02-07 hint gives instruction to build `dosfstools`, now we can
186 just follow BLFS instruction.
190 The 2017-02-07 hint uses `efivar-30`, but it's known to cause some issues.
191 So we update to `efivar-34`.
197 * https://github.com/rhboot/efivar/releases/download/34/efivar-34.tar.bz2
203 The meaning of the make parameter:
205 * `libdir=/usr/lib`: This option overrides the default library directory
206 of the package (`/usr/lib64`).
208 Despite the Makefile having a `test` target, albeit one which isn't run
209 by default, you SHOULD NOT run that `make test`, as it has been found
210 to cause firmware bugs. Here are the thoughts on, and the exhortation
211 not to do, this from the `efivar` community:
212 https://github.com/rhboot/efivar/issues/78 .
216 Now as the `root` user:
218 make libdir=/usr/lib install
223 * Required: `pciutils` and `efivars`
224 * Required (runtime): `dosfstools`
227 * https://github.com/rhinstaller/efibootmgr/releases/download/14/efibootmgr-14.tar.bz2
231 make EFIDIR=LFS EFI_LOADER=grubx64.efi
233 The meaning of the make parameters:
235 * `EFIDIR=LFS`: This is the distro's subdirectory name under
236 `/boot/efi/EFI`. `Make.default` file of `efibootmgr` need this variable
238 * `EFI_LOADER=grubx64.efi`: This variable is set to the default EFI boot
239 loader. It affects the default of parameter `--loader`. You can skip
240 this if you won't invoke `efibootmgr` directly and only `grub-install`
245 Now as the `root` user:
247 install -v -D -m0755 src/efibootmgr /usr/sbin/efibootmgr &&
248 install -v -D -m0644 src/efibootmgr.8 \
249 /usr/share/man/man8/efibootmgr.8
254 * http://unifoundry.com/pub/unifont-10.0.07/font-builds/unifont-10.0.07.pcf.gz
258 [NOTE] This package is not a tarball. So DON'T (and you can't)
259 `tar -xf` it and change to the unzipped directory like normal LFS/BLFS
264 mkdir -pv /usr/share/fonts/unifont &&
265 gunzip -c unifont-10.0.07.pcf.gz > \
266 /usr/share/fonts/unifont/unifont.pcf
271 * Optional: `FreeType` (for `grub-mkfont` and `unicode.pf2`)
272 * Optional: `unifont` (for `unicode.pf2`)
274 [NOTE] The 2017-02-07 hint installs `unicode.pf2` manually.
275 However, if `freetype` and `unifont` are both installed, GRUB
276 will build `unicode.pf2`, and `grub-install` will install the
277 file automatically. This is recommended in 2018-04-09 hint.
280 * https://ftp.gnu.org/gnu/grub/grub-2.02.tar.xz
282 Prepare for compilation:
284 [NOTE] Some options in 2017-02-07 hint are no longer necessary.
286 ./configure --prefix=/usr \
290 --enable-grub-mkfont \
291 --with-platform=efi \
294 The meaning of configure options:
296 * `--enable-grub-mkfont`: This ensures `grub-mkfont` to be built.
297 If `Freetype` is not installed, remove this option and then you
298 have to get `unicode.pf2` from other sources (either the host or
301 * `--with-platform=efi`: This ensures `grub` to be built for EFI.
303 If the optional dependencies are installed, `configure` should
304 output the following information at last:
307 Build-time grub-mkfont: Yes
308 With unifont from /usr/share/fonts/unifont/unifont.pcf
310 That means `unicode.pf2` would be built and used.
318 Now as the `root` user:
322 MODIFICATION OF /etc/fstab
324 When constructing `/etc/fstab` in LFS chapter 8, add a line to
327 /dev/<name of EFI partition> /boot/efi vfat defaults 0 1
329 Systemd would mount `efivarfs` automatically. If using sysvinit,
330 add another line to mount `efivarfs`:
332 efivarfs /sys/firmware/efi/efivars efivarfs defaults 0 1
336 a) If you are going to be booting your UEFI-aware LFS system using a
337 non-LFS GRUB from your host AND if that GRUB is one (eg Fedora)
338 that allows for the kernel to be specified using that GRUB's
339 `linuxefi` attribute, so
341 linuxefi /path/to/kernel root=/path/to/root ro
343 then you don't appear to need the `/etc/fstab` line, and indeed,
344 you'll get told during the boot that the mounter knows nothing
345 about the efivars filesystem type. However, LFS's efibootmgr will
346 still be capable of interrogating your UEFI environment.
348 b) If the LFS system is booted from the LFS+Hint's grub, which doesn't
349 appear to know about the "linuxefi" attribute so using
351 linux /path/to/kernel root=/path/to/root ro
353 then, unless you have the efivars filesystem mounted, and you are
354 able to, then LFS's efibootmgr will be **not** capable of interrogating
355 your UEFI environment, and you'll be told that there is no `efivars`
358 KERNEL CONFIGURATION OPTIONS FOR EFI
360 The LFS 8.2 kernel build's `make defconfig` populated a good number of
361 the EFI-related options on my UEFI-enabled hardware, however, so as to
362 make the 2014-10-16 hint's list of settings easier to find when coming
363 to alter/set things, here is the list of the options along with the
364 location of the various checkboxes and the settings they should have,
365 as seen when starting from a `make menuconfig`:
367 ## CONFIG_EFI_PARTITION=y
370 -> Enable the block layer
372 [*] Advanced partition selection
374 [*] EFI GUID Partition support
380 -> Processor type and features
381 [*] EFI runtime service support
389 -> Frame buffer Devices
390 [*] EFI-based Framebuffer Support
392 ## CONFIG_FRAMEBUFFER_CONSOLE=y
397 -> Console display driver support
398 Framebuffer Console support (Not available on mine)
400 ## CONFIG_EFI_VARS is not set
401 ## CONFIG_EFI_RUNTIME_MAP=y
405 -> EFI (Extensible Firmware Interface) Support
406 < > EFI Variable Support via sysfs
407 [*] Export efi runtime maps to sysfs
410 ## CONFIG_EFIVAR_FS=y/m
414 -> Pseudo filesystems
415 [*] EFI Variable filesystem
419 The only Kernel Config setting that a `make defconfig` didn't set on
420 the UEFI-enabled host was this one:
424 and without that setting in the kernel, attempts to boot the LFS system
427 Kernel doesn't support EFI handover
429 however, adding just that one Kernel Config setting sees you able to
430 boot into the LFS system using the host system's Grub.
432 `CONFIG_FB_EFI=y` seems not necessary if you have other FB devices
433 avaliable. But without it you will lose some boot messages along
434 with the Tux logos on the FB.
436 USING GRUB TO SET UP THE BOOT PROCESS
438 INSTALLING GRUB TO THE EFI PARTITION
440 Installing GRUB to the EFI partition and creating an OS Boot Manager
441 entry is the major difference between the recipes in this hint and the
442 procedures in the LFS book. In concept, it is not actually a divergence
443 from the concepts of the book. The instructions there install GRUB to
444 the MBR, the MBR protected layer of a GPT disk or to a dedicated /boot
445 partition. The recipes here install GRUB to the EFI partition and
446 generate an entry in the system's Boot Manager. It is for the single
447 command here that this hint was written and for which all the non-LFS
448 packages were installed.
450 grub-install --bootloader-id=LFS --recheck --debug &> grub.log
452 `--bootloader-id=<some name>` is the directory on the EFI partition to
453 which the GRUB image is written.
455 Running this command generates lots of output (redirected to `grub.log`).
456 But at the end it will indicate that it was successful. This command
457 installs the GRUB image to `/boot/efi/EFI/LFS/grubx64.efi` and creates
458 the entry `LFS` in the system's Boot Manager.
460 To check it, inspect the contents of `/boot/efi/EFI/LFS` and, as root, run
461 `efibootmgr`. The results of this command will list the Boot Order and
462 all the Boot Entries. If the entry "LFS" does not appear, read the
463 efibootmgr man page, create an entry and change the Boot Order to what is
466 If GRUB was built with `freetype` and `unifont`, `unicode.pf2` should be
467 installed automatically now. Issue:
469 grep "unicode.pf2" grub.log
471 You should see something like
473 copying `/usr/share/grub/unicode.pf2' -> `/boot/grub/fonts/unicode.pf2'
475 If not, you should get `unicode.pf2` from the host system or Internet,
476 and install it into `/boot/grub/fonts`.
482 cat > /boot/grub/grub.cfg << "EOF"
483 # Begin /boot/grub/grub.cfg
490 set root=(hd[x], gpt[y])
491 # hd[x] is the drive of the LFS partion and gpt[y] is the partition
496 if loadfont /boot/grub/fonts/unicode.pf2; then
497 loadfont /boot/grub/fonts/unicode.pf2
501 terminal_output gfxterm
504 menuentry "GNU/Linux, Linux <kernel name>" {
505 linux /boot/vmlinuz-<kernel name> root=/dev/sda[x] ro
509 Note that in `menuentry`, `/dev/sda[x]` is the device of the LFS
512 [NOTE] From GRUB's perspective, the kernel files are relative
513 to the partition used. If you used a separate `/boot` partition,
514 remove `/boot` from the above linux line and path of `unicode.pf2`.
515 You will also need to change the `set root` line to point to the
520 As stated before, the implementation of UEFI firmware and its manipulation
521 depends hugely on the manufacturer. As of the initial writing of this
522 hint, there is no standard approach. Therefore, while the recipes here all
523 do what is advertised, regrettably the system may not default to the grub
524 boot loader "out of the box." In that case, reviewing References 1-3, will
525 provide information that will lead users to a solution to the situation.
526 As always, one of the best resources is the {,B}LFS mailing lists.
528 At this point, it is worth stating that there are other helpful tools:
529 gummiboot and rEFInd are two of them. They are described as Boot Managers,
530 but in fact are a user space layer between the OS Boot Manager and the Boot
531 Loader. Information about both is in the references.
535 1. Rod's Books - A collection of web page articles that goes into great
536 detail about the concepts of UEFI booting, partitioning and tools.
537 The below URL goes right to the efi information. www.rodsbooks.com is
538 the main page and has many, many good articles.
539 URL: http://www.rodsbooks.com/efi-bootloaders/index.html
541 2. "Unified Extensible Firmware Interface - ArchWiki"
542 URL: https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface
545 URL: https://wiki.archlinux.org/index.php/GRUB
547 4. Google. URL: https://google.com
551 * Craig Magee for comments and testing.
552 * Pierre Labastie for testing, font manipulation and comments.
553 * Lei Niu for comments on efivar and grub.cfg issues.
556 * Add paragraph and section numbers and TOC to make searchable
557 * Add appendix for migration from Legacy Boot to UEFI boot
558 * Add appendix for more options to default to GRUB
559 * Add appendix for LVM
560 * Add appendix for "standalone" GRUB on EFI partition independent
566 Use BLFS-like format for package dependency list
567 Use package name in BLFS (FreeType instead of Freetype2)
568 Deleted dosfstools-3.0.28 (replaced by dosfstools-4.1 in BLFS)
569 Updated efivar-30 to efivar-34
570 Updated unifont-9.0.06 to unifont-10.0.07
571 Updated GRUB-2.02~beta3 to GRUB-2.02
572 Modified the hint to let GRUB install unicode.pf2 automatically
573 Removed some options not necessary now
574 Fixed path to unicode.pf2 in grub.cfg for those without /boot partition
575 Copied note about seperated /boot partition for grub.cfg from LFS book
576 Removed incorrect personal email addresses (they are LFS mail lists)
578 Adapted for checkHint script (AUTHORS to AUTHOR)
581 Updated for LFS 7.10 and "extra package" updates
582 dosfstools-3.0.26 -> dosfstools-3.0.28
583 efivar-0.12 -> efivar-30
584 efibootmgr-0.9.0 -> efibootmgr-14
585 unifont-7.0.05 -> unifont-9.0.06