Index: postlfs/filesystems/filesystems.xml
===================================================================
--- postlfs/filesystems/filesystems.xml	(revision 64b8189f92785f669ffc75036d1c82a90ce73954)
+++ postlfs/filesystems/filesystems.xml	(revision 756a787f17843fefeb3044393a4c868e39f230c7)
@@ -42,4 +42,9 @@
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="sshfs.xml"/>
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="xfsprogs.xml"/>
+  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="uefi-bootloaders/dummy.xml"/>
+  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="uefi-bootloaders/efivar.xml"/>
+  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="uefi-bootloaders/efibootmgr.xml"/>
+  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="uefi-bootloaders/grub-efi.xml"/>
+  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="uefi-bootloaders/grub-setup.xml"/>
 
 </chapter>
Index: postlfs/filesystems/uefi-bootloaders/dummy.xml
===================================================================
--- postlfs/filesystems/uefi-bootloaders/dummy.xml	(revision 756a787f17843fefeb3044393a4c868e39f230c7)
+++ postlfs/filesystems/uefi-bootloaders/dummy.xml	(revision 756a787f17843fefeb3044393a4c868e39f230c7)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+   "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+
+<sect1 role="dummy">
+
+  <sect1info>
+    <othername>$LastChangedBy: renodr $</othername>
+    <date>$Date: 2020-10-06 04:28:57 +0800 (二, 2020-10-06) $</date>
+  </sect1info>
+
+  <title>Packages for UEFI Boot</title>
+  <para/>
+</sect1>
+
Index: postlfs/filesystems/uefi-bootloaders/efibootmgr.xml
===================================================================
--- postlfs/filesystems/uefi-bootloaders/efibootmgr.xml	(revision 756a787f17843fefeb3044393a4c868e39f230c7)
+++ postlfs/filesystems/uefi-bootloaders/efibootmgr.xml	(revision 756a787f17843fefeb3044393a4c868e39f230c7)
@@ -0,0 +1,186 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+   "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+  <!ENTITY % general-entities SYSTEM "../../../general.ent">
+  %general-entities;
+
+  <!ENTITY efibootmgr-download-http "https://github.com/rhboot/efibootmgr/releases/download/&efibootmgr-version;/efibootmgr-&efibootmgr-version;.tar.bz2">
+  <!ENTITY efibootmgr-download-ftp  " ">
+  <!ENTITY efibootmgr-md5sum        "6ae315936d9bc8613b3a4cb8a4064128">
+  <!ENTITY efibootmgr-size          "44 KB">
+  <!ENTITY efibootmgr-buildsize     "592 KB">
+  <!ENTITY efibootmgr-time          "less than 0.1 SBU">
+]>
+
+<sect1 id="efibootmgr" xreflabel="efibootmgr-&efibootmgr-version;">
+  <?dbhtml filename="efibootmgr.html"?>
+
+  <sect1info>
+    <othername>$LastChangedBy: bdubbs $</othername>
+    <date>$Date: 2021-02-21 03:35:58 +0800 (日, 2021-02-21) $</date>
+  </sect1info>
+
+  <title>efibootmgr-&efibootmgr-version;</title>
+
+  <indexterm zone="efibootmgr">
+    <primary sortas="a-efibootmgr">efibootmgr</primary>
+  </indexterm>
+
+  <sect2 role="package">
+    <title>Introduction to efibootmgr</title>
+
+    <para>
+      The <application>efibootmgr</application> package provides tools and
+      libraries to manipulate EFI variables.
+    </para>
+
+    &lfs101_checked;
+
+    <bridgehead renderas="sect3">Package Information</bridgehead>
+    <itemizedlist spacing="compact">
+      <listitem>
+        <para>
+          Download (HTTP): <ulink url="&efibootmgr-download-http;"/>
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Download (FTP): <ulink url="&efibootmgr-download-ftp;"/>
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Download MD5 sum: &efibootmgr-md5sum;
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Download size: &efibootmgr-size;
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Estimated disk space required: &efibootmgr-buildsize;
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Estimated build time: &efibootmgr-time;
+        </para>
+      </listitem>
+    </itemizedlist>
+
+    <bridgehead renderas="sect3">efibootmgr Dependencies</bridgehead>
+
+    <bridgehead renderas="sect4">Required</bridgehead>
+    <para role="required">
+      <xref linkend="efivar"/> and
+      <xref linkend="popt"/>
+    </para>
+
+    <para condition="html" role="usernotes">User Notes:
+    <ulink url="&blfs-wiki;/efibootmgr"/></para>
+
+  </sect2>
+
+  <sect2 role="installation">
+    <title>Installation of efibootmgr</title>
+
+    <para>
+      At first, fix an outdated hotfix declaration causing compilation
+      failure:
+    </para>
+
+<screen><userinput>sed -e '/extern int efi_set_verbose/d' -i src/efibootmgr.c</userinput></screen>
+
+    <para>
+      Build <application>efibootmgr</application> with the following
+      commands:
+    </para>
+
+<screen><userinput>make EFIDIR=LFS EFI_LOADER=grubx64.efi</userinput></screen>
+
+    <para>
+      This package does not have a test suite.
+    </para>
+
+    <para>
+      Now, as the <systemitem class="username">root</systemitem> user:
+    </para>
+
+<screen role="root"><userinput>make install sbindir=/sbin EFIDIR=LFS</userinput></screen>
+
+  </sect2>
+
+  <sect2 role="commands">
+    <title>Command Explanations</title>
+
+    <para>
+      <parameter>EFIDIR=LFS</parameter>:
+      This option specify the distro's subdirectory name under
+      <filename class="directory">/boot/efi/EFI</filename>.
+      The building system of this package needs it to be set explicitly.
+    </para>
+
+    <para>
+      <parameter>EFI_LOADER=grubx64.efi</parameter>:
+      This option specify the name of the default EFI boot loader.  It is
+      set to match the EFI boot loader provided by
+      GRUB<!--xref linkend="grub-efi"/-->.
+    </para>
+
+    <para>
+      <parameter>sbindir=/sbin</parameter>:
+      Make <command>efibootmgr</command> avaliable even if
+      <filename class="directory">/usr</filename> is offline.
+    </para>
+  </sect2>
+
+  <sect2 role="content">
+    <title>Contents</title>
+
+    <segmentedlist>
+      <segtitle>Installed Programs</segtitle>
+
+      <seglistitem>
+        <seg>
+          efibootdump and efibootmgr
+        </seg>
+      </seglistitem>
+    </segmentedlist>
+
+    <variablelist>
+      <bridgehead renderas="sect3">Short Descriptions</bridgehead>
+      <?dbfo list-presentation="list"?>
+      <?dbhtml list-presentation="table"?>
+
+      <varlistentry id="efibootdump">
+        <term><command>efibootmgr</command></term>
+        <listitem>
+          <para>
+            is a tool to display individual UEFI boot options, from a file
+            or an UEFI variable
+          </para>
+          <indexterm zone="efibootdump">
+            <primary sortas="b-efibootdump">efibootdump</primary>
+          </indexterm>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry id="efibootmgr-prog">
+        <term><command>efibootmgr</command></term>
+        <listitem>
+          <para>
+            is a tool to manipulate the UEFI Boot Manager
+          </para>
+          <indexterm zone="efibootmgr efibootmgr-prog">
+            <primary sortas="b-efibootmgr">efibootmgr</primary>
+          </indexterm>
+        </listitem>
+      </varlistentry>
+
+    </variablelist>
+
+  </sect2>
+
+</sect1>
Index: postlfs/filesystems/uefi-bootloaders/efivar.xml
===================================================================
--- postlfs/filesystems/uefi-bootloaders/efivar.xml	(revision 756a787f17843fefeb3044393a4c868e39f230c7)
+++ postlfs/filesystems/uefi-bootloaders/efivar.xml	(revision 756a787f17843fefeb3044393a4c868e39f230c7)
@@ -0,0 +1,218 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+   "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+  <!ENTITY % general-entities SYSTEM "../../../general.ent">
+  %general-entities;
+
+  <!ENTITY efivar-download-http "https://github.com/rhboot/efivar/releases/download/&efivar-version;/efivar-&efivar-version;.tar.bz2">
+  <!ENTITY efivar-download-ftp  " ">
+  <!ENTITY efivar-md5sum        "9f067275c5f7aafdd75bfb364280ac9c">
+  <!ENTITY efivar-size          "108 KB">
+  <!ENTITY efivar-buildsize     "2.75 MB">
+  <!ENTITY efivar-time          "less than 0.1 SBU">
+]>
+
+<sect1 id="efivar" xreflabel="efivar-&efivar-version;">
+  <?dbhtml filename="efivar.html"?>
+
+  <sect1info>
+    <othername>$LastChangedBy: bdubbs $</othername>
+    <date>$Date: 2021-02-21 03:35:58 +0800 (日, 2021-02-21) $</date>
+  </sect1info>
+
+  <title>efivar-&efivar-version;</title>
+
+  <indexterm zone="efivar">
+    <primary sortas="a-efivar">efivar</primary>
+  </indexterm>
+
+  <sect2 role="package">
+    <title>Introduction to efivar</title>
+
+    <para>
+      The <application>efivar</application> package provides tools and
+      libraries to manipulate EFI variables.
+    </para>
+
+    &lfs101_checked;
+
+    <bridgehead renderas="sect3">Package Information</bridgehead>
+    <itemizedlist spacing="compact">
+      <listitem>
+        <para>
+          Download (HTTP): <ulink url="&efivar-download-http;"/>
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Download (FTP): <ulink url="&efivar-download-ftp;"/>
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Download MD5 sum: &efivar-md5sum;
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Download size: &efivar-size;
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Estimated disk space required: &efivar-buildsize;
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Estimated build time: &efivar-time;
+        </para>
+      </listitem>
+    </itemizedlist>
+
+    <bridgehead renderas="sect3">Additional Downloads</bridgehead>
+    <itemizedlist spacing="compact">
+      <listitem>
+        <para>
+          Required patch:
+          <ulink url="&patch-root;/efivar-&efivar-version;-gcc_9-1.patch"/>
+        </para>
+      </listitem>
+    </itemizedlist>
+
+    <para condition="html" role="usernotes">User Notes:
+    <ulink url="&blfs-wiki;/efivar"/></para>
+
+  </sect2>
+
+  <sect2 role="installation">
+    <title>Installation of efivar</title>
+
+    <para>
+      At first, apply a patch to fix an issue breaking the build with GCC 9
+      or later:
+    </para>
+
+<screen><userinput>patch -Np1 -i ../efivar-37-gcc_9-1.patch</userinput></screen>
+
+    <para>
+      Build <application>efivar</application> with the following
+      commands:
+    </para>
+
+<screen><userinput>make CFLAGS="-O2 -Wno-stringop-truncation"</userinput></screen>
+
+    <para>
+      The test suite of this package is dangerous.  Running it may trigger
+      firmware bugs and make your system unusable without using some special
+      hardware to reprogram the firmware.
+    </para>
+
+    <para>
+      Now, as the <systemitem class="username">root</systemitem> user:
+    </para>
+
+<screen role="root"><userinput>make install LIBDIR=/usr/lib BINDIR=/bin</userinput></screen>
+
+    <para>
+      Move the shared libraries to <filename class="directory">/lib</filename>,
+      and recreate the symlinks in <filename class="directory">/usr/lib</filename>:
+    </para>
+
+<screen role="root"><userinput>mv /usr/lib/libefi{boot,var}.so.* /lib &amp;&amp;
+ln -sfv ../../lib/$(readlink /usr/lib/libefiboot.so) /usr/lib/libefiboot.so &amp;&amp;
+ln -sfv ../../lib/$(readlink /usr/lib/libefivar.so) /usr/lib/libefivar.so
+</userinput></screen>
+
+  </sect2>
+
+  <sect2 role="commands">
+    <title>Command Explanations</title>
+
+    <para>
+      <parameter>CFLAGS="-O2 -Wno-stringop-truncation"</parameter>:
+      This option overrides the compiler flags defaulted by this package,
+      to avoid build failure.
+    </para>
+
+    <para>
+      <parameter>LIBDIR=/usr/lib</parameter>:
+      This option overrides the default library directory of the package
+      (<filename class="directory">/usr/lib64</filename>, which is not used
+      by LFS.)
+    </para>
+
+    <para>
+      <parameter>BINDIR=/bin</parameter>:
+      Make <command>efivar</command> avaliable even if
+      <filename class="directory">/usr</filename> is offline.
+    </para>
+  </sect2>
+
+  <sect2 role="content">
+    <title>Contents</title>
+
+    <segmentedlist>
+      <segtitle>Installed Programs</segtitle>
+      <segtitle>Installed Libraries</segtitle>
+      <segtitle>Installed Directories</segtitle>
+
+      <seglistitem>
+        <seg>
+          efivar
+        </seg>
+        <seg>
+          libefiboot.so and libefivar.so
+        </seg>
+        <seg>
+          /usr/include/efivar
+        </seg>
+      </seglistitem>
+    </segmentedlist>
+
+    <variablelist>
+      <bridgehead renderas="sect3">Short Descriptions</bridgehead>
+      <?dbfo list-presentation="list"?>
+      <?dbhtml list-presentation="table"?>
+
+      <varlistentry id="efivar-prog">
+        <term><command>efivar</command></term>
+        <listitem>
+          <para>
+            is a tool to manipulate UEFI variables
+          </para>
+          <indexterm zone="efivar efivar-prog">
+            <primary sortas="b-efivar">efivar</primary>
+          </indexterm>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry id="libefiboot">
+        <term><filename class="libraryfile">libefiboot.so</filename></term>
+        <listitem>
+          <para>
+            is a library used by <command>efibootmgr</command>
+          </para>
+          <indexterm zone="efivar libefiboot">
+            <primary sortas="c-libefiboot">libefiboot.so</primary>
+          </indexterm>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry id="libefivar">
+        <term><filename class="libraryfile">libefivar.so</filename></term>
+        <listitem>
+          <para>
+            is a library for the manipulation of EFI variables
+          </para>
+          <indexterm zone="efivar libefiboot">
+            <primary sortas="c-libefiboot">libefiboot.so</primary>
+          </indexterm>
+        </listitem>
+      </varlistentry>
+
+    </variablelist>
+
+  </sect2>
+
+</sect1>
Index: postlfs/filesystems/uefi-bootloaders/grub-efi.xml
===================================================================
--- postlfs/filesystems/uefi-bootloaders/grub-efi.xml	(revision 756a787f17843fefeb3044393a4c868e39f230c7)
+++ postlfs/filesystems/uefi-bootloaders/grub-efi.xml	(revision 756a787f17843fefeb3044393a4c868e39f230c7)
@@ -0,0 +1,214 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+   "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+  <!ENTITY % general-entities SYSTEM "../../../general.ent">
+  %general-entities;
+
+  <!ENTITY grub-efi-download-http "https://alpha.gnu.org/gnu/grub/grub-&grub-version;.tar.xz">
+  <!ENTITY grub-efi-download-ftp  " ">
+  <!ENTITY grub-efi-md5sum        "3c222b51347c182d655f9b94d5b56582">
+  <!ENTITY grub-efi-size          "6.2 MB">
+  <!ENTITY grub-efi-buildsize     "592 KB">
+  <!ENTITY grub-efi-time          "less than 0.1 SBU">
+
+  <!ENTITY unifont-download-http  "http://unifoundry.com/pub/unifont/unifont-&unifont-version;/font-builds/unifont-&unifont-version;.pcf.gz">
+  <!ENTITY unifont-md5sum         "4fbc33c8d8d25985f1bcdd4d28bc2420">
+  <!ENTITY unifont-size           "1.3 MB">
+]>
+
+<sect1 id="grub-efi" xreflabel="GRUB-&grub-version; for EFI">
+  <?dbhtml filename="grub-efi.html"?>
+
+  <sect1info>
+    <othername>$LastChangedBy: bdubbs $</othername>
+    <date>$Date: 2021-02-21 03:35:58 +0800 (日, 2021-02-21) $</date>
+  </sect1info>
+
+  <title>GRUB-&grub-version; for EFI</title>
+
+  <indexterm zone="grub-efi">
+    <primary sortas="a-grub-efi">grub-efi</primary>
+  </indexterm>
+
+  <sect2 role="package">
+    <title>Introduction to GRUB</title>
+
+    <para>
+      The <application>GRUB</application> package provides GRand Unified
+      Bootloader.  In this page it will be built with UEFI support, which
+      is not enabled for GRUB built in LFS.
+    </para>
+
+    &lfs101_checked;
+
+    <bridgehead renderas="sect3">Package Information</bridgehead>
+    <itemizedlist spacing="compact">
+      <listitem>
+        <para>
+          Download (HTTP): <ulink url="&grub-efi-download-http;"/>
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Download (FTP): <ulink url="&grub-efi-download-ftp;"/>
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Download MD5 sum: &grub-efi-md5sum;
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Download size: &grub-efi-size;
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Estimated disk space required: &grub-efi-buildsize;
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Estimated build time: &grub-efi-time;
+        </para>
+      </listitem>
+    </itemizedlist>
+
+    <bridgehead renderas="sect3">Additional Downloads</bridgehead>
+
+    <itemizedlist spacing="compact">
+      <title>Unicode font data used to display GRUB menu</title>
+      <listitem>
+        <para>
+          Download (HTTP): <ulink url="&unifont-download-http;"/>
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Download MD5 sum: &unifont-md5sum;
+        </para>
+      </listitem>
+      <listitem>
+        <para>
+          Download size: &unifont-size;
+        </para>
+      </listitem>
+    </itemizedlist>
+
+    <bridgehead renderas="sect3">GRUB Dependencies</bridgehead>
+
+    <bridgehead renderas="sect4">Required (runtime)</bridgehead>
+    <para role="runtime">
+      <xref linkend="efibootmgr"/>
+    </para>
+
+    <bridgehead renderas="sect4">Recommended</bridgehead>
+    <para role="recommended">
+      <xref linkend="freetype2"/>
+    </para>
+
+    <bridgehead renderas="sect4">Optional</bridgehead>
+    <para role="optional">
+      <xref linkend="lvm2"/>
+    </para>
+
+    <para condition="html" role="usernotes">User Notes:
+    <ulink url="&blfs-wiki;/grub-efi"/></para>
+
+  </sect2>
+
+  <sect2 role="installation">
+    <title>Installation of GRUB</title>
+
+    <para>
+      At first, install font data as the
+      <systemitem class="username">root</systemitem> user:
+    </para>
+
+<screen role="root"><userinput>mkdir -pv /usr/share/fonts/unifont &amp;&amp;
+gunzip -c unifont-&unifont-version;.pcf.gz > /usr/share/fonts/unifont/unifont.pcf</userinput></screen>
+
+    <warning>
+      <para>Unset any environment variables which may affect the build:</para>
+
+      <screen><userinput>unset {C,CPP,CXX,LD}FLAGS</userinput></screen>
+
+      <para>Don't try <quote>tuning</quote> this package with custom
+      compilation flags: this package is a bootloader, with low-level
+      operations in the source code which is likely to be broken by some
+      aggressive optimizations.</para>
+    </warning>
+
+    <para>
+      Build <application>GRUB</application> with the following commands:
+    </para>
+
+<screen><userinput>./configure --prefix=/usr        \
+            --sbindir=/sbin      \
+            --sysconfdir=/etc    \
+            --disable-efiemu     \
+            --enable-grub-mkfont \
+            --with-platform=efi  \
+            --disable-werror     &amp;&amp;
+
+make</userinput></screen>
+
+    <para>
+      This package does not have a test suite providing meaningful result.
+    </para>
+
+    <para>
+      Now, as the <systemitem class="username">root</systemitem> user:
+    </para>
+
+<screen role="root"><userinput>make install &amp;&amp;
+mv -v /etc/bash_completion.d/grub /usr/share/bash-completion/completions</userinput></screen>
+
+  </sect2>
+
+  <sect2 role="commands">
+    <title>Command Explanations</title>
+
+    <para>
+      <parameter>--enable-grub-mkfont</parameter>: Built the tool named
+      <command>grub-mkfont</command> to generate font file for the boot
+      loader, from the font data we've installed.
+    </para>
+
+    <warning>
+      <para>If the recommended dependency <xref linkend="freetype2"/> is not
+      installed, it's possible to omit this option and build GRUB.  However,
+      if <command>grub-mkfont</command> is not built, or the unicode font
+      data is not avaliable at the time GRUB is built, GRUB won't install
+      any font for the boot loader.  The GRUB boot menu will be displayed
+      in an ugly way, and the early stage of kernel initialization will be
+      in <quote>blind mode</quote> - you can't see any kernel message before
+      the graphics card driver is initialized.  It will be very difficult to
+      diagnostic some boot issue (especially, if the graphics driver is
+      built as module).</para>
+    </warning>
+
+    <para>
+      <parameter>--with-platform=efi</parameter>: Ensures to build GRUB with
+      for EFI.
+    </para>
+
+  </sect2>
+
+  <sect2>
+    <title>Configuring GRUB</title>
+
+    <para>
+      Using GRUB to make the LFS system bootable on UEFI platform will be
+      discussed in <xref linkend="grub-setup"/>.
+    </para>
+  </sect2>
+
+  <sect2 role="content">
+    <title>Contents</title>
+
+    <para>See the page for GRUB in LFS book.</para>
+  </sect2>
+
+</sect1>
Index: postlfs/filesystems/uefi-bootloaders/grub-setup.xml
===================================================================
--- postlfs/filesystems/uefi-bootloaders/grub-setup.xml	(revision 756a787f17843fefeb3044393a4c868e39f230c7)
+++ postlfs/filesystems/uefi-bootloaders/grub-setup.xml	(revision 756a787f17843fefeb3044393a4c868e39f230c7)
@@ -0,0 +1,429 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+   "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+  <!ENTITY % general-entities SYSTEM "../../../general.ent">
+  %general-entities;
+]>
+
+<sect1 id="grub-setup" xreflabel="Using GRUB to Set Up the Boot Process with UEFI">
+  <?dbhtml filename="grub-setup.html"?>
+
+  <sect1info>
+    <othername>$LastChangedBy: bdubbs $</othername>
+    <date>$Date: 2021-02-21 03:35:58 +0800 (日, 2021-02-21) $</date>
+  </sect1info>
+
+  <title>Using GRUB to Set Up the Boot Process with UEFI</title>
+
+  <sect2>
+    <title>Turn Off Secure Boot</title>
+
+    <para>
+      BLFS doesn't have the essential packages to support Secure Boot. To
+      set up the boot process with GRUB for UEFI installed in BLFS, Secure
+      Boot must be turned off from the configuration interface of the
+      firmware.  Read the documentation provided by the manufacturer of your
+      system to find out how.
+    </para>
+  </sect2>
+
+  <sect2>
+    <title>Create an Emergency Boot Disk</title>
+
+    <para>
+      Ensure that an emergency boot disk is ready to <quote>rescue</quote>
+      the system, in case the system becomes un-bootable.  To make a
+      emergency boot disk with GRUB for EFI platform, at first find a spare
+      USB flash drive and create a
+      <systemitem class="filesystem">vfat</systemitem> file system on it.
+      Install <xref linkend="dosfstools"/> first, then
+      as the <systemitem class="username">root</systemitem> user:
+    </para>
+
+    <warning>
+      <para>
+        The following command will erase all directories and files in the
+        partition.  Make sure your USB flash drive contains no data which
+        will be needed, and change <userinput>sdx1</userinput> to the
+        device node corresponding to the first partition of the USB flash
+        drive.  Be careful not to overwrite your hard drive with a typo!
+      </para>
+    </warning>
+
+    <screen role="nodump"><userinput>mkfs.vfat /dev/sdx1</userinput></screen>
+
+    <para>
+      Still as the <systemitem class="username">root</systemitem> user, use
+      the CLI of <command>fdisk</command> utility to set the first parition
+      of the USB flash drive to be an <quote>EFI system</quote> partition
+      (change <userinput>sdx</userinput> to the device node corresponding
+      to your USB flash drive):
+    </para>
+
+<screen role="nodump"><userinput>fdisk /dev/sdx</userinput>
+<literal>
+Welcome to fdisk (util-linux 2.36.2).
+Changes will remain in memory only, until you decide to write them.
+Be careful before using the write command.
+
+
+Command (m for help): </literal><userinput>t</userinput>
+<literal>Selected partition 1
+Hex code or alias (type L to list all): </literal><userinput>ef</userinput>
+<literal>Changed type of partition 'Linux' to 'EFI (FAT-12/16/32)'.
+
+Command (m for help): </literal><userinput>w</userinput>
+<literal>The partition table has been altered.
+Calling ioctl() to re-read partition table.
+Syncing disks.</literal></screen>
+
+    <para>
+      Still as the <systemitem class="username">root</systemitem> user,
+      create a mount point for the EFI partition on the USB flash drive
+      and mount it:
+    </para>
+
+<screen role="nodump"><userinput>mkdir -pv /mnt/rescue &amp;&amp;
+mount -v -t vfat /dev/sdx1 /mnt/rescue</userinput></screen>
+
+    <para>
+      Install GRUB for EFI on the partition:
+    </para>
+
+<screen role="nodump"><userinput>grub-install --removable --efi-directory=/mnt/rescue --boot-directory=/mnt/rescue/grub</userinput></screen>
+
+    <para>
+      Unmount the partition:
+    </para>
+
+<screen role="nodump"><userinput>umount /mnt/rescue</userinput></screen>
+
+    <para>
+      Now the USB flash drive can be used as a emergency boot disk on x86-64
+      UEFI platform.  It will boot the system and show GRUB shell.  Then you
+      can type commands to boot your operation systems on the hard drive.
+      To get how to select the boot device, read the manual of your
+      motherboard or laptop.
+    </para>
+
+  </sect2>
+
+  <sect2 role="kernel" id="uefi-kernel">
+    <title>Kernel Configuration for UEFI support</title>
+
+    <para>
+      Enable the following options in the kernel configuration and recompile
+      the kernel if necessary:
+    </para>
+
+<screen><literal>Processor type and features ---&gt;
+  [*] EFI runtime service support                              [CONFIG_EFI]
+  [*]   EFI stub support                                       [CONFIG_EFI_STUB]
+Firmware Drivers ---&gt;
+  EFI (Extensible Firmware Interface) Support ---&gt;
+    &lt; &gt; EFI Variable Support via sysfs                         [CONFIG_EFI_VARS]
+    [*] Export efi runtime maps to sysfs                       [CONFIG_EFI_RUNTIME_MAP]
+Enable the block layer ---&gt;
+  Partition Types ---&gt;
+    [*] Advanced partition selection                           [CONFIG_PARTITION_ADVANCED]
+    [*] EFI GUID Partition support                             [CONFIG_EFI_PARTITION]
+Device Drivers ---&gt;
+  Graphics support ---&gt;
+    Frame buffer Devices ---&gt;
+      Support for frame buffer devices ---&gt;                    [CONFIG_FB]
+        [*] EFI-based Framebuffer support                      [CONFIG_FB_EFI]
+    Console display driver support ---&gt;
+      [*] Framebuffer Console support                          [CONFIG_FRAMEBUFFER_CONSOLE]
+File systems ---&gt;
+  Pseudo filesystems ---&gt;
+    &lt;*/M&gt; EFI Variable filesystem                              [CONFIG_EFIVAR_FS]</literal></screen>
+
+    <variablelist>
+      <title>The meaning of the configure options:</title>
+
+      <varlistentry>
+        <term><parameter>CONFIG_EFI_STUB</parameter></term>
+        <listitem>
+          <para>Though EFI stub is designed to boot a kernel directly from
+          the UEFI firmware (without bootloaders like GRUB), GRUB needs the
+          kernel being loaded to support EFI handover protocol enabled by
+          this option.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><parameter>CONFIG_EFI_VARS</parameter></term>
+        <listitem>
+          <para>Don't use this option deprecated because of an 1024-byte
+          variable size limit.  Its function is replaced by
+          <parameter>CONFIG_EFIVAR_FS</parameter>.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><parameter>CONFIG_FB_EFI</parameter> and <parameter>CONFIG_FRAMEBUFFER_CONSOLE</parameter></term>
+        <listitem>
+          <para>The combination of these two options allows the kernel to
+          print debug messages (along with Tux logos) on early stage of boot
+          process with UEFI.</para>
+        </listitem>
+      </varlistentry>
+
+    </variablelist>
+
+  </sect2>
+
+  <sect2>
+    <title>Find or Create the EFI System Partition</title>
+
+    <para>
+      On EFI based system, the bootloaders are installed in a special FAT32
+      partition called <emphasis>EFI System Partition</emphasis> (ESP).
+      If your system supports EFI, and a recent version of Linux
+      distribution or Windows is pre-installed, it's likely that the ESP
+      is already created.  As the
+      <systemitem class="username">root</systemitem> user, list all the
+      partitions on your hard drive (replace <userinput>sda</userinput>
+      with the device node corresponding to the hard drive):
+    </para>
+
+    <screen role="nodump"><userinput>fdisk -l /dev/sda</userinput></screen>
+
+    <para>
+      The <quote>Type</quote> column of the ESP should be
+      <literal>EFI System</literal>.
+    </para>
+
+    <para>
+      If the system or the hard drive is new, or it's the first time to
+      install an UEFI booted OS on the system, the ESP may be nonexistent.
+      Then create a new partition, make a
+      <systemitem class="filesystem">vfat</systemitem> file system on it,
+      and set the partition type to <quote>EFI system</quote>.  Read the
+      instructions for the emergency boot device above as a reference.
+    </para>
+
+    <warning>
+      <para>
+        Some (old) UEFI implementations may demand the ESP to be the first
+        partition on the disk.
+      </para>
+    </warning>
+
+    <para>
+      Now, as the <systemitem class="username">root</systemitem> user,
+      create the mount point for the ESP, and mount it (replace
+      <userinput>sda1</userinput> with the device node corresponding to
+      the ESP):
+    </para>
+
+<screen role="nodump"><userinput>mkdir -pv /boot/efi &amp;&amp;
+mount -v -t vfat /dev/sda1 /boot/efi</userinput></screen>
+
+    <para>
+      It's recommended to add an entry for the ESP in
+      <filename>/etc/fstab</filename>, so it will be mounted automatically
+      during system boot:
+    </para>
+
+<screen role="nodump"><userinput>cat &gt;&gt; /etc/fstab &lt;&lt; EOF</userinput>
+<literal>/dev/sda1 /boot/efi vfat defaults 0 1</literal>
+<userinput>EOF</userinput></screen>
+
+  </sect2>
+
+  <sect2>
+    <title>Mount the EFI Variable File System</title>
+
+    <para>
+      The installation of GRUB on UEFI platform requires the EFI Variable
+      file system (<systemitem class="filesystem">efivarfs</systemitem>)
+      mounted.  As the <systemitem class="username">root</systemitem> user:
+    </para>
+
+<screen role="nodump"><userinput>mount -v -t efivarfs efivarfs /sys/firmware/efi/efivars</userinput></screen>
+
+    <note revision="systemd">
+      <para>
+        If the system is booted with UEFI and systemd,
+        <systemitem class="filesystem">efivarfs</systemitem> will be mounted
+        automatically.  However in LFS chroot environment it still needs to
+        be mounted manually.
+      </para>
+    </note>
+
+    <para revision="sysv">
+      It's recommended to add an entry for the
+      <systemitem class="filesystem">efivarfs</systemitem> in
+      <filename>/etc/fstab</filename>, so it will be mounted automatically
+      during system boot:
+    </para>
+
+<screen revision="sysv" role="nodump"><userinput>cat &gt;&gt; /etc/fstab &lt;&lt; EOF</userinput>
+<literal>efivarfs /sys/firmware/efi/efivars efivarfs defaults 0 1</literal>
+<userinput>EOF</userinput></screen>
+
+    <warning>
+      <para>
+        If the system is not booted with UEFI, the directory
+        <filename class="directory">/sys/firmware/efi</filename> will be
+        missing. In this case you should boot the system in UEFI mode with
+        the emergency boot disk created as above.
+      </para>
+    </warning>
+  </sect2>
+
+  <sect2>
+    <title>Setting Up the Configuration</title>
+
+    <para>
+      On UEFI based systems, GRUB works by installing an EFI application
+      (a special kind of PE executable) into
+      <filename class="directory">/boot/efi/EFI/[id]/grubx64.efi</filename>,
+      where <filename class="directory">/boot/efi</filename> is the mount
+      point of the ESP, and <literal>[id]</literal> is replaced with an
+      identifier specified in the <command>grub-install</command> command
+      line.  Then GRUB will create an entry in the EFI variables containing
+      the path <literal>EFI/[id]/grubx64.efi</literal>, so the EFI firmware
+      can find <filename>grubx64.efi</filename> and load it.
+    </para>
+
+    <para>
+      <filename>grubx64.efi</filename> is very lightweight (136 KB with
+      GRUB-2.06~rc1) so it won't cost much space in the ESP.  A typical ESP
+      size is 100 MB (for Windows boot manager, which cost about 50 MB in
+      the ESP). Once <filename>grubx64.efi</filename> loaded by the
+      firmware, it will load GRUB modules in the boot partition.
+      The default location is
+      <filename class="directory">/boot/grub</filename>.
+    </para>
+
+    <para>
+      As the <systemitem class="username">root</systemitem> user, install
+      the GRUB files into <filename>/boot/efi/EFI/LFS/grubx64.efi</filename>
+      and <filename class="directory">/boot/grub</filename>, and set up the
+      boot entry in the EFI variables:
+    </para>
+
+<screen role="nodump"><userinput>grub-install --bootloader-id=LFS --recheck</userinput></screen>
+
+    <para>
+      If the installation is successful, the output should be:
+    </para>
+
+<screen role="nodump"><literal>Installing for x86_64-efi platform.
+Installation finished. No error reported.</literal></screen>
+
+    <para>
+      Issue <command>efibootmgr</command> to recheck the EFI boot
+      configuration.  An example of the output is:
+    </para>
+
+<screen role="nodump"><literal>BootCurrent: 0000
+Timeout: 1 seconds
+BootOrder: 0005,0000,0002,0001,0003,0004
+Boot0000* ARCH
+Boot0001* UEFI:CD/DVD Drive
+Boot0002* Windows Boot Manager
+Boot0003* UEFI:Removable Device
+Boot0004* UEFI:Network Device
+Boot0005* LFS</literal></screen>
+
+    <para>
+      Note that <literal>0005</literal> is the first in
+      <literal>BootOrder</literal>, and <literal>Boot0005</literal>
+      is <literal>LFS</literal>.  So on the next boot, GRUB installed
+      by LFS will be used to boot the system.
+    </para>
+
+  </sect2>
+
+  <sect2>
+    <title>Creating the GRUB Configuration File</title>
+
+    <indexterm zone="grub-setup grub-video">
+      <primary sortas="e-boot-grub-grub-cfg">/boot/grub/grub.cfg</primary>
+    </indexterm>
+
+    <para>
+      Generate <filename>/boot/grub/grub.cfg</filename> to configure the
+      boot menu of GRUB:
+    </para>
+
+<screen role="nodump"><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; EOF</userinput>
+<literal># Begin /boot/grub/grub.cfg
+set default=0
+set timeout=5
+
+insmod part_gpt
+insmod ext2
+set root=(hd0,2)
+
+if loadfont /boot/grub/fonts/unicode.pf2; then
+  set gfxmode=auto
+  insmod all_video
+  terminal_output gfxterm
+fi
+
+menuentry "GNU/Linux, Linux 5.10.17-lfs-10.1"  {
+  linux   /boot/vmlinuz-5.10.17-lfs-10.1 root=/dev/sda2 ro
+}
+
+menuentry "Firmware Setup" {
+  fwsetup
+}</literal>
+<userinput>EOF</userinput></screen>
+
+    <para>
+      <literal>(hd0,2)</literal>, <literal>sda2</literal>, and
+      <literal>5.10.17-lfs-10.1</literal> should be replaced to match your
+      configuration.
+    </para>
+
+    <note>
+      <para>
+        From GRUB's perspective, the files are relative to the partition
+        used. If you used a separate /boot partition, remove /boot from the
+        above paths (to kernel and to <filename>unicode.pf2</filename>). You
+        will also need to change the set root line to point to the boot
+        partition.
+      </para>
+    </note>
+
+    <para>
+      The <literal>Firmware Setup</literal> entry can be used to enter the
+      configuration interface provided by the firmware (sometimes called
+      "BIOS configuration").
+    </para>
+  </sect2>
+
+  <sect2>
+    <title>Dual-booting with Windows</title>
+
+    <para>
+      Add a menu entry for Windows into <filename>grub.cfg</filename>:
+    </para>
+
+<screen role="nodump"><userinput>cat &gt;&gt; /boot/grub/grub.cfg &lt;&lt; EOF</userinput>
+<literal># Begin Windows addition
+
+menuentry "Windows 10" {
+  insmod fat
+  insmod chain
+  set root=(hd0,1)
+  chainloader /EFI/Microsoft/Boot/bootmgfw.efi
+}</literal>
+<userinput>EOF</userinput></screen>
+
+    <para>
+      <literal>(hd0,1)</literal> should be replaced with the GRUB
+      designated name for the ESP.  <literal>chainloader</literal>
+      directive can be used to tell GRUB to run another EFI executable,
+      in this case the Windows Boot Manager. You may put more usable tools
+      in EFI executable format (for example, an EFI shell) into the ESP and 
+      create GRUB entries for them.
+    </para>
+
+  </sect2>
+
+</sect1>
