I decided to start over and regenerate the keys. The kernel is the distribution kernel (sys-kernel/gentoo-kernel-bin) and should be signed. I followed the instructions here to regenerate the keys:
https://wiki.gentoo.org/wiki/Handbook:A ... el_modules
Code: Select all
mkdir -p /root/secure_boot
cd /root/secure_boot
openssl req -new -nodes -utf8 -sha256 -x509 -outform PEM -out kernel_key.pem -keyout kernel_key.pem
chown root: /root/secure_boot/kernel_key.pem
chmod 400 /root/secure_boot/kernel_key.pem
I ignored the description regarding /etc/portage/make.conf in this case.
For the installation of shim and Grub, I followed the instructions in the following manual:
https://wiki.gentoo.org/wiki/Handbook:A ... ecure_Boot
Code: Select all
export GRUB_MODULES="all_video boot btrfs cat chain configfile echo efifwsetup efinet ext2 fat font gettext gfxmenu gfxterm gfxterm_background gzio halt help hfsplus iso9660 jpeg keystatus loadenv loopback linux ls lsefi lsefimmap lsefisystab lssal memdisk minicmd normal ntfs part_apple part_msdos part_gpt password_pbkdf2 png probe reboot regexp search search_fs_uuid search_fs_file search_label sleep smbios squash4 test true video xfs zfs zfscrypt zfsinfo"
grub-install --target=x86_64-efi --efi-directory=/efi --modules="${GRUB_MODULES}" --sbat /usr/share/grub/sbat.csv
I signed Grub with the generated key as follows, and no errors occurred:
Code: Select all
sbsign /efi/EFI/gentoo/grubx64.efi --key /root/secure_boot/kernel_key.pem --cert /root/secure_boot/kernel_key.pem --out /efi/EFI/gentoo/grubx64.efi
Next, I copied the primary bootloader (shim) and the fallback menu screen (mmx64) in case of issues with shim:
Code: Select all
cp /usr/share/shim/BOOTX64.EFI /efi/EFI/Gentoo/shimx64.efi
cp /usr/share/shim/mmx64.efi /efi/EFI/Gentoo/mmx64.efi
Since the Grub signature was generated by me, it needs to be added to the MOKlist (otherwise, shim won't boot Grub).
I created the key and certificate in PEM format, but since mokutil only accepts DER format, I converted them:
Code: Select all
openssl x509 -in /root/secure_boot/kernel_key.pem -inform PEM -out /root/secure_boot/kernel_key.der -outform DER
I then loaded the converted DER format certificate into mokutil:
Code: Select all
mokutil --import /root/secure_boot/kernel_key.der
This registered the Grub certificate, so I understand why it can boot up to Grub. The issue now is that an error occurs when the kernel is loaded. Although not mentioned in the manual (which I find questionable), I forcefully registered the x509 certificate in DER format with mokutil in the same way as above:
Code: Select all
openssl x509 -in /usr/src/linux-6.8.9-gentoo-dist/certs/signing_key.x509 -out /root/secure_boot/signing_key.der -outform DER
mokutil --import /root/secure_boot/signing_key.der --ignore-keyring
You will be prompted for a password, which you need to enter twice for confirmation.
Finally, I created the entry with efibootmgr:
Code: Select all
efibootmgr --create --disk /dev/sda --part 1 --loader '\EFI\gentoo\shimx64.efi' --label 'secure gentoo' --unicode
These are all the steps I redid. I didn't touch anything else. When I changed the BIOS settings to enable Secure Boot and rebooted, the mmx64 screen appeared at about half the size of the display. The boot process continued, and GRUB did start. However, the borders of the GRUB screen were garbled (this has been happening since I enabled Secure Boot).
The problem remains that when loading the Linux kernel, I still get a "bad shim signature" error, and the kernel does not load.(OMG)
After writing out the process, I am still unsure about how the signed distribution kernel's signature information is supposed to be registered in the MOKlist. It might be that this registration is done during the kernel installation stage, but I have not yet confirmed this.