<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Just another blog (Posts about secureboot)</title><link>https://www.setphaserstostun.org/</link><description></description><atom:link href="https://www.setphaserstostun.org/categories/secureboot.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2025 &lt;a href="mailto:gabriele.svelto@gmail.com"&gt;Gabriele Svelto&lt;/a&gt; </copyright><lastBuildDate>Thu, 25 Sep 2025 08:27:20 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Secure Boot on Gentoo with shim &amp; GRUB</title><link>https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/</link><dc:creator>Gabriele Svelto</dc:creator><description>&lt;p&gt;Getting Secure Boot to work on Gentoo has traditionally been tricky, due to the
widespread use of custom kernels and the absence of pre-signed boot loaders
like those used by the mainstream binary Linux distributions. Since the
required information is spread through the handbook and the wiki I decided to
write one easy-to-follow tutorial instead, in order to make this information a
bit more accessible.&lt;/p&gt;
&lt;p&gt;There are several ways to make Secure Boot work, the goal being that every
executable loaded by the system during boot is signed and can be verified by
the one loading it. The method I've chosen uses the &lt;a class="reference external" href="https://github.com/rhboot/shim/"&gt;shim bootloader&lt;/a&gt; to
launch a standalone installation of &lt;a class="reference external" href="https://www.gnu.org/software/grub/"&gt;GRUB&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The way the boot chain will work is the following:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;Your machine's UEFI firmware will load the &lt;strong&gt;shim&lt;/strong&gt; bootloader, verifying its
signature using the pre-loaded Microsoft-provided key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;shim&lt;/strong&gt; bootloader will load a GRUB standalone executable which contains
everything needed by GRUB to run: its modules, configuration file, fonts and
themes. This executable will be signed with a key we'll generate and load
into the Machine Key Owner list, a user-managed list of keys. The &lt;strong&gt;shim&lt;/strong&gt;
bootloader will also set GRUB's &lt;strong&gt;shim_lock&lt;/strong&gt; option which will inform GRUB
to verify all the files it loads.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The GRUB standalone executable will thus launch a signed Linux kernel. This
will either be a Gentoo binary distribution kernel - in which case we'll also
load Gentoo binary distribution key in the MOK to verify it - or a custom
kernel which will be signed with the same key we'll have used to sign GRUB.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Linux kernel will optionally enforce that the modules it loads are also
signed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In a dual-boot system GRUB will also be able to chain-load the Microsoft
Windows bootloader or other signed UEFI executables, never breaking the
Secure Boot chain.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note that you can follow this procedure in place of following the &lt;strong&gt;Configuring
the bootloader&lt;/strong&gt; chapter of the Gentoo handbook, or do it on an already
existing installation. You don't need to turn off Secure Boot for the procedure
to work. In fact, if you're installing Gentoo using a live distribution that
supports Secure Boot, you can do the entire installation without ever turning
it off.&lt;/p&gt;
&lt;nav class="contents" id="contents" role="doc-toc"&gt;
&lt;p class="topic-title"&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#top"&gt;Contents&lt;/a&gt;&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#preparing-the-system" id="toc-entry-1"&gt;Preparing the system&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#setting-up-the-signing-keys" id="toc-entry-2"&gt;Setting up the signing keys&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#configuring-and-installing-the-required-packages" id="toc-entry-3"&gt;Configuring and installing the required packages&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#installing-the-kernel" id="toc-entry-4"&gt;Installing the kernel&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#gentoo-binary-distribution-kernel" id="toc-entry-5"&gt;Gentoo binary distribution kernel&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#gentoo-kernel-built-from-sources" id="toc-entry-6"&gt;Gentoo kernel built from sources&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#custom-kernel" id="toc-entry-7"&gt;Custom kernel&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#installing-the-shim-and-grub-bootloaders" id="toc-entry-8"&gt;Installing the shim and GRUB bootloaders&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#importing-the-key-in-the-mok-list" id="toc-entry-9"&gt;Importing the key in the MOK list&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#creating-a-new-efi-boot-entry" id="toc-entry-10"&gt;Creating a new EFI boot entry&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#reboot-enrolling-the-key-in-the-mok-list" id="toc-entry-11"&gt;Reboot &amp;amp; enrolling the key in the MOK list&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#conclusion" id="toc-entry-12"&gt;Conclusion&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#updating-and-troubleshooting" id="toc-entry-13"&gt;Updating and troubleshooting&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#kernel-updates" id="toc-entry-14"&gt;Kernel updates&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#removing-old-kernels" id="toc-entry-15"&gt;Removing old kernels&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#grub-updates" id="toc-entry-16"&gt;GRUB updates&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#shim-bootloader-updates-troubleshooting" id="toc-entry-17"&gt;shim bootloader updates &amp;amp; troubleshooting&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#motherboard-uefi-firmware-updates-troubleshooting" id="toc-entry-18"&gt;motherboard UEFI firmware updates &amp;amp; troubleshooting&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#bitlocker-recovery" id="toc-entry-19"&gt;BitLocker recovery&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/nav&gt;
&lt;section id="preparing-the-system"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-1" role="doc-backlink"&gt;Preparing the system&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;First of all we need to mount the EFI boot partition. This is a FAT-formatted
partition that you'll have made during the partitioning step of a Gentoo
installation, or was already present if you're installing Gentoo alongside
Windows or another Linux distribution using UEFI boot. This guide assumes that
this partition will be mounted under the &lt;code class="docutils literal"&gt;/boot/efi&lt;/code&gt; mount-point, so you'll
have something like this in &lt;code class="docutils literal"&gt;/etc/fstab&lt;/code&gt;:&lt;/p&gt;
&lt;pre class="literal-block"&gt;/dev/sda1       /boot/efi       vfat            defaults            0 0&lt;/pre&gt;
&lt;p&gt;Go on and mount the partition if it hasn't been mounted already:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# mount /boot/efi&lt;/pre&gt;
&lt;/section&gt;
&lt;section id="setting-up-the-signing-keys"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-2" role="doc-backlink"&gt;Setting up the signing keys&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;It's now time to generate the keys that we'll use to sign GRUB. We'll generate
an RSA-2048 certificate in &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail"&gt;PEM&lt;/a&gt; format which will be used to sign GRUB
(as well as the kernel and its modules if you're building it from source):&lt;/p&gt;
&lt;pre class="literal-block"&gt;# openssl req -new -nodes -utf8 -sha256 -x509 -outform PEM \
    -out /root/secureboot/MOK.pem -keyout /root/secureboot/MOK.pem \
    -subj "/CN=&amp;lt;your name here&amp;gt;/"&lt;/pre&gt;
&lt;p&gt;Note that it is good practice to keep this certificate offline, but for
simplicity this guide assumes that it is under &lt;code class="docutils literal"&gt;/root/secureboot/&lt;/code&gt;. You can
always move it to a removable drive later.&lt;/p&gt;
&lt;p&gt;Now we also need the certificate in binary &lt;a class="reference external" href="https://en.wikipedia.org/wiki/X.690#DER_encoding"&gt;DER&lt;/a&gt; format. This version of the
certificate will be loaded into the MOK list.&lt;/p&gt;
&lt;pre class="literal-block"&gt;# openssl x509 -in /root/secureboot/MOK.pem -outform DER -out /root/secureboot/MOK.cer&lt;/pre&gt;
&lt;p&gt;Now modify your &lt;code class="docutils literal"&gt;make.conf&lt;/code&gt; so that the &lt;code class="docutils literal"&gt;secureboot&lt;/code&gt; USE flag is enabled
and the &lt;cite&gt;SECUREBOOT_SIGN_KEY&lt;/cite&gt;, &lt;cite&gt;SECUREBOOT_SIGN_CERT&lt;/cite&gt;, &lt;cite&gt;MODULES_SIGN_KEY&lt;/cite&gt;
and &lt;cite&gt;MODULES_SIGN_CERT&lt;/cite&gt; variables point to the certificate in the PEM format.&lt;/p&gt;
&lt;pre class="literal-block"&gt;# USE flags
USE=".. secureboot .."

# Secure Boot signing keys
SECUREBOOT_SIGN_KEY="/root/secureboot/MOK.pem"
SECUREBOOT_SIGN_CERT="/root/secureboot/MOK.pem"
MODULES_SIGN_KEY="/root/secureboot/MOK.pem"
MODULES_SIGN_CERT="/root/secureboot/MOK.pem"&lt;/pre&gt;
&lt;/section&gt;
&lt;section id="configuring-and-installing-the-required-packages"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-3" role="doc-backlink"&gt;Configuring and installing the required packages&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Now let's install the packages we'll use: we need the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-boot/efibootmgr&lt;/span&gt;&lt;/code&gt;
package to add new boot entries, the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-boot/mokutil&lt;/span&gt;&lt;/code&gt; package to load our
keys into the &lt;cite&gt;Machine Owner Key list&lt;/cite&gt; and the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-boot/shim&lt;/span&gt;&lt;/code&gt; package that
contains the signed &lt;strong&gt;shim&lt;/strong&gt; bootloader. The &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-boot/mokutil&lt;/span&gt;&lt;/code&gt; package is
currently marked as unstable so we'll unmask it first.&lt;/p&gt;
&lt;pre class="literal-block"&gt;# echo "sys-boot/mokutil ~amd64" &amp;gt;&amp;gt; /etc/portage/package.accept_keywords
# echo emerge --ask sys-boot/efibootmgr sys-boot/mokutil sys-boot/shim&lt;/pre&gt;
&lt;p&gt;I also recommend rebuilding the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-apps/kmod&lt;/span&gt;&lt;/code&gt; package with the &lt;code class="docutils literal"&gt;pkcs7&lt;/code&gt;
USE flag, so that the &lt;strong&gt;modinfo&lt;/strong&gt; command will show you the signatures in
the kernel modules.&lt;/p&gt;
&lt;pre class="literal-block"&gt;# echo "sys-apps/kmod pkcs7" &amp;gt;&amp;gt; /etc/portage/package.use
# emerge --ask --newuse --oneshot sys-apps/kmod&lt;/pre&gt;
&lt;/section&gt;
&lt;section id="installing-the-kernel"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-4" role="doc-backlink"&gt;Installing the kernel&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Now that the keys have been set up it's time to make sure that the kernel image
is signed so that it can be verified by GRUB when loading it. The procedure is
different depending on the type of kernel you're using.&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;If you're using Gentoo's binary distribution kernel (via the
&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/gentoo-kernel-bin&lt;/span&gt;&lt;/code&gt; package) refer to the
&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#gentoo-binary-distribution-kernel"&gt;Gentoo binary distribution kernel&lt;/a&gt; instructions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you're using a custom kernel built using the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/gentoo-kernel&lt;/span&gt;&lt;/code&gt;
package use the &lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#gentoo-kernel-built-from-sources"&gt;Gentoo kernel built from sources&lt;/a&gt; instructions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally if you're using a custom kernel built by hand
(&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/gentoo-sources&lt;/span&gt;&lt;/code&gt;, &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/vanilla-sources&lt;/span&gt;&lt;/code&gt; or anything
else that's completely built from source) use the &lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#custom-kernel"&gt;Custom kernel&lt;/a&gt;
instructions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;section id="gentoo-binary-distribution-kernel"&gt;
&lt;h3&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-5" role="doc-backlink"&gt;Gentoo binary distribution kernel&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Gentoo binary distribution kernels are already signed with Gentoo's binary
distribution key. The public key, which we'll need to verify the signature,
is installed alongside the kernel. So proceed to install it as usual:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# emerge --ask sys-kernel/gentoo-kernel-bin&lt;/pre&gt;
&lt;p&gt;Now we need to import the key in the MOK list. The key is stored under
&lt;code class="docutils literal"&gt;certs/signing_key.x509&lt;/code&gt; in the kernel sources installation directory. To
load it into the MOK list use the following command:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# mokutil --import /usr/src/linux-&amp;lt;version&amp;gt;-gentoo-dist/certs/signing_key.x509&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;mokutil&lt;/strong&gt; will ask for a password to enroll the key. This will be used only
once after you have rebooted the system during the enrollment process, it can
be discarded afterwards.&lt;/p&gt;
&lt;p&gt;If &lt;strong&gt;mokutil&lt;/strong&gt; complains about the key already being in the keyring you can
force it to be loaded like this (this might happen if a firmware update wiped
the MOK list and you need to re-enroll the key).&lt;/p&gt;
&lt;pre class="literal-block"&gt;# mokutil --ignore-keyring --import /usr/src/linux-&amp;lt;version&amp;gt;-gentoo-dist/certs/signing_key.x509&lt;/pre&gt;
&lt;p&gt;That's it, you can now move on to the
&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#installing-the-shim-and-grub-bootloaders"&gt;Installing the shim and GRUB bootloaders&lt;/a&gt; section.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="gentoo-kernel-built-from-sources"&gt;
&lt;h3&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-6" role="doc-backlink"&gt;Gentoo kernel built from sources&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;When building the kernel using the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/gentoo-kernel&lt;/span&gt;&lt;/code&gt; package the
kernel will be automatically signed with the keys that we've set up in the
&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#setting-up-the-signing-keys"&gt;Setting up the signing keys&lt;/a&gt; section. To sign the loadable modules too set
the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;modules-sign&lt;/span&gt;&lt;/code&gt; USE flag in &lt;code class="docutils literal"&gt;make.conf&lt;/code&gt;:&lt;/p&gt;
&lt;pre class="literal-block"&gt;USE=".. modules-sign .."&lt;/pre&gt;
&lt;p&gt;This will instruct the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/gentoo-kernel&lt;/span&gt;&lt;/code&gt; package to also sign all the
modules using the aformentioned keys. Additionally, all packages that build
third-party modules will automatically sign them.&lt;/p&gt;
&lt;p&gt;Now install the kernel as usual:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# emerge --ask sys-kernel/gentoo-kernel&lt;/pre&gt;
&lt;p&gt;That's it, you can now move on to the
&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#installing-the-shim-and-grub-bootloaders"&gt;Installing the shim and GRUB bootloaders&lt;/a&gt; section.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="custom-kernel"&gt;
&lt;h3&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-7" role="doc-backlink"&gt;Custom kernel&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;When building your own kernel you'll need to specify the module signing key in
your .config file and force signature checks on all loaded modules:&lt;/p&gt;
&lt;pre class="literal-block"&gt;CONFIG_MODULE_SIG_FORCE=y
CONFIG_MODULE_SIG_KEY="/root/secureboot/MOK.pem"&lt;/pre&gt;
&lt;p&gt;Now build and install the kernel as usual&lt;/p&gt;
&lt;pre class="literal-block"&gt;# make
# make install
# make modules_install&lt;/pre&gt;
&lt;p&gt;The modules will be signed automatically but the kernel image needs to be
signed manually:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# sbsign --key /root/secureboot/MOK.key --cert /root/secureboot/MOK.crt /boot/vmlinuz-&amp;lt;version&amp;gt;&lt;/pre&gt;
&lt;p&gt;That's it, you can now move on to the
&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#installing-the-shim-and-grub-bootloaders"&gt;Installing the shim and GRUB bootloaders&lt;/a&gt; section.&lt;/p&gt;
&lt;/section&gt;
&lt;/section&gt;
&lt;section id="installing-the-shim-and-grub-bootloaders"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-8" role="doc-backlink"&gt;Installing the shim and GRUB bootloaders&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Now let's add a folder for our bootloader to the EFI partition and move the
&lt;strong&gt;shim&lt;/strong&gt; bootloader inside of it.&lt;/p&gt;
&lt;pre class="literal-block"&gt;# mkdir --parents /boot/efi/EFI/gentoo
# cp /usr/share/shim/mmx64.efi /boot/efi/EFI/gentoo/
# cp /usr/share/shim/BOOTX64.EFI /boot/efi/EFI/gentoo/&lt;/pre&gt;
&lt;p&gt;Notice how the &lt;strong&gt;shim&lt;/strong&gt; bootloader is made up of two executables: the actual
bootloader &lt;code class="docutils literal"&gt;BOOTX64.EFI&lt;/code&gt; and a tool to manipulate the MOK list
(&lt;code class="docutils literal"&gt;mmx64.efi&lt;/code&gt;). The latter will be used during the first reboot to enroll our
keys.&lt;/p&gt;
&lt;p&gt;The next step is to install GRUB. Make sure that you've got UEFI support
enabled by setting the &lt;cite&gt;GRUB_PLATFORMS&lt;/cite&gt; variable in &lt;code class="docutils literal"&gt;make.conf&lt;/code&gt;:&lt;/p&gt;
&lt;pre class="literal-block"&gt;GRUB_PLATFORMS="efi-64"&lt;/pre&gt;
&lt;p&gt;If you want to dual-boot Windows - or other Linux distributions - enable the
&lt;cite&gt;mount&lt;/cite&gt; USE flag so that GRUB's OS prober will be able to find them.&lt;/p&gt;
&lt;pre class="literal-block"&gt;# echo "sys-boot/grub mount" &amp;gt;&amp;gt; /etc/portage/package.use&lt;/pre&gt;
&lt;p&gt;Now install the GRUB package:&lt;/p&gt;
&lt;pre class="literal-block"&gt;emerge --ask sys-boot/grub&lt;/pre&gt;
&lt;p&gt;Now adjust the &lt;code class="docutils literal"&gt;/etc/default/grub&lt;/code&gt; configuration file with the options suitable
for your machine. In case you want to dual-boot Windows you'll need to
explicitly set the &lt;cite&gt;GRUB_DISABLE_OS_PROBER&lt;/cite&gt; option:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# Enable OS prober
GRUB_DISABLE_OS_PROBER=false&lt;/pre&gt;
&lt;p&gt;We can now generate GRUB's configuration and the unsigned standalone bootloader
executable. It's worth spending a few words on why we'll opt for a standalone
bootloader instead of GRUB's traditional installation (done using the
&lt;strong&gt;grub-install&lt;/strong&gt; tool).&lt;/p&gt;
&lt;p&gt;By default GRUB's configuration will use the &lt;strong&gt;shim_lock&lt;/strong&gt; verifier. This is a
mechanism that causes the &lt;strong&gt;shim&lt;/strong&gt; bootloader to inform GRUB that it's being
loaded in a Secure Boot environment and thus it's now GRUB's turn to validate
the boot chain. When this happens GRUB will verify all the executable files it
loads - including its modules. A traditional GRUB installation will store all
these files separately and require a separate GPG signature for &lt;em&gt;each of them&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Adding and maintaining these signatures is an unwieldy and error-prone
excercise and requires a separate GPG key in addition to the ones we've already
generated. A standalone installation on the other hand produces a single
executable which contains a memdisk holding all the modules, fonts, themes as
well as the configuration. This executable needs to be signed only once,
greatly reducing the maintainance burden.&lt;/p&gt;
&lt;p&gt;With that said let's proceed. We'll first generate GRUB's configuration using
&lt;strong&gt;grub-mkconfig&lt;/strong&gt; then use &lt;strong&gt;grub-mkstandalone&lt;/strong&gt; to produce the actual
bootloader:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# grub-mkconfig -o /boot/grub/grub.cfg
# grub-mkstandalone --output /boot/efi/EFI/gentoo/grubx64.efi \
    --directory /usr/lib/grub/x86_64-efi --sbat /usr/share/grub/sbat.csv \
    --format x86_64-efi "/boot/grub/grub.cfg=/boot/grub/grub.cfg"&lt;/pre&gt;
&lt;p&gt;It's worth breaking down the options we're passing to &lt;strong&gt;grub-mkstandalone&lt;/strong&gt; to
explain what's going on here:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;--output&lt;/span&gt;&lt;/code&gt; specifies the path of the bootloader executable we'll be
generating&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;--directory&lt;/span&gt;&lt;/code&gt; indicates where GRUB will find the modules that will be
included in the bootloader executable, &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;/usr/lib/grub/x86_64-efi&lt;/span&gt;&lt;/code&gt; is the
default location for these modules on Gentoo&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;--sbat&lt;/span&gt; /usr/share/grub/sbat.csv&lt;/code&gt; specifies the
&lt;cite&gt;Secure Boot Advanced Targeting&lt;/cite&gt; metadata to use. This is a list of EFI
progams and their minimum versions which are allowed to run. It's used to
prevent outdated EFI progams - such as buggy/compromised bootloaders - from
being used. Since we don't need to add anything there we use the default
version that comes with Gentoo's GRUB installation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;--format&lt;/span&gt; &lt;span class="pre"&gt;x86_64-efi&lt;/span&gt;&lt;/code&gt; specifies the bootloader executable format, that is
64-bit EFI.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;"/boot/grub/grub.cfg=/boot/grub/grub.cfg"&lt;/span&gt;&lt;/code&gt; will make &lt;strong&gt;grub-mkstandalone&lt;/strong&gt;
use the &lt;code class="docutils literal"&gt;grub.cfg&lt;/code&gt; file we've generated to populate the
&lt;code class="docutils literal"&gt;/boot/grub/grub.cfg&lt;/code&gt; file contained in the bundled memdisk. The memdisk is
a small tarball or SquashFS image that GRUB will use to store all the files
that go into a regular installation. By default GRUB uses the &lt;code class="docutils literal"&gt;/boot/grub&lt;/code&gt;
prefix when installing these files, which is why it expects &lt;code class="docutils literal"&gt;grub.cfg&lt;/code&gt; to
be there.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;At this point we've got ourselves an unsigned bootloader with everything we
need to boot our system, time to sign it:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# sbsign --cert /root/secureboot/MOK.pem --key /root/secureboot/MOK.pem \
    --output /boot/efi/EFI/gentoo/grubx64.efi /boot/efi/EFI/gentoo/grubx64.efi&lt;/pre&gt;
&lt;p&gt;Note that we've placed the signed GRUB bootloader next to the shim bootloader.
It needs to be called &lt;strong&gt;grubx64.efi&lt;/strong&gt; because that's what the &lt;strong&gt;shim&lt;/strong&gt;
bootloader expects to find.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="importing-the-key-in-the-mok-list"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-9" role="doc-backlink"&gt;Importing the key in the MOK list&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;It's now time to import the key we've used to sign GRUB (and possibly the
kernel too) into the MOK list. This is a two step process, the first part is
to import the key:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# mokutil --import /root/secureboot/MOK.cer&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;mokutil&lt;/strong&gt; will ask for a password to enroll the key. This will be used only
once after you have rebooted the system during the enrollment process, it can
be discarded afterwards.&lt;/p&gt;
&lt;p&gt;If &lt;strong&gt;mokutil&lt;/strong&gt; complains about the key already being in the keyring you can
force it to be loaded like this (this might happen if a firmware update wiped
the MOK list and you need to re-enroll the key).&lt;/p&gt;
&lt;pre class="literal-block"&gt;# mokutil --ignore-keyring --import /root/secureboot/MOK.cer&lt;/pre&gt;
&lt;p&gt;The second part will happen upon the next reboot. Remember the &lt;code class="docutils literal"&gt;mmx64.efi&lt;/code&gt;
file we've put in the EFI parition alongside the &lt;strong&gt;shim&lt;/strong&gt; bootloader? Upon
being loaded, &lt;strong&gt;shim&lt;/strong&gt; will notice that we're trying to import a key in the MOK
and launch it to do the actual enrollment.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="creating-a-new-efi-boot-entry"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-10" role="doc-backlink"&gt;Creating a new EFI boot entry&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The last step is to create a new EFI boot entry for the &lt;strong&gt;shim&lt;/strong&gt; bootloader.
Note that we don't need an entry for GRUB, because it will be loaded via SHIM.&lt;/p&gt;
&lt;p&gt;The boot entry can be created with this command:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# efibootmgr --disk &amp;lt;disk_with_efi_partition&amp;gt; --part &amp;lt;partition_number&amp;gt; --create -L "shim" -l '\EFI\gentoo\BOOTX64.EFI'&lt;/pre&gt;
&lt;p&gt;&lt;cite&gt;disk_with_efi_partition&lt;/cite&gt; is the disk which holds the EFI partition, and
&lt;cite&gt;partition_number&lt;/cite&gt; is the number of the EFI partition in the GPT table. So,
if your EFI partition is on the &lt;code class="docutils literal"&gt;/dev/sda1&lt;/code&gt; device you'll create the boot
entry with:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# efibootmgr --disk /dev/sda --part 1 --create -L "shim" -l '\EFI\gentoo\BOOTX64.EFI'&lt;/pre&gt;
&lt;p&gt;This command should also set the new boot entry as the default one,
double-check it with:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# efibootmgr
BootCurrent: 0003
Timeout: 0 seconds
BootOrder: 0003,0000,0017,0018,0019,001A,001B,001C,001D,001E,001F,0024,0002
...
Boot0003* shim  HD(1,GPT,e8389b70-d497-40e7-94a5-0b4a48732aa0,0x800,0x82000)/File(\EFI\gentoo\BOOTX64.EFI)
...&lt;/pre&gt;
&lt;p&gt;Notice how the &lt;cite&gt;BootOrder&lt;/cite&gt; variable starts with &lt;cite&gt;0003&lt;/cite&gt; which corresponds to the
&lt;cite&gt;shim&lt;/cite&gt; entry in this example. If this is not the case adjust the boot order
using:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# efibootmgr --bootorder &amp;lt;shim_entry&amp;gt;,&amp;lt;other_entry&amp;gt;,...&lt;/pre&gt;
&lt;/section&gt;
&lt;section id="reboot-enrolling-the-key-in-the-mok-list"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-11" role="doc-backlink"&gt;Reboot &amp;amp; enrolling the key in the MOK list&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;You can now reboot your machine. Upon the next reboot the &lt;strong&gt;shim&lt;/strong&gt; bootloader
will notice that you tried to enroll a new key and load the
&lt;cite&gt;Shim UEFI key management executable&lt;/cite&gt;. It will look like this (I apologize for
the horrible Moiré artifacts on the pictures):&lt;/p&gt;
&lt;img alt="/images/secure_boot_1.jpg" class="align-center" src="https://www.setphaserstostun.org/images/secure_boot_1.jpg"&gt;
&lt;p&gt;After pressing a key you'll be presented with the key management menu, choose
the &lt;cite&gt;Enroll MOK&lt;/cite&gt; entry:&lt;/p&gt;
&lt;img alt="/images/secure_boot_2.jpg" class="align-center" src="https://www.setphaserstostun.org/images/secure_boot_2.jpg"&gt;
&lt;p&gt;You will presented with the list of keys you enrolled. One if you only added
yours or two if you also added the Gentoo kernel distribution key. You can
view the keys to ensure they're what you expect:&lt;/p&gt;
&lt;img alt="/images/secure_boot_3.jpg" class="align-center" src="https://www.setphaserstostun.org/images/secure_boot_3.jpg"&gt;
&lt;p&gt;Here's the information about the selected key:&lt;/p&gt;
&lt;img alt="/images/secure_boot_4.jpg" class="align-center" src="https://www.setphaserstostun.org/images/secure_boot_4.jpg"&gt;
&lt;p&gt;Once you've verified you're enrolling the proper keys choose &lt;cite&gt;Continue&lt;/cite&gt;:&lt;/p&gt;
&lt;img alt="/images/secure_boot_5.jpg" class="align-center" src="https://www.setphaserstostun.org/images/secure_boot_5.jpg"&gt;
&lt;p&gt;You will be asked if you want to enroll the key(s), choose &lt;cite&gt;Yes&lt;/cite&gt;:&lt;/p&gt;
&lt;img alt="/images/secure_boot_6.jpg" class="align-center" src="https://www.setphaserstostun.org/images/secure_boot_6.jpg"&gt;
&lt;p&gt;You will now be asked for the password you used when you enrolled the key using
&lt;strong&gt;mokutil&lt;/strong&gt;. Input the password, you won't need it anymore once this is done:&lt;/p&gt;
&lt;img alt="/images/secure_boot_7.jpg" class="align-center" src="https://www.setphaserstostun.org/images/secure_boot_7.jpg"&gt;
&lt;p&gt;Once you've entered the password it's time to reboot:&lt;/p&gt;
&lt;img alt="/images/secure_boot_8.jpg" class="align-center" src="https://www.setphaserstostun.org/images/secure_boot_8.jpg"&gt;
&lt;/section&gt;
&lt;section id="conclusion"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-12" role="doc-backlink"&gt;Conclusion&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;You're done! Your machine should now reboot using the &lt;strong&gt;shim&lt;/strong&gt; bootloader which
will in turn load GRUB. If you had other operating systems such as Windows
these should appear in the menu, as well as other UEFI executables like
&lt;cite&gt;memtest86+&lt;/cite&gt; for example. Booting any of the entries should work and provide
a validated boot chain. Once you've booted back into Gentoo you can always
verify that this is the case by using &lt;strong&gt;mokutil&lt;/strong&gt; again:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# mokutil --sb-state
SecureBoot enabled&lt;/pre&gt;
&lt;/section&gt;
&lt;section id="updating-and-troubleshooting"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-13" role="doc-backlink"&gt;Updating and troubleshooting&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;You might wonder about how to deal updates to the packages we've used when
setting everything up. Here's how.&lt;/p&gt;
&lt;section id="kernel-updates"&gt;
&lt;h3&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-14" role="doc-backlink"&gt;Kernel updates&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;If you're using a custom kernel you'll have to execute some of the steps above
every time you install (or remove) a new kernel. In particular you'll have to
regenerate the &lt;code class="docutils literal"&gt;grub.cfg&lt;/code&gt; file, rebuild the &lt;strong&gt;GRUB&lt;/strong&gt; bootloader standalone
image and copy it over to your EFI partition.&lt;/p&gt;
&lt;p&gt;If you're using a distribution kernel there's a simpler way. You can instruct
the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/installkernel&lt;/span&gt;&lt;/code&gt; package to regenerate the GRUB signed UEFI
executable automatically every time a new kernel is installed by using a
plug-in script. Here's instructions for installing them depending on the init
system you're using. Be sure to adjust the &lt;cite&gt;GRUB_CFG&lt;/cite&gt;, &lt;cite&gt;EFI_PARTITION&lt;/cite&gt; and
&lt;cite&gt;GRUB_UEFI&lt;/cite&gt; environment variable if you're using different paths respectively
for your &lt;code class="docutils literal"&gt;grub.cfg&lt;/code&gt; file, EFI boot partition or the location of the GRUB EFI
executable.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;OpenRC&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Copy the following script into
&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;/etc/kernel/postinst.d/92-grub-mkstandalone-secureboot.install&lt;/span&gt;&lt;/code&gt; then make
it executable:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-1" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-1" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-1"&gt;&lt;/a&gt;&lt;span class="ch"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-2" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-2" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-2"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-3" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-3" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-3"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# Copyright 2024-2025 Gabriele Svelto&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-4" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-4" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-4"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-5" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-5" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-5"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# This script must be installed under /etc/kernel/postinst.d, it will&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-6" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-6" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-6"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# run after the 91-grub-mkconfig.install script and generate a signed&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-7" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-7" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-7"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# stand-alone GRUB image suitable for booting on UEFI systems with&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-8" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-8" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-8"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# Secure Boot enabled.&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-9" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-9" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-9"&gt;&lt;/a&gt;&lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-10" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-10" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-10"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# This script is meant to be executed by the traditional installkernel&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-11" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-11" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-11"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# tool and will run only when the systemd USE flag is disabled or&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-12" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-12" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-12"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# SYSTEMD_KERNEL_INSTALL=0 is set in the environment.&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-13" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-13" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-13"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-14" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-14" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-14"&gt;&lt;/a&gt;:&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_CFG&lt;/span&gt;&lt;span class="p"&gt;:=/boot/grub/grub.cfg&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-15" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-15" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-15"&gt;&lt;/a&gt;:&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;EFI_PARTITION&lt;/span&gt;&lt;span class="p"&gt;:=/boot/efi&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-16" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-16" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-16"&gt;&lt;/a&gt;:&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="p"&gt;:=/boot/efi/EFI/gentoo/grubx64.efi&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-17" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-17" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-17"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-18" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-18" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-18"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# familiar helpers, we intentionally don't use Gentoo functions.sh&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-19" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-19" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-19"&gt;&lt;/a&gt;die&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-20" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-20" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-20"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-e&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;" &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NOCOLOR&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="se"&gt;\e&lt;/span&gt;&lt;span class="p"&gt;[1;31m*&lt;/span&gt;&lt;span class="se"&gt;\e&lt;/span&gt;&lt;span class="p"&gt;[0m &lt;/span&gt;&lt;span class="si"&gt;}${&lt;/span&gt;&lt;span class="p"&gt;*&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-21" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-21" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-21"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-22" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-22" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-22"&gt;&lt;/a&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-23" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-23" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-23"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-24" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-24" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-24"&gt;&lt;/a&gt;einfo&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-25" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-25" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-25"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-e&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;" &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NOCOLOR&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="se"&gt;\e&lt;/span&gt;&lt;span class="p"&gt;[1;32m*&lt;/span&gt;&lt;span class="se"&gt;\e&lt;/span&gt;&lt;span class="p"&gt;[0m &lt;/span&gt;&lt;span class="si"&gt;}${&lt;/span&gt;&lt;span class="p"&gt;*&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-26" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-26" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-26"&gt;&lt;/a&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-27" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-27" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-27"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-28" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-28" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-28"&gt;&lt;/a&gt;ewarn&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-29" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-29" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-29"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-e&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;" &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NOCOLOR&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="se"&gt;\e&lt;/span&gt;&lt;span class="p"&gt;[1;33m*&lt;/span&gt;&lt;span class="se"&gt;\e&lt;/span&gt;&lt;span class="p"&gt;[0m &lt;/span&gt;&lt;span class="si"&gt;}${&lt;/span&gt;&lt;span class="p"&gt;*&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-30" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-30" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-30"&gt;&lt;/a&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-31" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-31" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-31"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-32" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-32" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-32"&gt;&lt;/a&gt;eerror&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-33" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-33" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-33"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-e&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;" &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NOCOLOR&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="se"&gt;\e&lt;/span&gt;&lt;span class="p"&gt;[1;31m*&lt;/span&gt;&lt;span class="se"&gt;\e&lt;/span&gt;&lt;span class="p"&gt;[0m &lt;/span&gt;&lt;span class="si"&gt;}${&lt;/span&gt;&lt;span class="p"&gt;*&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-34" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-34" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-34"&gt;&lt;/a&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-35" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-35" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-35"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-36" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-36" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-36"&gt;&lt;/a&gt;main&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-37" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-37" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-37"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# re-define for subst to work&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-38" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-38" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-38"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NOCOLOR&lt;/span&gt;&lt;span class="p"&gt;+yes&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;NOCOLOR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-39" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-39" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-39"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-40" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-40" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-40"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# do nothing if somehow GRUB is not installed&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-41" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-41" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-41"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-x&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-v&lt;span class="w"&gt; &lt;/span&gt;grub-mkstandalone&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;ewarn&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"grub-mkstandalone command not available"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-42" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-42" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-42"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-43" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-43" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-43"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;EUID&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-eq&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;die&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Please run this script as root"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-44" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-44" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-44"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-45" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-45" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-45"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# look for SECUREBOOT_SIGN_CERT and SECUREBOOT_SIGN_KEY values in make.conf&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-46" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-46" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-46"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;grep&lt;span class="w"&gt; &lt;/span&gt;-s&lt;span class="w"&gt; &lt;/span&gt;-h&lt;span class="w"&gt; &lt;/span&gt;SECUREBOOT_SIGN_CERT&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/etc/make.conf"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/etc/portage/make.conf"&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-47" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-47" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-47"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;grep&lt;span class="w"&gt; &lt;/span&gt;-s&lt;span class="w"&gt; &lt;/span&gt;-h&lt;span class="w"&gt; &lt;/span&gt;SECUREBOOT_SIGN_KEY&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/etc/make.conf"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/etc/portage/make.conf"&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-48" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-48" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-48"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-49" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-49" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-49"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# check that the Secure Boot signing certificate and key are present&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-50" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-50" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-50"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_CERT&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;die&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"SECUREBOOT_SIGN_CERT environment variable is not set"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-51" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-51" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-51"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-f&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_CERT&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;die&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Secure boot certificate file &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_CERT&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is not present"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-52" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-52" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-52"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_KEY&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;die&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"SECUREBOOT_SIGN_KEY environment variable is not set"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-53" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-53" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-53"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-f&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_KEY&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;die&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Secure boot certificate key &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_KEY&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is not present"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-54" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-54" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-54"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-55" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-55" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-55"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-f&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-56" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-56" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-56"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;einfo&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Backing up existing grub EFI binary as &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;~"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-57" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-57" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-57"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;cp&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;,~&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;die&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Failed to save existing EFI binary"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-58" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-58" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-58"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-59" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-59" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-59"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-60" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-60" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-60"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# Mount the EFI partition if it was specified&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-61" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-61" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-61"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;EFI_PARTITION&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;!&lt;span class="w"&gt; &lt;/span&gt;mountpoint&lt;span class="w"&gt; &lt;/span&gt;-q&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;EFI_PARTITION&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-62" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-62" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-62"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;ewarn&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"EFI partition &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;EFI_PARTITION&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; does not appear to be mounted"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-63" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-63" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-63"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-64" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-64" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-64"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-65" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-65" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-65"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;einfo&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Generating new GRUB EFI image as &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-66" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-66" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-66"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;dname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="p"&gt;%/*&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-67" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-67" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-67"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;mkdir&lt;span class="w"&gt; &lt;/span&gt;-vp&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;dname&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;die&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Failed to mkdir &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;dname&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-68" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-68" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-68"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# Exit non-fatally to ensure emerge does not fail completely in containers&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-69" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-69" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-69"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;grub-mkstandalone&lt;span class="w"&gt; &lt;/span&gt;-o&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-d&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/usr/lib/grub/x86_64-efi"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--sbat&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/usr/share/grub/sbat.csv"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--format&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"x86_64-efi"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/boot/grub/grub.cfg=&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_CFG&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;eerror&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"grub-mkstandalone failed"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-70" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-70" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-70"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;sbsign&lt;span class="w"&gt; &lt;/span&gt;--cert&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_CERT&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--key&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_KEY&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--output&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;eerror&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sbsign failed"&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-71" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-71" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-71"&gt;&lt;/a&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-72" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-72" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-72"&gt;&lt;/a&gt;
&lt;a id="rest_code_2c38fa4d6fb94032b937afd1e9992395-73" name="rest_code_2c38fa4d6fb94032b937afd1e9992395-73" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_2c38fa4d6fb94032b937afd1e9992395-73"&gt;&lt;/a&gt;main
&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;systemd&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Copy the following script into
&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;/etc/kernel/install.d/92-grub-mkstandalone-secureboot.install&lt;/span&gt;&lt;/code&gt; then make
it executable:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-1" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-1" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-1"&gt;&lt;/a&gt;&lt;span class="ch"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-2" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-2" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-2"&gt;&lt;/a&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-3" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-3" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-3"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# Copyright 2024-2025 Gabriele Svelto&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-4" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-4" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-4"&gt;&lt;/a&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-5" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-5" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-5"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# This script must be installed under /etc/kernel/install.d, it will&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-6" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-6" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-6"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# run after 91-grub-mkconfig.install and generate a signed stand-alone&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-7" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-7" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-7"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# GRUB image suitable for booting on UEFI systems with Secure Boot&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-8" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-8" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-8"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# enabled.&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-9" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-9" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-9"&gt;&lt;/a&gt;&lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-10" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-10" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-10"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# This script is executed by systemd's kernel-install, NOT by the&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-11" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-11" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-11"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# traditional installkernel. I.e. this plugin is run when the systemd&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-12" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-12" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-12"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# USE flag is enabled or SYSTEMD_KERNEL_INSTALL=1 is set in the&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-13" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-13" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-13"&gt;&lt;/a&gt;&lt;span class="c1"&gt;# environment.&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-14" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-14" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-14"&gt;&lt;/a&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-15" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-15" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-15"&gt;&lt;/a&gt;&lt;span class="nv"&gt;COMMAND&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-16" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-16" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-16"&gt;&lt;/a&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-17" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-17" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-17"&gt;&lt;/a&gt;:&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_CFG&lt;/span&gt;&lt;span class="p"&gt;:=/boot/grub/grub.cfg&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-18" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-18" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-18"&gt;&lt;/a&gt;:&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;EFI_PARTITION&lt;/span&gt;&lt;span class="p"&gt;:=/boot/efi&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-19" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-19" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-19"&gt;&lt;/a&gt;:&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="p"&gt;:=/boot/efi/EFI/gentoo/grubx64.efi&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-20" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-20" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-20"&gt;&lt;/a&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-21" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-21" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-21"&gt;&lt;/a&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;KERNEL_INSTALL_LAYOUT&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;!&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"grub"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-22" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-22" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-22"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-23" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-23" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-23"&gt;&lt;/a&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-24" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-24" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-24"&gt;&lt;/a&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-25" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-25" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-25"&gt;&lt;/a&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;COMMAND&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;add&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;COMMAND&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;remove&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-26" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-26" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-26"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# do nothing if somehow GRUB is not installed&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-27" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-27" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-27"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;!&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-v&lt;span class="w"&gt; &lt;/span&gt;grub-mkstandalone&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;/dev/null&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-28" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-28" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-28"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;KERNEL_INSTALL_VERBOSE&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-29" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-29" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-29"&gt;&lt;/a&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="s2"&gt;"grub-mkstandalone command not available"&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-30" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-30" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-30"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-31" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-31" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-31"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-32" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-32" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-32"&gt;&lt;/a&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-33" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-33" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-33"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# look for SECUREBOOT_SIGN_CERT and SECUREBOOT_SIGN_KEY values in make.conf&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-34" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-34" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-34"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;grep&lt;span class="w"&gt; &lt;/span&gt;-s&lt;span class="w"&gt; &lt;/span&gt;-h&lt;span class="w"&gt; &lt;/span&gt;SECUREBOOT_SIGN_CERT&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/etc/make.conf"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/etc/portage/make.conf"&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-35" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-35" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-35"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;grep&lt;span class="w"&gt; &lt;/span&gt;-s&lt;span class="w"&gt; &lt;/span&gt;-h&lt;span class="w"&gt; &lt;/span&gt;SECUREBOOT_SIGN_KEY&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/etc/make.conf"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/etc/portage/make.conf"&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-36" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-36" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-36"&gt;&lt;/a&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-37" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-37" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-37"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# check that the Secure Boot signing certificate and key are present&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-38" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-38" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-38"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_CERT&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"SECUREBOOT_SIGN_CERT environment variable is not set"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-39" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-39" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-39"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-f&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_CERT&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Secure boot certificate file &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_CERT&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is not present"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-40" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-40" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-40"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_KEY&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"SECUREBOOT_SIGN_KEY environment variable is not set"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-41" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-41" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-41"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-f&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_KEY&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Secure boot certificate key &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_KEY&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is not present"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-42" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-42" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-42"&gt;&lt;/a&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-43" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-43" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-43"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-f&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-44" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-44" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-44"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;KERNEL_INSTALL_VERBOSE&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-45" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-45" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-45"&gt;&lt;/a&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="s2"&gt;"Backing up existing grub EFI binary as &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;~"&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-46" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-46" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-46"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;cp&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;,~&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Failed to save existing EFI binary"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-47" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-47" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-47"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-48" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-48" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-48"&gt;&lt;/a&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-49" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-49" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-49"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;KERNEL_INSTALL_VERBOSE&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-50" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-50" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-50"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="s2"&gt;"Generating new GRUB EFI image as &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-51" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-51" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-51"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nv"&gt;dname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="p"&gt;%/*&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-52" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-52" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-52"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;mkdir&lt;span class="w"&gt; &lt;/span&gt;-p&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;dname&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Failed to mkdir &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;dname&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-53" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-53" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-53"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;grub-mkstandalone&lt;span class="w"&gt; &lt;/span&gt;-o&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-d&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/usr/lib/grub/x86_64-efi"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--sbat&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/usr/share/grub/sbat.csv"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--format&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"x86_64-efi"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/boot/grub/grub.cfg=&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_CFG&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"grub-mkstandalone failed"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-54" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-54" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-54"&gt;&lt;/a&gt;&lt;span class="w"&gt;  &lt;/span&gt;sbsign&lt;span class="w"&gt; &lt;/span&gt;--cert&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_CERT&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--key&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SECUREBOOT_SIGN_KEY&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--output&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GRUB_UEFI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sbsign failed"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;a id="rest_code_0073752a448d4239a3d6182d1d4d9c9a-55" name="rest_code_0073752a448d4239a3d6182d1d4d9c9a-55" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#rest_code_0073752a448d4239a3d6182d1d4d9c9a-55"&gt;&lt;/a&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id="removing-old-kernels"&gt;
&lt;h3&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-15" role="doc-backlink"&gt;Removing old kernels&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Removing old kernels can be done via the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;app-admin/eclean-kernel&lt;/span&gt;&lt;/code&gt; package.
It plays nice with the kernel installation scripts, so if you've added the
update scripts described in the paragraph above, it will regenerate the GRUB
configuration and signed EFI image every time you remove some kernels. For
example, let's say you have three kernels installed and install a new one.
After rebooting your machine running the following command will prune the
oldest kernel:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# eclean-kernel --num 3 --ask&lt;/pre&gt;
&lt;p&gt;Once the command is finished your GRUB EFI image will have the new
configuration files with only the most three recent kernels and will have
already been re-signed and installed.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="grub-updates"&gt;
&lt;h3&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-16" role="doc-backlink"&gt;GRUB updates&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;When the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-boot/grub&lt;/span&gt;&lt;/code&gt; package is updated you don't necessarily need to
update your installation, though it's recommended to do so. Re-create the
&lt;strong&gt;GRUB&lt;/strong&gt; configuration, standalone image and sign it again:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# grub-mkconfig -o /boot/grub/grub.cfg
# grub-mkstandalone --output /boot/efi/EFI/gentoo/grubx64.efi \
    --directory /usr/lib/grub/x86_64-efi --sbat /usr/share/grub/sbat.csv \
    --format x86_64-efi "/boot/grub/grub.cfg=/boot/grub/grub.cfg"
# sbsign --cert /root/secureboot/MOK.pem --key /root/secureboot/MOK.pem \
    --output /boot/efi/EFI/gentoo/grubx64.efi /boot/efi/EFI/gentoo/grubx64.efi&lt;/pre&gt;
&lt;/section&gt;
&lt;section id="shim-bootloader-updates-troubleshooting"&gt;
&lt;h3&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-17" role="doc-backlink"&gt;shim bootloader updates &amp;amp; troubleshooting&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;If the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-boot/shim&lt;/span&gt;&lt;/code&gt; package is updated it is highly recommended to also
update your installation. Failing to do so might lead to an unbootable system,
as older versions of the package are progressively marked as unsafe, and new
UEFI firmwares will refuse to boot them. To update the &lt;strong&gt;shim&lt;/strong&gt; bootloader
first update the package then manually copy the new version to the EFI
partition:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# cp /usr/share/shim/mmx64.efi /boot/efi/EFI/gentoo/
# cp /usr/share/shim/BOOTX64.EFI /boot/efi/EFI/gentoo/&lt;/pre&gt;
&lt;p&gt;In particular you'll have to update the &lt;strong&gt;shim&lt;/strong&gt; bootloader if you get a boot
failure with the following error message:&lt;/p&gt;
&lt;pre class="literal-block"&gt;Verifying shim SBAT data failed: security policy violation&lt;/pre&gt;
&lt;p&gt;You won't be able to boot with the existing bootloader and you'll have to
either temporarily disable Secure Boot or boot with another bootloader to fix
the issue. Updating &lt;strong&gt;shim&lt;/strong&gt; will solve the problem.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="motherboard-uefi-firmware-updates-troubleshooting"&gt;
&lt;h3&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-18" role="doc-backlink"&gt;motherboard UEFI firmware updates &amp;amp; troubleshooting&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Updating the motherboard UEFI firmware sometimes clears the MOK list. If that's
the case your system will fail to boot and you will have to enroll your key
again. Follow the steps in &lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#reboot-enrolling-the-key-in-the-mok-list"&gt;Reboot &amp;amp; enrolling the key in the MOK list&lt;/a&gt; to
enroll your key once more.&lt;/p&gt;
&lt;p&gt;Similarly sometimes the UEFI boot list will be cleared, removing the &lt;strong&gt;shim&lt;/strong&gt;
boot entry. If it happens repeat the steps in &lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#creating-a-new-efi-boot-entry"&gt;Creating a new EFI boot entry&lt;/a&gt;
to create a new one.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="bitlocker-recovery"&gt;
&lt;h3&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#toc-entry-19" role="doc-backlink"&gt;BitLocker recovery&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;If you have a dual-boot system with Windows and BitLocker enable then this
setup will probably trigger a BitLocker recovery procedure every time you
change either a kernel or GRUB configuration. Either change will cause your
GRUB EFI image to change, and it appears that Windows forces the recovery
procedure when that happens. Inserting the BitLocker recovery key is sufficent
to get the system back to normal but it can be a bit annoying.&lt;/p&gt;
&lt;/section&gt;
&lt;/section&gt;</description><category>gentoo</category><category>grub</category><category>linux</category><category>secureboot</category><category>shim</category><guid>https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/</guid><pubDate>Thu, 18 Jul 2024 15:38:23 GMT</pubDate></item></channel></rss>