<?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 linux)</title><link>https://www.setphaserstostun.org/</link><description></description><atom:link href="https://www.setphaserstostun.org/categories/linux.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><item><title>Gentoo 6.1.x generic kernel configuration</title><link>https://www.setphaserstostun.org/posts/gentoo-61x-generic-kernel-configuration/</link><dc:creator>Gabriele Svelto</dc:creator><description>&lt;p&gt;The 6.1.x branch of the Linux kernel has been marked as stable in &lt;a class="reference external" href="https://www.gentoo.org"&gt;Gentoo&lt;/a&gt; for a
few months already and I was busy enough that I forgot to publish an updated
generic kernel configuration for it. As with my previous posts this
configuration is largely based on the Fedora kernel with some Gentoo-specific
tweaks. It supports practically every bit of hardware in existence and enables
a lot of bleeding-edge kernel functionality.&lt;/p&gt;
&lt;p&gt;The only few notable changes compared to the Fedora kernel are the following:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;The &lt;code class="docutils literal"&gt;binfmt_misc&lt;/code&gt; module is baked in for convenience&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The NVMe core modules are baked in so you can boot from an NVMe drive without
having to use an initrd&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code class="docutils literal"&gt;CONFIG_ACPI_EXTLOG&lt;/code&gt; option is enabled. This is useful if you're using
&lt;a class="reference external" href="https://www.setphaserstostun.org/posts/monitoring-ecc-memory-on-linux-with-rasdaemon/"&gt;rasdaemon to monitor ECC memory&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The boot logo is disabled&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Kernel debugging is disabled&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code class="docutils literal"&gt;CONFIG_GENTOO_KERNEL_SELF_PROTECTION&lt;/code&gt; option is enabled. This
implicitly enables an additional set of security features for hardening the
kernel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code class="docutils literal"&gt;CONFIG_GENTOO_PRINT_FIRMWARE_INFO&lt;/code&gt; option is enabled, it prints out
the firmwares that are loaded into various bits of hardware. This is useful
if you want to reduce the amount of files installed
&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/linux-firmware&lt;/span&gt;&lt;/code&gt; package&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note that the &lt;strong&gt;RTC time based on NTP synchronization&lt;/strong&gt; is enabled so - if
you're using OpenRC - you don't need the &lt;strong&gt;hwclock&lt;/strong&gt; service (but you can use
&lt;strong&gt;osclock&lt;/strong&gt; instead if some other service requires the &lt;strong&gt;clock&lt;/strong&gt; facility).&lt;/p&gt;
&lt;p&gt;Additionally note that this kernel configuration is for use with OpenRC. If
you're using systemd you'll have to remove the
&lt;code class="docutils literal"&gt;CONFIG_GENTOO_LINUX_INIT_SCRIPT=y&lt;/code&gt; line from the configuration file and add
&lt;code class="docutils literal"&gt;CONFIG_GENTOO_LINUX_INIT_SYSTEMD=y&lt;/code&gt; instead.&lt;/p&gt;
&lt;p&gt;Now that zstd is well supported in many packages I have enabled it for
compressing kernel modules. The only thing you need to make sure to use it is
that the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-apps/kmod&lt;/span&gt;&lt;/code&gt; package has the &lt;strong&gt;zstd&lt;/strong&gt; &lt;code class="docutils literal"&gt;USE&lt;/code&gt; flag set so that it
can handle the compressed modules. If for some reason you don't want modules
to be compressed set &lt;cite&gt;CONFIG_MODULE_COMPRESS_ZSTD=n&lt;/cite&gt; and
&lt;cite&gt;CONFIG_MODULE_COMPRESS_NONE=y&lt;/cite&gt; respectively.&lt;/p&gt;
&lt;p&gt;To use this configuration file install the latest stable
&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/gentoo-sources&lt;/span&gt;&lt;/code&gt; package (6.1.x), copy the configuration file
under &lt;code class="docutils literal"&gt;/usr/src/linux/&lt;/code&gt; and rename it to &lt;code class="docutils literal"&gt;.config&lt;/code&gt; then proceed to build
and install the kernel as usual.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="https://www.setphaserstostun.org/config-6.1"&gt;Gentoo 6.1.x kernel configuration file&lt;/a&gt;&lt;/p&gt;</description><category>gentoo</category><category>kernel</category><category>linux</category><guid>https://www.setphaserstostun.org/posts/gentoo-61x-generic-kernel-configuration/</guid><pubDate>Sun, 26 Nov 2023 07:43:54 GMT</pubDate></item><item><title>Gentoo 5.15.x generic kernel configuration</title><link>https://www.setphaserstostun.org/posts/gentoo-515x-generic-kernel-configuration/</link><dc:creator>Gabriele Svelto</dc:creator><description>&lt;p&gt;The 5.15.11 Linux kernel has been marked as stable in &lt;a class="reference external" href="https://www.gentoo.org"&gt;Gentoo&lt;/a&gt; a few weeks ago
and I've wanted to put out a new generic kernel configuration but I kept
struggling with a really silly issue adapting it. As with my previous posts
this configuration is largely based on the Fedora kernel with some
Gentoo-specific tweaks. It supports practically every bit of hardware in
existence and enables a lot of bleeding-edge kernel functionality.&lt;/p&gt;
&lt;p&gt;The only few notable changes compared to the Fedora kernel are the following:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;The &lt;code class="docutils literal"&gt;binfmt_misc&lt;/code&gt; module is baked in for convenience&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The NVMe core modules are baked in so you can boot from an NVMe drive without
having to use an initrd&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code class="docutils literal"&gt;CONFIG_ACPI_EXTLOG&lt;/code&gt; option is enabled. This is useful if you're using
&lt;a class="reference external" href="https://www.setphaserstostun.org/posts/monitoring-ecc-memory-on-linux-with-rasdaemon/"&gt;rasdaemon to monitor ECC memory&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The boot logo is disabled&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Kernel debugging is disabled&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code class="docutils literal"&gt;CONFIG_GENTOO_KERNEL_SELF_PROTECTION&lt;/code&gt; option is enabled. This
implicitly enables an additional set of security features for hardening the
kernel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code class="docutils literal"&gt;CONFIG_GENTOO_PRINT_FIRMWARE_INFO&lt;/code&gt; option is enabled, it prints out
the firmwares that are loaded into various bits of hardware. This is useful
if you want to reduce the amount of files installed
&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/linux-firmware&lt;/span&gt;&lt;/code&gt; package&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note that the &lt;strong&gt;RTC time based on NTP synchronization&lt;/strong&gt; is enabled (and it's
finally become the default in many other Linux distros) so you don't need the
&lt;strong&gt;hwclock&lt;/strong&gt; service (but you can use &lt;strong&gt;osclock&lt;/strong&gt; instead if some other service
requires the &lt;strong&gt;clock&lt;/strong&gt; facility).&lt;/p&gt;
&lt;p&gt;Additionally note that this kernel configuration is for use with OpenRC. If
you're using systemd you'll have to remove the
&lt;code class="docutils literal"&gt;CONFIG_GENTOO_LINUX_INIT_SCRIPT=y&lt;/code&gt; line from the configuration file and add
&lt;code class="docutils literal"&gt;CONFIG_GENTOO_LINUX_INIT_SYSTEMD=y&lt;/code&gt; instead.&lt;/p&gt;
&lt;p&gt;For maximum compatibility I haven't enabled kernel compression in this
configuration, but I suggest using &lt;code class="docutils literal"&gt;CONFIG_MODULE_COMPRESS_ZSTD=y&lt;/code&gt; as it
provides significant space savings while having effectively no impact on load
times. Just make sure that the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-apps/kmod&lt;/span&gt;&lt;/code&gt; package has the &lt;strong&gt;zstd&lt;/strong&gt;
&lt;code class="docutils literal"&gt;USE&lt;/code&gt; flag set so that it can handle the compressed modules.&lt;/p&gt;
&lt;p&gt;To use this configuration file install the latest stable
&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/gentoo-sources&lt;/span&gt;&lt;/code&gt; package (5.15.x), copy the configuration file
under &lt;code class="docutils literal"&gt;/usr/src/linux/&lt;/code&gt; and rename it to &lt;code class="docutils literal"&gt;.config&lt;/code&gt; then proceed to build
and install the kernel as usual.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="https://www.setphaserstostun.org/config-5.15"&gt;Gentoo 5.15.x kernel configuration file&lt;/a&gt;&lt;/p&gt;</description><category>gentoo</category><category>kernel</category><category>linux</category><guid>https://www.setphaserstostun.org/posts/gentoo-515x-generic-kernel-configuration/</guid><pubDate>Tue, 11 Jan 2022 08:12:32 GMT</pubDate></item><item><title>Gentoo 5.10.x generic kernel configuration</title><link>https://www.setphaserstostun.org/posts/gentoo-510x-generic-kernel-configuration/</link><dc:creator>Gabriele Svelto</dc:creator><description>&lt;p&gt;The 5.10.27 Linux kernel has been marked as stable in &lt;a class="reference external" href="https://www.gentoo.org"&gt;Gentoo&lt;/a&gt; a few days ago and
I've just updated my generic kernel configuration file to support it. As with my
previous posts this configuration is based on the Fedora kernel with some
Gentoo-specific tweaks. It supports practically every bit of hardware in
existence and enables a lot of bleeding-edge kernel functionality.&lt;/p&gt;
&lt;p&gt;The only few notable changes compared to the Fedora kernel are the following:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;binfmt_misc&lt;/strong&gt; module is baked in for convenience&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The NVMe core modules are baked in so you can boot from an NVMe drive without
having to use an initrd&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;RTC time based on NTP synchronization&lt;/strong&gt; is enabled so you don't need the
&lt;strong&gt;hwclock&lt;/strong&gt; service (but you can use &lt;strong&gt;osclock&lt;/strong&gt; instead if some other service
requires the &lt;strong&gt;clock&lt;/strong&gt; facility)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;CONFIG_ACPI_EXTLOG&lt;/strong&gt; option is enabled. This is useful if you're using
&lt;a class="reference external" href="https://www.setphaserstostun.org/posts/monitoring-ecc-memory-on-linux-with-rasdaemon/"&gt;rasdaemon to monitor ECC memory&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The boot logo is disabled&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Kernel debugging is disabled&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note that this kernel configuration is for use with OpenRC. If you're using
systemd you'll have to remove the &lt;code class="docutils literal"&gt;CONFIG_GENTOO_LINUX_INIT_SCRIPT=y&lt;/code&gt; line
from the configuration file and add &lt;code class="docutils literal"&gt;CONFIG_GENTOO_LINUX_INIT_SYSTEMD=y&lt;/code&gt;
instead.&lt;/p&gt;
&lt;p&gt;To use it install the latest stable &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/gentoo-sources&lt;/span&gt;&lt;/code&gt; package
(5.10.x), copy the configuration file under &lt;code class="docutils literal"&gt;/usr/src/linux/&lt;/code&gt; and rename it
to &lt;code class="docutils literal"&gt;.config&lt;/code&gt; then proceed to build and install the kernel as usual.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="https://www.setphaserstostun.org/config-5.10"&gt;Gentoo 5.10.x kernel configuration file&lt;/a&gt;&lt;/p&gt;</description><category>gentoo</category><category>kernel</category><category>linux</category><guid>https://www.setphaserstostun.org/posts/gentoo-510x-generic-kernel-configuration/</guid><pubDate>Mon, 05 Apr 2021 13:21:12 GMT</pubDate></item><item><title>Monitoring ECC memory on Linux with rasdaemon</title><link>https://www.setphaserstostun.org/posts/monitoring-ecc-memory-on-linux-with-rasdaemon/</link><dc:creator>Gabriele Svelto</dc:creator><description>&lt;p&gt;If you have a workstation built around an AMD Ryzen/Threadripper or Intel Xeon
processor chances are you're using &lt;a class="reference external" href="https://en.wikipedia.org/wiki/ECC_memory"&gt;ECC memory&lt;/a&gt;. ECC memory is a worthy
investment to improve the reliability of your machine and if properly monitored
will allow you to spot memory problems before they become catastrophic.&lt;/p&gt;
&lt;p&gt;On recent Linux kernels the &lt;a class="reference external" href="https://github.com/mchehab/rasdaemon"&gt;rasdaemon&lt;/a&gt; tools can be used to monitor ECC memory
and report both correctable and uncorrectable memory errors. As we'll see with a
little bit of tweaking it's also possible to know exactly which DIMM is
experiencing the errors.&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/monitoring-ecc-memory-on-linux-with-rasdaemon/#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/monitoring-ecc-memory-on-linux-with-rasdaemon/#installing-rasdaemon" id="toc-entry-1"&gt;Installing rasdaemon&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/monitoring-ecc-memory-on-linux-with-rasdaemon/#configuring-rasdaemon" id="toc-entry-2"&gt;Configuring rasdaemon&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/monitoring-ecc-memory-on-linux-with-rasdaemon/#configuring-dimm-labels" id="toc-entry-3"&gt;Configuring DIMM labels&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/monitoring-ecc-memory-on-linux-with-rasdaemon/#troubleshooting" id="toc-entry-4"&gt;Troubleshooting&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/nav&gt;
&lt;section id="installing-rasdaemon"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/monitoring-ecc-memory-on-linux-with-rasdaemon/#toc-entry-1" role="doc-backlink"&gt;Installing rasdaemon&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;First of all you'll need to intall &lt;strong&gt;rasdeamon&lt;/strong&gt;, it's packaged for most Linux
distributions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Debian/Ubuntu&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="literal-block"&gt;# apt-get install rasdaemon&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fedora&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="literal-block"&gt;# dnf install rasdaemon&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;openSUSE&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="literal-block"&gt;# zypper install rasdaemon&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gentoo&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The package is currently marked as unstable so you'll need to unmask it first:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# echo "app-admin/rasdaemon ~amd64" &amp;gt;&amp;gt; /etc/portage/package.keywords&lt;/pre&gt;
&lt;p&gt;Then I recommend enabling sqlite support, this makes rasdaemon record events
to disk and is particularly useful for machines that get rebooted often:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# echo "app-admin/rasdaemon sqlite" &amp;gt;&amp;gt; /etc/portage/packages.use&lt;/pre&gt;
&lt;p&gt;Finally install rasdaemon itself:&lt;/p&gt;
&lt;pre class="literal-block"&gt;emerge rasdaemon&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id="configuring-rasdaemon"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/monitoring-ecc-memory-on-linux-with-rasdaemon/#toc-entry-2" role="doc-backlink"&gt;Configuring rasdaemon&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Then we'll setup &lt;strong&gt;rasdaemon&lt;/strong&gt; to launch at startup and to record events to
an on-disk sqlite database.&lt;/p&gt;
&lt;p&gt;Note that when booting with Secure Boot enabled, using the kernel lockdown
facility in &lt;strong&gt;confidentiality&lt;/strong&gt; mode will prevent rasdaemon from running. To
use &lt;strong&gt;rasdaemon&lt;/strong&gt; you'll have to use a different lockdown mode, disable
lockdown entirely or disable Secure Boot. You'll find more information in the
&lt;a class="reference internal" href="https://www.setphaserstostun.org/posts/monitoring-ecc-memory-on-linux-with-rasdaemon/#troubleshooting"&gt;Troubleshooting&lt;/a&gt; section.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Debian/Ubuntu/Fedora/openSUSE and other systemd-based distros&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="literal-block"&gt;# systemctl enable rasdaemon
# systemctl start rasdaemon&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gentoo with OpenRC&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add the following line to &lt;code class="docutils literal"&gt;/etc/conf.d/rasdaemon&lt;/code&gt;:&lt;/p&gt;
&lt;pre class="literal-block"&gt;RASDAEMON_ARGS=--record&lt;/pre&gt;
&lt;p&gt;Add &lt;code class="docutils literal"&gt;rasdaemon&lt;/code&gt; to the &lt;strong&gt;default&lt;/strong&gt; run-level and start it&lt;/p&gt;
&lt;pre class="literal-block"&gt;# rc-config add rasdaemon default
# rc-config start rasdaemon&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id="configuring-dimm-labels"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/monitoring-ecc-memory-on-linux-with-rasdaemon/#toc-entry-3" role="doc-backlink"&gt;Configuring DIMM labels&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;At this point &lt;strong&gt;rasdaemon&lt;/strong&gt; should already be running on your system. You can
now use the &lt;strong&gt;ras-mc-ctl&lt;/strong&gt; tool to query the errors that have been detected.
From now on I will use data from my machine to give an example of the output.&lt;/p&gt;
&lt;pre class="literal-block"&gt;# ras-mc-ctl --error-count
Label                 CE      UE
mc#0csrow#2channel#0  0   0
mc#0csrow#2channel#1  0   0
mc#0csrow#3channel#1  0   0
mc#0csrow#3channel#0  0   0&lt;/pre&gt;
&lt;p&gt;The CE column represents the number of corrected errors for a given DIMM, UE
represents uncorrectable errors that were detected. The label on the left
shows the EDAC path under &lt;code class="docutils literal"&gt;/sys/devices/system/edac/mc/&lt;/code&gt; of every DIMM.&lt;/p&gt;
&lt;p&gt;This is not very readable. Since the kernel has no idea of the physical layout
of your motherboard it will print the EDAC paths instead of the names of the
DIMM slots. We can confirm that the labels are missing with this command:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# ras-mc-ctl --print-labels
ras-mc-ctl: Error: No dimm labels for ASUSTeK COMPUTER INC. model PRIME B450-PLUS&lt;/pre&gt;
&lt;p&gt;To identify which DIMM slot corresponds to which EDAC path you will have to
reboot your system with only one DIMM inserted, write down the name of the
slot you insterted it in and then printing out the paths with
&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;ras-mc-ctl&lt;/span&gt; &lt;span class="pre"&gt;--error-count&lt;/span&gt;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In my case this was the mapping:&lt;/p&gt;
&lt;pre class="literal-block"&gt;mc#0csrow#0channel#0  DIMM_A1
mc#0csrow#0channel#1  DIMM_A2
mc#0csrow#1channel#1  DIMM_A2
mc#0csrow#1channel#0  DIMM_A1
mc#0csrow#2channel#0  DIMM_B1
mc#0csrow#2channel#1  DIMM_B2
mc#0csrow#3channel#1  DIMM_B2
mc#0csrow#3channel#0  DIMM_B1&lt;/pre&gt;
&lt;p&gt;Note that there's more than one path per DIMM label, that's fine.&lt;/p&gt;
&lt;p&gt;With this data at hand create a text file under &lt;code class="docutils literal"&gt;/etc/ras/dimm_labels.d/&lt;/code&gt;.
You will need to fill it up with the mapping data in the following format:&lt;/p&gt;
&lt;pre class="literal-block"&gt;Vendor: &amp;lt;motherboard vendor name&amp;gt;
Model: &amp;lt;motherboard model name&amp;gt;
  &amp;lt;label&amp;gt;: &amp;lt;mc&amp;gt;.&amp;lt;row&amp;gt;.&amp;lt;channel&amp;gt;&lt;/pre&gt;
&lt;p&gt;You can obtain the motherboard vendor and model name with the following
command:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# sudo ras-mc-ctl --mainboard
ras-mc-ctl: mainboard: ASUSTeK COMPUTER INC. model PRIME B450-PLUS&lt;/pre&gt;
&lt;p&gt;The label lines take a string (the name of the physical DIMM slot), then the
numbers in the EDAC path corresponding to the physical slot. You can put
more than one label entry per line by separating them with a semicolon. If a
given label is associated with more than one EDAC path you can add the separate
&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;&amp;lt;mc&amp;gt;.&amp;lt;row&amp;gt;.&amp;lt;channel&amp;gt;&lt;/span&gt;&lt;/code&gt; sequences by separating them with a comma.&lt;/p&gt;
&lt;p&gt;In my case the resulting file (&lt;code class="docutils literal"&gt;/etc/ras/dimm_labels.d/asus&lt;/code&gt;) looks like this:&lt;/p&gt;
&lt;pre class="literal-block"&gt;Vendor: ASUSTeK COMPUTER INC.
Model: PRIME B450-PLUS
  DIMM_A1:  0.0.0, 0.1.0;    DIMM_A2:   0.0.1, 0.1.1;
  DIMM_B1:  0.2.0, 0.3.0;    DIMM_B2:   0.2.1, 0.3.1;&lt;/pre&gt;
&lt;p&gt;You can find another example of this, with configuration entries for a bunch of
other motherboards, in the &lt;a class="reference external" href="https://github.com/grondo/edac-utils/blob/master/src/etc/labels.db"&gt;edac-utils&lt;/a&gt; repo.&lt;/p&gt;
&lt;p&gt;Once the file is ready it's time to load the labels in the kernel with the
following command:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# ras-mc-ctl --register-labels&lt;/pre&gt;
&lt;p&gt;Printing out labels and error counts will now use the physical DIMM slot names.
This is much better if you need to figure out which of your DIMMs is faulty and
needs to be replaced:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# ras-mc-ctl --print-labels
LOCATION                            CONFIGURED LABEL     SYSFS CONTENTS
                                    DIMM_A1              0:0:0 missing
                                    DIMM_A2              0:0:1 missing
                                    DIMM_A1              0:1:0 missing
                                    DIMM_A2              0:1:1 missing
mc0 csrow 2 channel 0               DIMM_B1              DIMM_B1
mc0 csrow 2 channel 1               DIMM_B2              DIMM_B2
mc0 csrow 3 channel 0               DIMM_B1              DIMM_B1
mc0 csrow 3 channel 1               DIMM_B2              DIMM_B2

# ras-mc-ctl --error-count
Label   CE      UE
DIMM_B2 0       0
DIMM_B1 0       0
DIMM_B1 0       0
DIMM_B2 0       0&lt;/pre&gt;
&lt;p&gt;To persist the DIMM names across reboots load the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;rac-mc-ctl&lt;/span&gt;&lt;/code&gt; service at
startup:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Debian/Ubuntu/Fedora and other systemd-based distros&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="literal-block"&gt;# systemctl enable ras-mc-ctl
# systemctl start ras-mc-ctl&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gentoo with OpenRC&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="literal-block"&gt;# rc-config add ras-mc-ctl default
# rc-config start ras-mc-ctl&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You're done! After rebooting your system rasdaemon will be continually running
and recording errors. You can use &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;ras-mc-ctl&lt;/span&gt;&lt;/code&gt; to print out a summary of all
the errors that have been seen and recorded. Since the counts are stored on
disk they will be persisted across reboots. Here's some example output from my
machine:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# ras-mc-ctl --summary
Memory controller events summary:
  Corrected on DIMM Label(s): 'DIMM_B1' location: 0:2:0:-1 errors: 5

PCIe AER events summary:
  1 Uncorrected (Non-Fatal) errors: BIT21

No Extlog errors.

No devlink errors.
Disk errors summary:
  0:0 has 6646 errors
No MCE errors.&lt;/pre&gt;
&lt;/section&gt;
&lt;section id="troubleshooting"&gt;
&lt;h2&gt;&lt;a class="toc-backref" href="https://www.setphaserstostun.org/posts/monitoring-ecc-memory-on-linux-with-rasdaemon/#toc-entry-4" role="doc-backlink"&gt;Troubleshooting&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;ras-mc-ctl&lt;/span&gt; &lt;span class="pre"&gt;--status&lt;/span&gt;&lt;/code&gt; prints out &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;ras-mc-ctl:&lt;/span&gt; drivers are not loaded&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;For &lt;strong&gt;rasdaemon&lt;/strong&gt; to work the EDAC kernel drivers for your particular
machine need to be loaded. They are usually loaded automatically at boot. You
can check out which ones are loaded with this command:&lt;/p&gt;
&lt;pre class="literal-block"&gt;# lsmod | grep edac
amd64_edac_mod         32768  0
edac_mce_amd           28672  1 amd64_edac_mod&lt;/pre&gt;
&lt;p&gt;If the EDAC drivers haven't been loaded automatically either your kernel
doesn't provide one for your machine or you need to manually load it. Check
the &lt;a class="reference external" href="https://www.kernel.org/doc/html/latest/driver-api/edac.html"&gt;EDAC kernel documentation&lt;/a&gt; for more details.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code class="docutils literal"&gt;rasdaemon&lt;/code&gt; fails to start, complaining it can't access the debugfs
filesystem&lt;/p&gt;
&lt;p&gt;You're likely using the kernel lockdown module in &lt;strong&gt;confidentiality&lt;/strong&gt; mode.
When Secure Boot is enabled this will prevent &lt;strong&gt;rasdaemon&lt;/strong&gt; from reading the
files it needs to gather its statistics. &lt;strong&gt;rasdaemon&lt;/strong&gt; can work with kernel
lockdown when using the &lt;strong&gt;integrity&lt;/strong&gt; mode. To switch to &lt;strong&gt;integrity&lt;/strong&gt; mode
add the &lt;cite&gt;lockdown=integrity&lt;/cite&gt; option to the Linux kernel command line in your
boot loader.&lt;/p&gt;
&lt;p&gt;When using &lt;strong&gt;GRUB&lt;/strong&gt; this can usually be achieved by editing
&lt;code class="docutils literal"&gt;/etc/default/grub&lt;/code&gt; and changing the &lt;code class="docutils literal"&gt;GRUB_CMDLINE_LINUX_DEFAULT&lt;/code&gt;
variable to include the option, e.g.:&lt;/p&gt;
&lt;pre class="literal-block"&gt;GRUB_CMDLINE_LINUX_DEFAULT="quiet splash lockdown=integrity"&lt;/pre&gt;
&lt;p&gt;Keep in mind that &lt;strong&gt;integrity&lt;/strong&gt; mode is less strict than &lt;strong&gt;confidentiality&lt;/strong&gt;
mode, as it permits userspace applications to access a fair amount of
information that lives in the kernel. This might not be suitable for some
deployments - such as those that must run untrusted userspace code.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;</description><category>debian</category><category>ecc</category><category>fedora</category><category>gentoo</category><category>linux</category><category>memory</category><category>opensuse</category><category>ubuntu</category><guid>https://www.setphaserstostun.org/posts/monitoring-ecc-memory-on-linux-with-rasdaemon/</guid><pubDate>Thu, 13 Feb 2020 22:31:44 GMT</pubDate></item><item><title>Gentoo 5.4.x generic kernel configuration</title><link>https://www.setphaserstostun.org/posts/gentoo-54x-generic-kernel-configuration/</link><dc:creator>Gabriele Svelto</dc:creator><description>&lt;p&gt;While the 5.4.x Linux kernel hasn't been marked as stable in &lt;a class="reference external" href="https://www.gentoo.org"&gt;Gentoo&lt;/a&gt; yet I've
updated my generic kernel configuration file to match it. As with the previous
config files for &lt;a class="reference external" href="https://www.setphaserstostun.org/posts/gentoo-414x-generic-kernel-configuration/"&gt;4.14.x&lt;/a&gt; and
&lt;a class="reference external" href="https://www.setphaserstostun.org/posts/gentoo-419x-generic-kernel-configuration/"&gt;4.19.x&lt;/a&gt; this configuration is
based on the Fedora kernel with some Gentoo-specific tweaks. It supports
practically every bit of hardware in existence and enables a lot of
bleeding-edge kernel functionality. The downside is that building it will take
a while and the modules will occupy quite a bit of storage.&lt;/p&gt;
&lt;p&gt;Note that this kernel configuration is for use with OpenRC. If you're using
systemd you'll have to remove the &lt;code class="docutils literal"&gt;CONFIG_GENTOO_LINUX_INIT_SCRIPT=y&lt;/code&gt; line
from the configuration file and add &lt;code class="docutils literal"&gt;CONFIG_GENTOO_LINUX_INIT_SYSTEMD=y&lt;/code&gt;
instead.&lt;/p&gt;
&lt;p&gt;To use it install the appropriate &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/gentoo-sources&lt;/span&gt;&lt;/code&gt; package
(5.4.x), copy the configuration file under &lt;code class="docutils literal"&gt;/usr/src/linux/&lt;/code&gt; and rename it
to &lt;code class="docutils literal"&gt;.config&lt;/code&gt; then proceed to build and install the kernel as usual.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="https://www.setphaserstostun.org/config-5.4"&gt;Gentoo 5.4.x kernel configuration file&lt;/a&gt;&lt;/p&gt;</description><category>gentoo</category><category>kernel</category><category>linux</category><guid>https://www.setphaserstostun.org/posts/gentoo-54x-generic-kernel-configuration/</guid><pubDate>Fri, 20 Dec 2019 08:28:11 GMT</pubDate></item><item><title>Gentoo 4.19.x generic kernel configuration</title><link>https://www.setphaserstostun.org/posts/gentoo-419x-generic-kernel-configuration/</link><dc:creator>Gabriele Svelto</dc:creator><description>&lt;p&gt;The 4.19.23 Linux kernel has been marked as stable in &lt;a class="reference external" href="https://www.gentoo.org"&gt;Gentoo&lt;/a&gt; a few days ago and
I've just updated my generic kernel configuration file to match it. As with the
&lt;a class="reference external" href="https://www.setphaserstostun.org/posts/gentoo-414x-generic-kernel-configuration/"&gt;the 4.14.x configuration&lt;/a&gt; I
posted a while ago this configuration is based on the Fedora kernel with some
Gentoo-specific tweaks. It supports practically every bit of hardware in
existence and enables a lot of bleeding-edge kernel functionality. The downside
is that building it will take a while and the modules will occupy quite a bit
of storage.&lt;/p&gt;
&lt;p&gt;To use it install the latest stable &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/gentoo-sources&lt;/span&gt;&lt;/code&gt; package
(4.19.x), copy the configuration file under &lt;code class="docutils literal"&gt;/usr/src/linux/&lt;/code&gt; and rename it
to &lt;code class="docutils literal"&gt;.config&lt;/code&gt; then proceed to build and install the kernel as usual.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="https://www.setphaserstostun.org/config-4.19"&gt;Gentoo 4.19.x kernel configuration file&lt;/a&gt;&lt;/p&gt;</description><category>gentoo</category><category>kernel</category><category>linux</category><guid>https://www.setphaserstostun.org/posts/gentoo-419x-generic-kernel-configuration/</guid><pubDate>Sun, 24 Feb 2019 20:10:28 GMT</pubDate></item><item><title>Setting the compose key on Xfce</title><link>https://www.setphaserstostun.org/posts/setting-the-compose-key-on-xfce/</link><dc:creator>Gabriele Svelto</dc:creator><description>&lt;p&gt;The &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Compose_key"&gt;compose key&lt;/a&gt; is a handy tool to generate characters that aren't available
on your keyboard. On Xfce there isn't a readily accessible way to set it, but
it can be done rather easily from the &lt;strong&gt;Settings Editor&lt;/strong&gt;:&lt;/p&gt;
&lt;ol class="arabic"&gt;
&lt;li&gt;&lt;p&gt;Launch the &lt;strong&gt;Settings Editor&lt;/strong&gt; from
&lt;em&gt;Applications &amp;gt; Settings &amp;gt; Settings Editor&lt;/em&gt; or via the terminal by executing
the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;xfce4-settings-editor&lt;/span&gt;&lt;/code&gt; command&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the &lt;strong&gt;keyboard-layout&lt;/strong&gt; channel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Look for the &lt;strong&gt;Compose&lt;/strong&gt; property under &lt;em&gt;Default &amp;gt; XkbOptions &amp;gt; Compose&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To enable the compose key you have to enter one of the following values in
the &lt;strong&gt;Compose&lt;/strong&gt; property:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th class="head"&gt;&lt;p&gt;Compose key&lt;/p&gt;&lt;/th&gt;
&lt;th class="head"&gt;&lt;p&gt;Value&lt;/p&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;p&gt;Right Win&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p&gt;compose:rwin&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;p&gt;Left Win&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p&gt;compose:lwin&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;p&gt;Right Ctrl&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p&gt;compose:rctrl&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;p&gt;Left Ctrl&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p&gt;compose:lctrl&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;p&gt;Right Alt&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p&gt;compose:ralt&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The resulting setting should look like this (I'm using the right Windows key in
this example):&lt;/p&gt;
&lt;img alt="/images/xfce-compose-key.png" src="https://www.setphaserstostun.org/images/xfce-compose-key.png"&gt;</description><category>linux</category><category>xfce</category><guid>https://www.setphaserstostun.org/posts/setting-the-compose-key-on-xfce/</guid><pubDate>Wed, 03 Oct 2018 11:21:27 GMT</pubDate></item><item><title>Gentoo 4.14.x generic kernel configuration</title><link>https://www.setphaserstostun.org/posts/gentoo-414x-generic-kernel-configuration/</link><dc:creator>Gabriele Svelto</dc:creator><description>&lt;p&gt;While the &lt;a class="reference external" href="https://wiki.gentoo.org/wiki/Handbook:Main_Page"&gt;Gentoo Handbook&lt;/a&gt; contains almost every step needed into making a
working &lt;a class="reference external" href="https://www.gentoo.org"&gt;Gentoo&lt;/a&gt; installation the kernel configuration step can be quite
confusing for a new user. Enabling proper hardware support and turning on all
the useful features can be daunting if you're not a developer or simply haven't
encountered the kernel configuration before.&lt;/p&gt;
&lt;p&gt;A good way around it is to use a generic kernel. &lt;a class="reference external" href="https://wiki.gentoo.org/wiki/Genkernel"&gt;genkernel&lt;/a&gt; provides a way to
build a default kernel but I often find its default configuration to be either
out-of-date or missing some important bit.&lt;/p&gt;
&lt;p&gt;So, if you want to get started on Gentoo quickly you might as well use &lt;em&gt;my&lt;/em&gt;
kernel configuration which is based on the Fedora kernel and as such follows an
everything-and-the-kitchen-sink approach. It supports practically every bit of
hardware out there, will work on desktop PCs, laptops and servers, and includes
important security features such as KPTI. The downside is that it's very large
and will take a long time to compile.&lt;/p&gt;
&lt;p&gt;To use it install the latest stable &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;sys-kernel/gentoo-sources&lt;/span&gt;&lt;/code&gt; package
(4.14.x), copy the configuration file under &lt;code class="docutils literal"&gt;/usr/src/linux/&lt;/code&gt; and rename it
to &lt;code class="docutils literal"&gt;.config&lt;/code&gt; then proceed to build the kernel as usual.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="https://www.setphaserstostun.org/config-4.14"&gt;Gentoo 4.14.x kernel configuration file&lt;/a&gt;&lt;/p&gt;</description><category>gentoo</category><category>kernel</category><category>linux</category><guid>https://www.setphaserstostun.org/posts/gentoo-414x-generic-kernel-configuration/</guid><pubDate>Thu, 13 Sep 2018 12:24:52 GMT</pubDate></item></channel></rss>