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
21 Base LFS system before or after Ch. 8
22 Basic understanding of obtaining and building packages
26 DISCLAIMER: The recipes in this hint neither supplant nor supersede the
27 build instructions in a stable version of either the LFS or BLFS books.
28 They merely augment them for newer firmware. If conflicts arise between
29 this hint and the instructions in the book, take the issue to the mailing
30 lists. Additionally, this hint applies to only x86_64 machines packaged
31 with Windows 7 or Windows 8. The recipes here can be used on Mac OS, but
32 have not been investigated at the initial writing of this hint.
34 USE OF TERMS: The following is a use of terms in this hint. Further
35 information for and amplification of them can be found in References 1-3.
37 BIOS Settings: A firmware interface accessed by the keyboard after power
38 is applied. In it a user can change the order and way of how the computer
41 BIOS System: Firmware with an MBR
43 EFI Mode: A condition of the booted system in which the EFI partition is
44 mounted and the uefi (efi) variable support in the kernel is working
45 properly. It results from enabling UEFI Mode in BIOS Settings.
47 EFI Mount Point: A user defined mount point for the EFI Partition. In
48 this hint, and in most distros, it is /boot/efi.
50 EFI Partition: A small partition, usually before any other partitions;
51 i.e., /dev/sda1 of 200-250 Mb, formatted in FAT32 with the /boot flag, in
52 parted, or ef00 (EF00) partition type in gdisk. (NOTE: The boot flag has a
53 different function and meaning in MBR partitioned disks.)
55 efi variables (synonymous: uefi variables): variables through which the
56 operating system can interact with the firmware.
58 Legacy Boot Option (Legacy Boot): A boot process in BIOS Settings that
59 disables UEFI booting and uses CIM.
61 GUID Partition Table (GPT): A partitioning scheme that uses UUID's instead
62 of cylinders to identify partitions.
65 PRELIMINARY DISCUSSION: Additional information and more in depth
66 discussion of the following concepts can be found using References 1-3.
68 Booting LFS is no longer as simple as "grub-install /dev/sda." There are
69 more options and more considerations. With the advent and proliferation of
70 UEFI firmware, a user's knowledge and philosophy of the boot
71 process requires expansion:
72 a) GPT partitioning is different from MBR partitioning. The tool fdisk
73 is not able to manipulate GPT partitions. Parted and gdisk (from
74 gptfdisk) are the tools to use. Each has their pros and cons,
75 supporters and detractors. Either one or both can be used.
76 (Update: fdisk now supports GPT partitioned disk drives.)
77 b) UEFI firmware uses Boot Managers to select Boot Loaders like GRUB or
78 LILO. They, themselves do not boot the machine.
79 c) The Boot Loaders are placed on the EFI partition rather than the
80 MBR. This concept is similar and parallel to the LFS procedures of
81 using a separate /boot partition.
82 d) There are additional tools that LFS needs in order to accomplish
84 e) LFS can be built and booted as the instructions are written up to
85 and including LFS-7.6. To do this on UEFI firmware, the BIOS
86 Settings must be changed to Legacy Options from UEFI Options.
88 One of the hugely discussed issues surrounding UEFI is Secure Boot. It is
89 necessary to understand that the terms "UEFI" and "Secure Boot" are NOT
90 synonymous. UEFI is firmware. Secure Boot is a process of using "keys" to
91 "guarantee" the safety and authenticity of a Boot Loader. NOTE: To use
92 the recipes in this hint, Secure Boot must be disabled in the BIOS Boot
95 Please note that the recommended order for implementing these recipes is a
96 departure from the build order in LFS. The most convenient, and arguably
97 the most practical way, to implement the recipes here is to use them in the
98 of build of an LFS System at the end of Ch. 6. Building the BLFS and
99 non-BLFS packages has been tested both inside and outside of the chroot
100 environment. Then, following the book, proceed through Ch. 7, returning to
101 the recipes in Ch. 8. The recipes are presented in that order.
103 The most inconvenient way to implement these recipes is in a completely
104 functional LFS-7.6, or earlier, system. This involves uninstalling
105 grub-2.00, removing it from its location as a result of grub-install and
106 implementing the recipes. Migrating from Legacy Boot to UEFI boot is
107 possible. At the initial writing of this hint, however, it is not
108 included. References 1-3 contain more information on this subject.
110 The last consideration in implementing the recipes here is GRUB's graphical
111 terminal. In UEFI systems, if the GRUB video mode is not initialized, no
112 kernel boot messages will appear until the kernel video takes over. The
113 GRUB package does not supply fonts, and GRUB defaults to unicode.pf2.
114 There are two ways to supply this font. The first is to copy unicode.pf2
115 from the host system to /boot/grub on the LFS system. The second method
116 involves configuring grub to build grub-mkfont, and this creates a build
117 dependency of Freetype2 for GRUB. This hint addresses both situations.
119 Finally, as of the initial writing of this hint, there is no standard for
120 the use of UEFI and the implementation of Secure Boot. These are hugely
121 manufacturer dependent. This hint uses terms used in the original author's
122 hardware. They may be different in other manufacturers' implementations.
123 However, the capabilities to do the boot setup operations contained in this
124 hint will exist on each machine. The terms may differ, and more than one
125 operation might be needed to achieve a desired goal. For example, someone
126 may need to disable Secure Boot and remove Secure Keys.
130 [NOTE] The recipes are written with the assumption that the packages are
131 being built in the chroot environment before the end of Ch. 8. They can be
132 modified, with little difficulty, to be used in a functional system.
135 Before entering the chroot environment, check that the host booted in
140 If this directory exists and is populated, the host booted in EFI Mode.
144 Determine which device is the EFI partition using gdisk or parted,
145 enter the chroot environment, create /boot/efi if needed, and
147 mount -vt vfat /dev/sda(x) /boot/efi
149 where sda(x) is the device containing the EFI partition.
153 Install the following BLFS packages, using the instructions in the book:
154 popt and pciutils. Build and install Freetype2 if building grub with
157 DOSFSTOOLS (runtime dependency of efibootmgr)
158 Note: As of October 3, 2014, dosfstools was tagged "orphaned.
159 It is still functional.]
162 http://daniel-baumann.ch/files/software/dosfstools/dosfstools-3.0.26.tar.xz
164 Build and Installation:
167 make PREFIX=/usr SBINDIR=/usr/bin MANDIR=/usr/share/man \
168 DOCDIR=/usr/share/doc install
171 EFIVAR-0.12 (depends on popt)
174 https://github.com/vathpela/efivar/releases/download/0.12/efivar-0.12.tar.bz2
177 sed 's|-O0|-Os|g' -i Make.defaults
178 sed 's|-rpath=$(TOPDIR)/src/|-rpath=$(libdir)|g' \
180 make libdir="/usr/lib/" bindir="/usr/bin/" \
181 mandir="/usr/share/man/" \
182 includedir=/usr/include/" V=1 -j1
185 make -j1 V=1 DESTDIR="${pkgdir}/" libdir="/usr/lib/" \
186 bindir="/usr/bin/" mandir="/usr/share/man" \
187 includedir="/usr/include/" install
189 install -v -D -m0755 src/test/tester /usr/bin/efivar-tester
193 (depends on pciutils, efivars,zlib to build and dosfstools to run.)
195 Download: https://github.com/vathpela/efibootmgr/releases/download/
196 efibootmgr-0.9.0/efibootmgr-0.9.0.tar.bz2
199 make EXTRA_CFLAGS="-Os"
202 install -v -D -m0755 src/efibootmgr/efibootmgr /usr/sbin/efibootmgr
203 install -v -D -m0644 src/man/man8/efibootmgr.8 \
204 /usr/share/man/man8/efibootmgr.8
207 GRUB-2.02~beta2 (depends on freetype2 if grub-mkfont is desired
208 and on efibootmgr, efivars and efivarfs at run time.)
210 Download: http://alpha.gnu.org/gnu/grub/grub-2.02~beta2.tar.xz
212 Prepare for compilation:
213 ./configure --prefix=/usr \
216 --disable-grub-emu-usb \
218 --enable-grub-mkfont \
219 --with-platform=efi \
221 --program-prefix="" \
222 --with-bootdir="/boot" \
223 --with-grubdir="grub" \
228 --enable-grub-mkfont This creates the build dependency on
229 Freetype2. To remove this dependency do not use this switch
230 and copy unicode.pf2 from the host system to /boot/grub of the
231 LFS partition. Alternatively, it can be downloaded from the
234 --program-prefix="" is a matter of convenience. If not used,
235 "x86_64" is inserted in all the grub executables. For
236 example, "grub-install" and "grub-mkconfig" become
237 x86_64-grub-install and x86_64-grub-mkconfig.
239 --with-platform=efi and --target=x86_64 are mandatory for the efi
242 The other configure options added to the ones in LFS-7.6 and
243 LFS-SVN were employed to insure that grub is built and installed
244 in the directories used in this hint. They may be used or
245 eliminated based on individual use and preference.
259 When constructing the file /etc/fstab, add the following lines:
261 /dev/sda(x) /boot/efi vfat defaults 0 1
263 efivarfs /sys/firmware/efi/efivars efivarfs defaults 0 1
265 where /dev/sda(x) is the EFI partion
270 KERNEL CONFIGURATION OPTIONS FOR EFI
272 CONFIG_EFI_PARTITION=y
275 (The above makes the kernel bootable from the EFI partition if
278 CONFIG_FRAMEBUFFER_CONSOLE=y
279 # CONFIG_EFI_VARS is not set
280 Do not enable this option. It creates runtime conflicts with
281 EFIVARFS which replaces it.
283 # CONFIG_UEFI_CPER is not set
284 # CONFIG_EARLY_PRINTK_EFI is not set
286 The module EFI_VARS will soon be deprecated and is not used except in
288 The last two options are included as of kernel 3.13.3 and may be enabled
289 based on personal and system needs.
292 USING GRUB TO SET UP THE BOOT PROCESS
294 If grub was built without grub-mkfont and unicode.pf2 is in /boot/grub,
295 skip to the next section.
298 Download and install unifont-7.0.05:
300 wget http://unifoundry.com/pub/unifont-7.0.05/font-builds/unifont-7.0.05.pcf.gz
301 mkdir -pv /usr/share/fonts/unifont
302 gunzip -c unifont-7.0.05.pcf.gz > /usr/share/fonts/unifont/unifont.pcf
303 grub-mkfont -o /usr/share/grub/unicode.pf2 \
304 /usr/share/fonts/unifont/unifont.pcf
307 INSTALLING GRUB TO THE EFI PARTITION
309 Installing GRUB to the EFI partition and creating an OS Boot Manager
310 entry is the major difference between the recipes in this hint and the
311 procedures in the LFS book. In concept, it is not actually a divergence
312 from the concepts of the book. The instructions there install GRUB to
313 the MBR, the MBR protected layer of a GPT disk or to a dedicated /boot
314 partition. The recipes here install GRUB to the EFI partition and
315 generate an entry in the system's Boot Manager. It is for the single
316 command here that this hint was written and for which all the non-LFS
317 packages were installed.
319 grub-install --target=x86_64-efi --efi-directory=/boot/efi \
320 --bootloader-id=LFS --recheck --debug
322 --efi-directory=<EFI Mount Point> not the actual EFI partition
323 --bootloader-id=<some name> is the directory on the EFI partition to
324 which the GRUB image is written.
326 Running this command generates lots of output. But at the end it will
327 indicate that it was successful. This command installs the GRUB image to
328 /boot/efi/EFI/LFS/grubx64.efi and creates the entry "LFS" in the system's
331 To check it, inspect the contents of /boot/efi/EFI/LFS and, as root, run
332 <efibootmgr>. The results of this command will list the Boot Order and
333 all the Boot Entries. If the entry "LFS" does not appear, read the
334 efibootmgr man page, create an entry and change the Boot Order to what is
341 cat > /boot/grub/grub.cfg << "EOF"
342 # Begin /boot/grub/grub.cfg
347 set root=(hd[x], gpt[y])
348 # hd[x] is the drive of the LFS partion and gpt[y] is the partition
353 if loadfont /grub/unicode.pf2; then
354 loadfont /grub/unicode.pf2
358 terminal_output gfxterm
361 menuentry "GNU/Linux, Linux <kernel name>" {
362 linux /boot/vmlinuz-<kernel name>; root=/dev/sda[x] ro
366 Note that in "menuentry" /dev/sda[x] is the device of the LFS partition.
370 As stated before, the implementation of UEFI firmware and its manipulation
371 depends hugely on the manufacturer. As of the initial writing of this
372 hint, there is no standard approach. Therefore, while the recipes here all
373 do what is advertised, regrettably the system may not default to the grub
374 boot loader "out of the box." In that case, reviewing References 1-3, will
375 provide information that will lead users to a solution to the situation.
376 As always, one of the best resources is the {,B}LFS mailing lists.
378 At this point, it is worth stating that there are other helpfultools:
379 gummiboot and rEFInd are two of them. They are described as Boot Managers,
380 but in fact are a user space layer between the OS Boot Manager and the Boot
381 Loader. Information about both is in the references.
385 1. Rod's Books A collection of web page articles that goes into great
386 detail about the concepts of UEFI booting, partitioning and tools.
387 The below URL goes right to the efi information. www.rodsbooks.com is
388 the main page and has many, many good articles.
389 URL: http://www.rodsbooks.com/efi-bootloaders/index.html
391 2. "Unified Extensible Firmware Interface-ArchWiki"
392 URL: https://wiki.archlinux.org/index.php/
393 Unified_Extensible_Firmware_Interface
396 URL: https://wiki.archlinux.org/index.php/GRUB
402 * Craig Magee <lfs-support at lists.linuxfromscratch.org> for comments and testing
403 * Pierre Labastie <http://lists.linuxfromscratch.org/listinfo/lfs-dev> for testing,
404 font manipulation and comments.
407 * Add paragraph and section numbers and TOC to make searchable
408 * Add appendix for migration from Legacy Boot to UEFI boot
409 * Add appendix for more options to default to GRUB
410 * Add appendix for LVM
411 * Add appendix for "standalone" GRUB on EFI partition independent