<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sbctl on Giovanni Bassi</title><link>https://giggio.net/en/blog/tags/sbctl/</link><image><url>https://giggio.net/images/base/logo-small.png</url><title>Sbctl on Giovanni Bassi</title><link>https://giggio.net/en/blog/tags/sbctl/</link></image><description>Sbctl no site do Giovanni Bassi</description><generator>Hugo</generator><language>en</language><managingEditor>giggio@giggio.net (Giovanni Bassi)</managingEditor><webMaster>giggio@giggio.net (Giovanni Bassi)</webMaster><copyright>© 2025 Giovanni Bassi</copyright><lastBuildDate>Thu, 14 May 2026 11:00:00 -0300</lastBuildDate><atom:link href="https://giggio.net/en/blog/tags/sbctl/index.xml" rel="self" type="application/rss+xml"/><item><title>NixOS: Installation Guide with RAID 1, encryption, and TPM Unlock (part 4 - Secure Boot)</title><link>https://giggio.net/en/blog/nix-os-guia-de-instalacao-com-raid-1-criptografia-e-tpm-unlock-parte-4-secure-boot/</link><pubDate>Thu, 14 May 2026 11:00:00 -0300</pubDate><author>giggio@giggio.net (Giovanni Bassi)</author><guid>https://giggio.net/en/blog/nix-os-guia-de-instalacao-com-raid-1-criptografia-e-tpm-unlock-parte-4-secure-boot/</guid><category>infra</category><description>&lt;p&gt;In the fourth post of our series, we are going to configure Secure Boot to ensure that only trusted operating
systems can be executed.&lt;/p&gt;
&lt;p&gt;This is the fourth post of the series:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://giggio.net/en/blog/nix-os-guia-de-instalacao-com-raid-1-criptografia-e-tpm-unlock-parte-1/"&gt;Preparing the virtual machine and partitioning the disks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://giggio.net/en/blog/nix-os-guia-de-instalacao-com-raid-1-criptografia-e-tpm-unlock-parte-2-disko-luks-e-btrfs/"&gt;Disko, LUKS, and btrfs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://giggio.net/en/blog/nix-os-guia-de-instalacao-com-raid-1-criptografia-e-tpm-unlock-parte-3-instalando-o-so/"&gt;Installing the OS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Enabling Secure Boot (this post)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Secure Boot is a fundamental component for tightening the security, especially when using the TPM to automatically
decrypt the disk. I will explain what it is, what it’s for, and how to implement it in NixOS using Lanzaboote.&lt;/p&gt;
&lt;h3 id="understanding-secure-boot"&gt;
 &lt;a href="#understanding-secure-boot" class="site-blog-post-header"&gt;
 &lt;span class="site-blog-post-header-text"&gt;Understanding Secure Boot&lt;/span&gt;
 &lt;i class="fa-solid fa-link site-blog-post-header-paragraph"&gt;&lt;/i&gt;
 &lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Secure Boot is a protocol that is part of the UEFI (Unified Extensible Firmware Interface). When enabled, it verifies if
the operating system&amp;rsquo;s bootloader has a valid digital signature recognized by the keys registered in the motherboard&amp;rsquo;s
firmware.&lt;/p&gt;
&lt;p&gt;This prevents boot-level malware (rootkits) or unauthorized operating systems from loading. Additionally, the TPM uses
the Secure Boot state as one of the metrics to decide whether or not to release the disk encryption keys.&lt;/p&gt;
&lt;p&gt;There are three main ways to manage Secure Boot keys:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Factory default keys:&lt;/strong&gt; Usually the Microsoft keys that come with almost every computer;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Custom keys (User Mode):&lt;/strong&gt; You remove the Microsoft keys and install only your own;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hybrid Mode:&lt;/strong&gt; You keep the Microsoft keys (for dual-booting with Windows) and add your own.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you don&amp;rsquo;t intend to run Windows, the second option is the most restrictive and secure. If you need dual boot, the
third is mandatory. It&amp;rsquo;s worth noting that NixOS does not have a bootloader signed by Microsoft (unlike Ubuntu or
Fedora), so we always need to generate our own keys.&lt;/p&gt;
&lt;p&gt;And why Microsoft keys, specifically? Because they were the first company to push Secure Boot as mandatory, and they
hold the largest share of the PC market.
&lt;a href="https://en.wikipedia.org/wiki/UEFI#Secure_Boot_criticism"&gt;There is quite a bit of controversy regarding this&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The important thing for our setup is knowing that once you define how Secure Boot will be used, it cannot be changed
without breaking the automatic decryption process (which will be done with the help of the TPM). In our case, we will
use the third option (mixing Microsoft keys with our own). If Secure Boot is turned off on the machine or a new platform
key is loaded, the TPM will refuse to decrypt the disk. I’ll explain this in future posts, so for now, what matters is
enabling Secure Boot.&lt;/p&gt;
&lt;h3 id="putting-the-firmware-into-setup-mode"&gt;
 &lt;a href="#putting-the-firmware-into-setup-mode" class="site-blog-post-header"&gt;
 &lt;span class="site-blog-post-header-text"&gt;Putting the Firmware into Setup Mode&lt;/span&gt;
 &lt;i class="fa-solid fa-link site-blog-post-header-paragraph"&gt;&lt;/i&gt;
 &lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;In the first post, we cleared the keys in the VM&amp;rsquo;s boot menu to enter Setup Mode. This is essential: for us to write
our keys via software, the firmware must be &amp;ldquo;open&amp;rdquo; to new signatures.&lt;/p&gt;
&lt;p&gt;Confirm the status by running:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-console" data-lang="console"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="gp"&gt;$&lt;/span&gt; sudo bootctl status
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;Secure Boot: disabled (setup)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If &lt;code&gt;disabled (setup)&lt;/code&gt; appears, we are ready to proceed.&lt;/p&gt;
&lt;h3 id="generating-keys-with-sbctl"&gt;
 &lt;a href="#generating-keys-with-sbctl" class="site-blog-post-header"&gt;
 &lt;span class="site-blog-post-header-text"&gt;Generating Keys with sbctl&lt;/span&gt;
 &lt;i class="fa-solid fa-link site-blog-post-header-paragraph"&gt;&lt;/i&gt;
 &lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;We will use &lt;a href="https://github.com/Foxboron/sbctl/"&gt;sbctl&lt;/a&gt; to create and register our keys. Since it isn&amp;rsquo;t installed by
default, let&amp;rsquo;s use &lt;code&gt;nix-shell&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;nix-shell -p sbctl
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: In NixOS, you can bring any application into your terminal&amp;rsquo;s context using &lt;code&gt;nix-shell&lt;/code&gt;. With this, the &lt;code&gt;sbctl&lt;/code&gt;
command becomes available in a subshell — to exit, just run &lt;code&gt;exit&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To generate the keys, we will run the &lt;code&gt;create-keys&lt;/code&gt; subcommand:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo sbctl create-keys
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The keys will be generated in &lt;code&gt;/var/lib/sbctl/&lt;/code&gt;. You can see the structure with the &lt;code&gt;tree&lt;/code&gt; command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-console" data-lang="console"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="gp"&gt;$&lt;/span&gt; tree /var/lib/sbctl/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;/var/lib/sbctl/
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;├── GUID
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;└── keys
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; ├── db
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; │   ├── db.key
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; │   └── db.pem
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; ├── KEK
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; │   ├── KEK.key
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; │   └── KEK.pem
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; └── PK
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; ├── PK.key
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; └── PK.pem
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Install the keys into the machine&amp;rsquo;s firmware with &lt;code&gt;enroll-keys&lt;/code&gt;. This will use the keys we created earlier with &lt;code&gt;sbctl&lt;/code&gt;.
With the &lt;code&gt;--microsoft&lt;/code&gt; argument, Microsoft&amp;rsquo;s platform keys will also be installed:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo sbctl enroll-keys --microsoft
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Verify that Secure Boot has been re-enabled with:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo bootctl status
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It should show &lt;code&gt;Secure Boot: enabled (user)&lt;/code&gt;. It might not show as enabled yet until the next boot, showing up as
&lt;code&gt;Secure Boot: disabled&lt;/code&gt;, but without &lt;code&gt;setup&lt;/code&gt;. But don&amp;rsquo;t reboot just yet!&lt;/p&gt;
&lt;h3 id="signing-the-boot-with-lanzaboote"&gt;
 &lt;a href="#signing-the-boot-with-lanzaboote" class="site-blog-post-header"&gt;
 &lt;span class="site-blog-post-header-text"&gt;Signing the Boot with Lanzaboote&lt;/span&gt;
 &lt;i class="fa-solid fa-link site-blog-post-header-paragraph"&gt;&lt;/i&gt;
 &lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;At this point, if you restart the machine, NixOS will no longer boot, as the NixOS bootloader is not yet signed with the
Secure Boot keys we created in the previous step. That’s where &lt;a href="https://github.com/nix-community/lanzaboote"&gt;Lanzaboote&lt;/a&gt;
comes in. It automates the signing of NixOS generations. It replaces the default &lt;code&gt;systemd-boot&lt;/code&gt; manager with one that
handles the keys generated by &lt;code&gt;sbctl&lt;/code&gt;. Once enabled, whenever a new bootloader is created in the &lt;code&gt;/boot&lt;/code&gt; directory, it
will be signed with the keys located in &lt;code&gt;/var/lib/sbctl&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To enable Lanzaboote and then sign the files, first go to the configuration directory that was copied in previous posts
to &lt;code&gt;/etc/nixos&lt;/code&gt;, and check out the correct commit. Be careful not to forget the &lt;code&gt;git checkout&lt;/code&gt;, or it won&amp;rsquo;t work:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /etc/nixos
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# ensuring the current user owns the files:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo chown -R giggio:users .
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# checkout with the message &amp;#34;Enable lanzaboote&amp;#34;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git checkout dab0fd4
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The change in your &lt;code&gt;configuration.nix&lt;/code&gt; disables the native &lt;code&gt;systemd-boot&lt;/code&gt; and activates &lt;code&gt;lanzaboote&lt;/code&gt;, pointing to the
keys directory:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-nix" data-lang="nix"&gt;&lt;span class="line hl"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;boot&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loader&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;systemd-boot&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;enable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;boot&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lanzaboote&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line hl"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;enable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;pkiBundle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;/var/lib/sbctl&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The Lanzaboote configuration was already present; it was just disabled. And with it enabled, &lt;code&gt;systemd-boot&lt;/code&gt; can be
disabled. Note also that the keys directory, defined in the &lt;code&gt;pkiBundle&lt;/code&gt; attribute, is already correctly pointed to
&lt;code&gt;/var/lib/sbctl&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s all; now just install the new configurations, which take effect immediately and will also be effective on the
next boot:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo nixos-rebuild switch
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="validating-the-signature"&gt;
 &lt;a href="#validating-the-signature" class="site-blog-post-header"&gt;
 &lt;span class="site-blog-post-header-text"&gt;Validating the Signature&lt;/span&gt;
 &lt;i class="fa-solid fa-link site-blog-post-header-paragraph"&gt;&lt;/i&gt;
 &lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;To ensure Lanzaboote did its job and signed the &lt;code&gt;.efi&lt;/code&gt; binaries, run:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-console" data-lang="console"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="gp"&gt;$&lt;/span&gt; sudo sbctl verify
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;Verifying file database and EFI images in /boot...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;✓ /boot/EFI/BOOT/BOOTX64.EFI is signed
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;✓ /boot/EFI/Linux/nixos-generation-1-xxx.efi is signed
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;✓ /boot/EFI/Linux/nixos-generation-2-yyy.efi is signed
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;✗ /boot/EFI/nixos/kernel-7.0-zzz.efi is not signed
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;✓ /boot/EFI/systemd/systemd-bootx64.efi is signed
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Note about the Kernel:&lt;/strong&gt; It is normal to see an &lt;code&gt;✗&lt;/code&gt; on the isolated kernel file. What matters are the files inside
&lt;code&gt;/boot/EFI/&lt;/code&gt; and the boot managers. Lanzaboote creates a &lt;strong&gt;Unified Kernel Image (UKI)&lt;/strong&gt;, which bundles the kernel and
the initrd into a single signed executable that the UEFI can run directly.&lt;/p&gt;
&lt;p&gt;Now you can reboot. If everything went well, the system will come up normally and &lt;code&gt;bootctl status&lt;/code&gt; will confirm: &lt;code&gt;Secure Boot: enabled (user)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The machine still asks for the password to decrypt the disk. This is expected, as we haven&amp;rsquo;t yet implemented the
structure for automatic decryption with the TPM.&lt;/p&gt;
&lt;h3 id="troubleshooting-secure-boot"&gt;
 &lt;a href="#troubleshooting-secure-boot" class="site-blog-post-header"&gt;
 &lt;span class="site-blog-post-header-text"&gt;Troubleshooting Secure Boot&lt;/span&gt;
 &lt;i class="fa-solid fa-link site-blog-post-header-paragraph"&gt;&lt;/i&gt;
 &lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If something goes wrong and the VM won&amp;rsquo;t start, you can reset the NVRAM (the VM&amp;rsquo;s &amp;ldquo;BIOS&amp;rdquo;). On your host, turn off the VM
and run:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# on the host:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;virsh start &amp;lt;vm_name&amp;gt; --reset-nvram
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will start the virtual machine normally, but with all the firmware boot settings lost, including Secure Boot
settings.&lt;/p&gt;
&lt;p&gt;The following commands will re-apply the boot settings to the firmware&amp;rsquo;s non-volatile memory and the disk:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# on the vm:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# registering platform keys in the firmware again:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo sbctl enroll-keys --microsoft
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# installing the boot menu option:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo bootctl install
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# re-signing the UKIs:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo nixos-rebuild switch
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Why run switch again&lt;/strong&gt;: When running &lt;code&gt;bootctl install&lt;/code&gt;, the files &lt;code&gt;/boot/EFI/systemd/systemd-bootx64.efi&lt;/code&gt; and
&lt;code&gt;/boot/EFI/BOOT/BOOTX64.EFI&lt;/code&gt; will not be signed, so it is necessary to run &lt;code&gt;switch&lt;/code&gt; so that these two files become
signed again.&lt;/p&gt;
&lt;h3 id="declarative-approach"&gt;
 &lt;a href="#declarative-approach" class="site-blog-post-header"&gt;
 &lt;span class="site-blog-post-header-text"&gt;Declarative Approach&lt;/span&gt;
 &lt;i class="fa-solid fa-link site-blog-post-header-paragraph"&gt;&lt;/i&gt;
 &lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Lanzaboote allows generating platform keys automatically via Nix config:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-nix" data-lang="nix"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;boot&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lanzaboote&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;autoGenerateKeys&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;enable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;autoEnrollKeys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;enable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;autoReboot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is described in more detail in the
&lt;a href="https://github.com/nix-community/lanzaboote/blob/079c608988c2747db3902c9de033572cd50e8656/docs/explanation/automatic-provisioning.md"&gt;docs on automatic provisioning&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;While practical for testing, I don&amp;rsquo;t recommend using this in production systems. The ideal approach is to generate keys
manually (as I demonstrated here) and store them securely somewhere. A good option is to use
&lt;a href="https://github.com/Mic92/sops-nix/"&gt;sops-nix&lt;/a&gt;, keeping the keys encrypted within the repository itself. The
inconvenience would be during application, where you would always need the keys or devices to decrypt the &lt;code&gt;sops&lt;/code&gt; secrets
at every &lt;code&gt;nixos-rebuild&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id="next-up-using-tpm-to-decrypt-the-disk"&gt;
 &lt;a href="#next-up-using-tpm-to-decrypt-the-disk" class="site-blog-post-header"&gt;
 &lt;span class="site-blog-post-header-text"&gt;Next Up: Using TPM to Decrypt the Disk&lt;/span&gt;
 &lt;i class="fa-solid fa-link site-blog-post-header-paragraph"&gt;&lt;/i&gt;
 &lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Secure Boot is active. The disk is encrypted. But we still have to type the LUKS password at every boot.&lt;/p&gt;
&lt;p&gt;If someone tries to start another operating system, it will need to be signed with your platform key or Microsoft&amp;rsquo;s. You
can make the system more secure by removing the &lt;code&gt;--microsoft&lt;/code&gt; option from the &lt;code&gt;enroll-keys&lt;/code&gt; command and not allowing any
other operating system.&lt;/p&gt;
&lt;p&gt;In the next post, we will configure the &lt;strong&gt;TPM (Trusted Platform Module)&lt;/strong&gt; so that it &amp;ldquo;measures&amp;rdquo; the Secure Boot state
and releases the encryption key automatically if the system hasn&amp;rsquo;t been tampered with. Maximum security with
convenience.&lt;/p&gt;
&lt;p&gt;See you then!&lt;/p&gt;</description></item></channel></rss>