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
12 This hint contains the information to direct the OS Boot Manager to default
13 to the GRUB in a UEFI environment employing EFI Mode. This hint applies to
16 This version, hereafter referred to as "the 2018-04-09 hint", updates Dan
17 McGhee and Kevin M. Buckley's original, dated 2017-02-07.
19 The 2018-04-09 hint saw the UEFI packages built against an LFS 8.2 systemd
20 installation that was already being booted using the existing host system's
23 Where possible, changes to the 2018-04-09 hint have been made so that it
24 should be obvious where the the 2018-04-09 and 2017-02-07 hint's differ.
30 * Base LFS system before or after Ch. 8
31 * Basic understanding of obtaining and building packages
35 DISCLAIMER: The recipes in this hint neither supplant nor supersede the
36 build instructions in a stable version of either the LFS or BLFS books.
37 They merely augment them for newer firmware. If conflicts arise between
38 this hint and the instructions in the book, take the issue to the mailing
39 lists. Additionally, this hint applies to only x86_64 machines packaged
40 with Windows 7 or Windows 8. The recipes here can be used on Mac OS, but
41 have not been investigated at the initial writing of this hint.
43 The 2018-04-09 hint refers to an LFS 8.2 system, built onto an x86_64
44 machine from within a LFS 7.9 host, that had had never had a version of
45 windows installed on it, indeed the host contained one EFI directories
46 below `/boot/efi/EFI/`, namely `boot`, that having been installed by
47 the vendor of the computer.
49 USE OF TERMS: The following is a use of terms in this hint. Further
50 information for and amplification of them can be found in References 1-3.
52 * BIOS Settings: A firmware interface accessed by the keyboard after power
53 is applied. In it a user can change the order and way of how the computer
56 * BIOS System: Firmware with an MBR
58 * EFI Mode: A condition of the booted system in which the EFI partition is
59 mounted and the uefi (efi) variable support in the kernel is working
60 properly. It results from enabling UEFI Mode in BIOS Settings.
62 * EFI Mount Point: A user defined mount point for the EFI Partition. In
63 this hint, and in most distros, it is `/boot/efi`.
65 * EFI Partition: A small partition, usually before any other partitions;
66 i.e., `/dev/sda1` of 200-250 Mb, formatted in FAT32 with the `boot` flag, in
67 parted, or `ef00` (EF00) partition type in gdisk. (NOTE: The `boot` flag has a
68 different function and meaning in MBR partitioned disks.)
70 * efi variables (synonymous: uefi variables): variables through which the
71 operating system can interact with the firmware.
73 * Legacy Boot Option (Legacy Boot): A boot process in BIOS Settings that
74 disables UEFI booting and uses CIM.
76 * GUID Partition Table (GPT): A partitioning scheme that uses UUID's instead
77 of cylinders to identify partitions.
80 PRELIMINARY DISCUSSION: Additional information and more in depth
81 discussion of the following concepts can be found using References 1-3.
83 Booting LFS is no longer as simple as `grub-install /dev/sda`. There are
84 more options and more considerations. With the advent and proliferation of
85 UEFI firmware, a user's knowledge and philosophy of the boot
86 process requires expansion:
88 1. GPT partitioning is different from MBR partitioning. The tool fdisk
89 is not able to manipulate GPT partitions. Parted and gdisk (from
90 gptfdisk) are the tools to use. Each has their pros and cons,
91 supporters and detractors. Either one or both can be used.
92 2. UEFI firmware uses Boot Managers to select Boot Loaders like GRUB or
93 LILO. They, themselves do not boot the machine.
94 3. The Boot Loaders are placed on the EFI partition rather than the
95 MBR. This concept is similar and parallel to the LFS procedures of
96 using a separate `/boot` partition.
97 4. There are additional tools that LFS needs in order to accomplish
99 5. LFS can be built and booted as the instructions are written up to
100 and including LFS-8.2. To do this on UEFI firmware, the BIOS
101 Settings must be changed to Legacy Options from UEFI Options.
103 One of the hugely discussed issues surrounding UEFI is Secure Boot. It is
104 necessary to understand that the terms "UEFI" and "Secure Boot" are NOT
105 synonymous. UEFI is firmware. Secure Boot is a process of using "keys" to
106 "guarantee" the safety and authenticity of a Boot Loader. NOTE: To use
107 the recipes in this hint, Secure Boot must be disabled in the BIOS Boot
110 Please note that the recommended order for implementing these recipes is a
111 departure from the build order in LFS. The most convenient, and arguably
112 the most practical way, to implement the recipes here is to use them in the
113 build of an LFS System at the end of Ch. 6. Building the BLFS and
114 non-BLFS packages has been tested both inside and outside of the chroot
115 environment. Then, following the book, proceed through Ch. 7, returning to
116 the recipes in Ch. 8. The recipes are presented in that order.
118 The most inconvenient way to implement these recipes is in a completely
119 functional LFS-8.2, or earlier, system. This involves uninstalling
120 `GRUB-2.02`, removing it from its location as a result of `grub-install` and
121 implementing the recipes. Migrating from Legacy Boot to UEFI boot is
122 possible. At the initial writing of this hint, however, it is not
123 included. References 1-3 contain more information on this subject.
125 The last consideration in implementing the recipes here is GRUB's graphical
126 terminal. In UEFI systems, if the GRUB video mode is not initialized, no
127 kernel boot messages will appear until the kernel video takes over. The
128 GRUB package does not supply fonts, and GRUB defaults to `unicode.pf2`.
129 There are two ways to supply this font. The first is to copy `unicode.pf2`
130 from the host system to `/boot/grub` on the LFS system. The second method
131 involves configuring grub to build grub-mkfont, and this creates a build
132 dependency of `FreeType` for GRUB. This hint addresses both situations.
134 Finally, as of the initial writing of this hint, there is no standard for
135 the use of UEFI and the implementation of Secure Boot. These are hugely
136 manufacturer dependent. This hint uses terms used in the original author's
137 hardware. They may be different in other manufacturers' implementations.
138 However, the capabilities to do the boot setup operations contained in this
139 hint will exist on each machine. The terms may differ, and more than one
140 operation might be needed to achieve a desired goal. For example, someone
141 may need to disable Secure Boot and remove Secure Keys.
144 [NOTE] The recipes are written with the assumption that the packages are
145 being built in the chroot environment before the end of Ch. 8. They can be
146 modified, with little difficulty, to be used in a functional system.
149 Before entering the chroot environment, check that the host booted in
154 If this directory exists and is populated, the host booted in EFI Mode.
156 CREATE AND FORMAT NEW EFI PARTITION, IF NECESSARY
157 Some firmwares (for example those in Dell desktops) has a reserved,
158 invisible EFI partition for its OEM Windows. If it's the first time you
159 install another EFI booted OS on the system, create a new EFI partition
160 using `fdisk` or your prefered partition tool. Then, mark it with the
163 If you created a new EFI partition, install `dosfstools` from BLFS and
164 format the new EFI partition with:
166 mkfs.vfat /dev/sda(x)
168 where sda(x) is the device containing the EFI partition.
171 Determine which device is the EFI partition using gdisk or parted,
172 enter the chroot environment, create `/boot/efi` if needed, and
174 mount -vt vfat /dev/sda(x) /boot/efi
176 where sda(x) is the device containing the EFI partition.
180 Install the following BLFS packages, using the instructions in the book:
181 `dosfstools`, `popt` and `pciutils`. Build and install `FreeType`
182 if building grub with `grub-mkfont` enabled.
184 The BLFS 8.2 `FreeType` instructions recommend that it be built after
185 `which` and `libpng` have been installed, so it was, however, as the
186 recommendation for "HarfBuzz" notes that one builds `FreeType` without
187 it first, and then do a re-install, it wasn't thought necessary to do
190 The `libpng` install did include the "apng" patch.
192 The 2017-02-07 hint suggests we need static library of popt. But
193 now `efivar` no longer needs it. So we can just follow BLFS
194 instruction to build these packages.
196 The 2017-02-07 hint gives instruction to build `dosfstools`, now we can
197 just follow BLFS instruction.
202 * https://github.com/rhboot/efivar/releases/download/37/efivar-37.tar.bz2
208 The meaning of the make parameter:
210 * `libdir=/usr/lib`: This option overrides the default library directory
211 of the package (`/usr/lib64`).
213 Despite the Makefile having a `test` target, albeit one which isn't run
214 by default, you SHOULD NOT run that `make test`, as it has been found
215 to cause firmware bugs. Here are the thoughts on, and the exhortation
216 not to do, this from the `efivar` community:
217 https://github.com/rhboot/efivar/issues/78 .
221 Now as the `root` user:
223 make libdir=/usr/lib install
228 * Required: `popt` and `efivar`
231 * https://github.com/rhinstaller/efibootmgr/releases/download/16/efibootmgr-16.tar.bz2
235 make EFIDIR=LFS EFI_LOADER=grubx64.efi
237 The meaning of the make parameters:
239 * `EFIDIR=LFS`: This is the distro's subdirectory name under
240 `/boot/efi/EFI`. `Make.default` file of `efibootmgr` need this variable
242 * `EFI_LOADER=grubx64.efi`: This variable is set to the default EFI boot
243 loader. It affects the default of parameter `--loader`. You can skip
244 this if you won't invoke `efibootmgr` directly and only `grub-install`
249 Now as the `root` user:
251 install -v -D -m0755 src/efibootmgr /usr/sbin/efibootmgr &&
252 install -v -D -m0644 src/efibootmgr.8 \
253 /usr/share/man/man8/efibootmgr.8
258 * http://unifoundry.com/pub/unifont/unifont-12.0.01/font-builds/unifont-12.0.01.pcf.gz
262 [NOTE] This package is not a tarball. So DON'T (and you can't)
263 `tar -xf` it and change to the unzipped directory like normal LFS/BLFS
268 mkdir -pv /usr/share/fonts/unifont &&
269 gunzip -c unifont-10.0.07.pcf.gz > \
270 /usr/share/fonts/unifont/unifont.pcf
275 * Optional: `FreeType` (for `grub-mkfont` and `unicode.pf2`)
276 * Optional: `unifont` (for `unicode.pf2`)
278 [NOTE] The 2017-02-07 hint installs `unicode.pf2` manually.
279 However, if `freetype` and `unifont` are both installed, GRUB
280 will build `unicode.pf2`, and `grub-install` will install the
281 file automatically. This is recommended in 2018-04-09 hint.
284 * https://ftp.gnu.org/gnu/grub/grub-2.02.tar.xz
286 http://www.linuxfromscratch.org/patches/downloads/grub/grub-2.02-relocation_fix-1.patch
288 Prepare for compilation:
290 Apply a patch to make some fixes required by binutils-2.31:
292 patch -Np1 -i ../grub-2.02-relocation_fix-1.patch
294 [NOTE] Some options in 2017-02-07 hint are no longer necessary.
296 ./configure --prefix=/usr \
300 --enable-grub-mkfont \
301 --with-platform=efi \
304 The meaning of configure options:
306 * `--enable-grub-mkfont`: This ensures `grub-mkfont` to be built.
307 If `Freetype` is not installed, remove this option and then you
308 have to get `unicode.pf2` from other sources (either the host or
311 * `--with-platform=efi`: This ensures `grub` to be built for EFI.
313 If the optional dependencies are installed, `configure` should
314 output the following information at last:
317 Build-time grub-mkfont: Yes
318 With unifont from /usr/share/fonts/unifont/unifont.pcf
320 That means `unicode.pf2` would be built and used.
328 Now as the `root` user:
332 MODIFICATION OF /etc/fstab
334 When constructing `/etc/fstab` in LFS chapter 8, add a line to
337 /dev/<name of EFI partition> /boot/efi vfat defaults 0 1
339 Systemd would mount `efivarfs` automatically. If using sysvinit,
340 add another line to mount `efivarfs`:
342 efivarfs /sys/firmware/efi/efivars efivarfs defaults 0 1
346 a) If you are going to be booting your UEFI-aware LFS system using a
347 non-LFS GRUB from your host AND if that GRUB is one (eg Fedora)
348 that allows for the kernel to be specified using that GRUB's
349 `linuxefi` attribute, so
351 linuxefi /path/to/kernel root=/path/to/root ro
353 then you don't appear to need the `/etc/fstab` line, and indeed,
354 you'll get told during the boot that the mounter knows nothing
355 about the efivars filesystem type. However, LFS's efibootmgr will
356 still be capable of interrogating your UEFI environment.
358 b) If the LFS system is booted from the LFS+Hint's grub, which doesn't
359 appear to know about the "linuxefi" attribute so using
361 linux /path/to/kernel root=/path/to/root ro
363 then, unless you have the efivars filesystem mounted, and you are
364 able to, then LFS's efibootmgr will be **not** capable of interrogating
365 your UEFI environment, and you'll be told that there is no `efivars`
368 KERNEL CONFIGURATION OPTIONS FOR EFI
370 The LFS 8.2 kernel build's `make defconfig` populated a good number of
371 the EFI-related options on my UEFI-enabled hardware, however, so as to
372 make the 2014-10-16 hint's list of settings easier to find when coming
373 to alter/set things, here is the list of the options along with the
374 location of the various checkboxes and the settings they should have,
375 as seen when starting from a `make menuconfig`:
377 ## CONFIG_EFI_PARTITION=y
380 -> Enable the block layer
382 [*] Advanced partition selection
384 [*] EFI GUID Partition support
390 -> Processor type and features
391 [*] EFI runtime service support
399 -> Frame buffer Devices
400 [*] EFI-based Framebuffer Support
402 ## CONFIG_FRAMEBUFFER_CONSOLE=y
407 -> Console display driver support
408 Framebuffer Console support (Not available on mine)
410 ## CONFIG_EFI_VARS is not set
411 ## CONFIG_EFI_RUNTIME_MAP=y
415 -> EFI (Extensible Firmware Interface) Support
416 < > EFI Variable Support via sysfs
417 [*] Export efi runtime maps to sysfs
420 ## CONFIG_EFIVAR_FS=y/m
424 -> Pseudo filesystems
425 [*] EFI Variable filesystem
429 The only Kernel Config setting that a `make defconfig` didn't set on
430 the UEFI-enabled host was this one:
434 and without that setting in the kernel, attempts to boot the LFS system
437 Kernel doesn't support EFI handover
439 however, adding just that one Kernel Config setting sees you able to
440 boot into the LFS system using the host system's Grub.
442 `CONFIG_FB_EFI=y` seems not necessary if you have other FB devices
443 avaliable. But without it you will lose some boot messages along
444 with the Tux logos on the FB.
446 USING GRUB TO SET UP THE BOOT PROCESS
448 INSTALLING GRUB TO THE EFI PARTITION
450 Installing GRUB to the EFI partition and creating an OS Boot Manager
451 entry is the major difference between the recipes in this hint and the
452 procedures in the LFS book. In concept, it is not actually a divergence
453 from the concepts of the book. The instructions there install GRUB to
454 the MBR, the MBR protected layer of a GPT disk or to a dedicated /boot
455 partition. The recipes here install GRUB to the EFI partition and
456 generate an entry in the system's Boot Manager. It is for the single
457 command here that this hint was written and for which all the non-LFS
458 packages were installed.
460 grub-install --bootloader-id=LFS --recheck --debug &> grub.log
462 `--bootloader-id=<some name>` is the directory on the EFI partition to
463 which the GRUB image is written.
465 Running this command generates lots of output (redirected to `grub.log`).
466 But at the end it will indicate that it was successful. This command
467 installs the GRUB image to `/boot/efi/EFI/LFS/grubx64.efi` and creates
468 the entry `LFS` in the system's Boot Manager.
470 To check it, inspect the contents of `/boot/efi/EFI/LFS` and, as root, run
471 `efibootmgr`. The results of this command will list the Boot Order and
472 all the Boot Entries. If the entry "LFS" does not appear, read the
473 efibootmgr man page, create an entry and change the Boot Order to what is
476 If GRUB was built with `freetype` and `unifont`, `unicode.pf2` should be
477 installed automatically now. Issue:
479 grep "unicode.pf2" grub.log
481 You should see something like
483 copying `/usr/share/grub/unicode.pf2' -> `/boot/grub/fonts/unicode.pf2'
485 If not, you should get `unicode.pf2` from the host system or Internet,
486 and install it into `/boot/grub/fonts`.
492 cat > /boot/grub/grub.cfg << "EOF"
493 # Begin /boot/grub/grub.cfg
500 set root=(hd[x], gpt[y])
501 # hd[x] is the drive of the LFS partion and gpt[y] is the partition
506 if loadfont /boot/grub/fonts/unicode.pf2; then
507 loadfont /boot/grub/fonts/unicode.pf2
511 terminal_output gfxterm
514 menuentry "GNU/Linux, Linux <kernel name>" {
515 linux /boot/vmlinuz-<kernel name> root=/dev/sda[x] ro
519 Note that in `menuentry`, `/dev/sda[x]` is the device of the LFS
522 [NOTE] From GRUB's perspective, the kernel files are relative
523 to the partition used. If you used a separate `/boot` partition,
524 remove `/boot` from the above linux line and path of `unicode.pf2`.
525 You will also need to change the `set root` line to point to the
530 As stated before, the implementation of UEFI firmware and its manipulation
531 depends hugely on the manufacturer. As of the initial writing of this
532 hint, there is no standard approach. Therefore, while the recipes here all
533 do what is advertised, regrettably the system may not default to the grub
534 boot loader "out of the box." In that case, reviewing References 1-3, will
535 provide information that will lead users to a solution to the situation.
536 As always, one of the best resources is the {,B}LFS mailing lists.
538 At this point, it is worth stating that there are other helpful tools:
539 gummiboot and rEFInd are two of them. They are described as Boot Managers,
540 but in fact are a user space layer between the OS Boot Manager and the Boot
541 Loader. Information about both is in the references.
545 1. Rod's Books - A collection of web page articles that goes into great
546 detail about the concepts of UEFI booting, partitioning and tools.
547 The below URL goes right to the efi information. www.rodsbooks.com is
548 the main page and has many, many good articles.
549 URL: http://www.rodsbooks.com/efi-bootloaders/index.html
551 2. "Unified Extensible Firmware Interface - ArchWiki"
552 URL: https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface
555 URL: https://wiki.archlinux.org/index.php/GRUB
557 4. Google. URL: https://google.com
561 * Craig Magee for comments and testing.
562 * Pierre Labastie for testing, font manipulation and comments.
563 * Lei Niu for comments on efivar and grub.cfg issues.
566 * Add paragraph and section numbers and TOC to make searchable
567 * Add appendix for migration from Legacy Boot to UEFI boot
568 * Add appendix for more options to default to GRUB
569 * Add appendix for LVM
570 * Add appendix for "standalone" GRUB on EFI partition independent
575 Use linuxfromscratch.org URL for grub patch
577 Update to efibootmgr-16
579 Add instructions creating new EFI partition
582 Added grub patch for binutils-2.31
586 Use BLFS-like format for package dependency list
587 Use package name in BLFS (FreeType instead of Freetype2)
588 Deleted dosfstools-3.0.28 (replaced by dosfstools-4.1 in BLFS)
589 Updated efivar-30 to efivar-34
590 Updated unifont-9.0.06 to unifont-10.0.07
591 Updated GRUB-2.02~beta3 to GRUB-2.02
592 Modified the hint to let GRUB install unicode.pf2 automatically
593 Removed some options not necessary now
594 Fixed path to unicode.pf2 in grub.cfg for those without /boot partition
595 Copied note about seperated /boot partition for grub.cfg from LFS book
596 Removed incorrect personal email addresses (they are LFS mail lists)
598 Adapted for checkHint script (AUTHORS to AUTHOR)
601 Updated for LFS 7.10 and "extra package" updates
602 dosfstools-3.0.26 -> dosfstools-3.0.28
603 efivar-0.12 -> efivar-30
604 efibootmgr-0.9.0 -> efibootmgr-14
605 unifont-7.0.05 -> unifont-9.0.06