@charles17 told me he linked this post from https://wiki.gentoo.org/wiki/EFI_stub_k ... ecure_boot
Therefore I translated it in english (with google translator because of my poor school english) and you will find the translated text in the next post of this thread.
(Dieser Post ist Teil einer Installation-Anleitung. Falls nicht schon geschehen lies bitte: Installation Guide for Paranoid Dummies)
B.3 Umstellung auf SecureBoot
Voraussetzung ist ein Stub-Kernel ! Diesen musst Du vorher nach der Anleitung in B.2 gemacht haben.
Achtung: Diese Anleitung ist nicht geeignet, wenn Du Dual-Boot mit Windows willst !
Edit 2021-08-29: Dual-Boot mit Windows ist möglich, wenn die vorhandenen Schlüssel mit Deinen eigenen vereint werden . Ich habe das nicht selbst getestet, es soll jedoch funktionieren. Hier ist die Beschreibung von @dasPaul: https://forums.gentoo.org/viewtopic-p-8 ... ml#8652037
Folgende Links haben mir geholfen (habe ich numeriert, weil ich später darauf zu sprechen komme):
[1] http://www.rodsbooks.com/efi-bootloader ... ng-sb.html
[2] https://wiki.gentoo.org/wiki/User:Sakak ... der_OpenRC
(Allerdings benutzt Salaki da ein selbstgeschriebenes build-script für den Kernel, welches ich nicht brauchen kann. Dafür fehlten dann die nötigen Befehle. Hier hat [1] weitergeholfen.)
1. Den Kernel signieren
Dies war dank [1] sehr einfach, weil ich dort sein Skript rauskopiert habe und mir alle Schlüssel automatisiert erstellen habe lassen. Einzig die Gültigkeitsdauer der Schlüssel habe ich von 3650 Tagen (das sind ca. 10 Jahre) auf 9999 Tagen (das sind ca. 27 Jahre) geändert. Alles was jetzt kommt musst Du als root machen. Als erstes brauchst Du noch die "efitools", danach kannst Du von hier oder von [1] kopieren.
Code: Select all
# emerge -pvD efitools
# mkdir -p -m 0600 /etc/MY/efikeys
# cd /etc/MY/efikeys
# nano mkkeys.sh
===>
#!/bin/bash
# Copyright (c) 2015 by Roderick W. Smith
# Licensed under the terms of the GPL v3
echo -n "Enter a Common Name to embed in the keys: "
read NAME
openssl req -new -x509 -newkey rsa:2048 -subj "/CN=$NAME PK/" -keyout PK.key \
-out PK.crt -days 9999 -nodes -sha256
openssl req -new -x509 -newkey rsa:2048 -subj "/CN=$NAME KEK/" -keyout KEK.key \
-out KEK.crt -days 9999 -nodes -sha256
openssl req -new -x509 -newkey rsa:2048 -subj "/CN=$NAME DB/" -keyout DB.key \
-out DB.crt -days 9999 -nodes -sha256
openssl x509 -in PK.crt -out PK.cer -outform DER
openssl x509 -in KEK.crt -out KEK.cer -outform DER
openssl x509 -in DB.crt -out DB.cer -outform DER
GUID=`python -c 'import uuid; print(str(uuid.uuid1()))'`
echo $GUID > myGUID.txt
cert-to-efi-sig-list -g $GUID PK.crt PK.esl
cert-to-efi-sig-list -g $GUID KEK.crt KEK.esl
cert-to-efi-sig-list -g $GUID DB.crt DB.esl
rm -f noPK.esl
touch noPK.esl
sign-efi-sig-list -t "$(date --date='1 second' +'%Y-%m-%d %H:%M:%S')" \
-k PK.key -c PK.crt PK PK.esl PK.auth
sign-efi-sig-list -t "$(date --date='1 second' +'%Y-%m-%d %H:%M:%S')" \
-k PK.key -c PK.crt PK noPK.esl noPK.auth
sign-efi-sig-list -t "$(date --date='1 second' +'%Y-%m-%d %H:%M:%S')" \
-k PK.key -c PK.crt KEK KEK.esl KEK.auth
sign-efi-sig-list -t "$(date --date='1 second' +'%Y-%m-%d %H:%M:%S')" \
-k KEK.key -c KEK.crt db DB.esl DB.auth
chmod 0600 *.key
echo ""
echo ""
echo "For use with KeyTool, copy the *.auth and *.esl files to a FAT USB"
echo "flash drive or to your EFI System Partition (ESP)."
echo "For use with most UEFIs' built-in key managers, copy the *.cer files."
echo "" Code: Select all
# chmod +x mkkeys.sh
# ./mkkeys.shCode: Select all
# mount /boot
# sbsign --key DB.key --cert DB.crt --output bzImage.efi /boot/EFI/Boot/bzImage.efi
# cp bzImage.efi /boot/EFI/Boot/.Hier hat mir [2] geholfen. Ich habe von dort kopiert. Du kannst von hier kopieren:
Code: Select all
# cd ..
# mkdir oldefikeys
# cd oldefikeys
# efi-readvar -v PK -o old_PK.esl
# efi-readvar -v KEK -o old_KEK.esl
# efi-readvar -v db -o old_db.esl
# efi-readvar -v dbx -o old_dbx.eslErstmal die neuen Schlüssel in das EFI-Verzeichnis der ESP-Partition kopieren. Ich mache das, damit diese jetzt gleich über den UEFI-BIOS Menupunkt "Lade Schlüssel von Festplatte" übernommen werden können. In anderen Anleitungen wird dies über den Befehl "efi-updatevar" gemacht. Dies funktioniert aber nicht bei allen Mainboards; manche übernehmen die neuen Schlüssel nicht OHNE Dir einen Fehler zu melden. Deswegen ist die manuelle Übernahme im BIOS die sicherste Methode (sollte bei allen mainboards funktionieren).
Code: Select all
# cd /etc/MY/efikeys
# cp -v *.{auth,cer,crt,esl} /boot/EFI/.
'DB.auth' -> '/boot/EFI/./DB.auth'
'KEK.auth' -> '/boot/EFI/./KEK.auth'
'noPK.auth' -> '/boot/EFI/./noPK.auth'
'PK.auth' -> '/boot/EFI/./PK.auth'
'DB.cer' -> '/boot/EFI/./DB.cer'
'KEK.cer' -> '/boot/EFI/./KEK.cer'
'PK.cer' -> '/boot/EFI/./PK.cer'
'DB.crt' -> '/boot/EFI/./DB.crt'
'KEK.crt' -> '/boot/EFI/./KEK.crt'
'PK.crt' -> '/boot/EFI/./PK.crt'
'DB.esl' -> '/boot/EFI/./DB.esl'
'KEK.esl' -> '/boot/EFI/./KEK.esl'
'noPK.esl' -> '/boot/EFI/./noPK.esl'
'PK.esl' -> '/boot/EFI/./PK.esl'4. Überprüfen und Aufräumen
Mein Startbildschirm (BIOS Boot-Logo) zeigte mir erstmalig unter dem Logo eine zusätzliche Zeile an:
"EFI Stub: UEFI Secure Boot is enabled"
Sofort in die /var/log/messages reingeschaut und siehe da:
Code: Select all
Mar 14 00:57:07 big kernel: [ 0.003681] Secure boot enabledCode: Select all
# od --address-radix=n --format=u1 /sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c
6 0 0 0 1 Code: Select all
# efi-readvar
Variable PK, length 851
PK: List 0, type X509
Signature 0, size 823, owner 79a99678-6581-11ea-b4d3-1c1b0d93463e
Subject:
CN=MY SECURE BOOT KEYS PK
Issuer:
CN=MY SECURE BOOT KEYS PK
Variable KEK, length 853
KEK: List 0, type X509
Signature 0, size 825, owner 79a99678-6581-11ea-b4d3-1c1b0d93463e
Subject:
CN=MY SECURE BOOT KEYS KEK
Issuer:
CN=MY SECURE BOOT KEYS KEK
Variable db, length 851
db: List 0, type X509
Signature 0, size 823, owner 79a99678-6581-11ea-b4d3-1c1b0d93463e
Subject:
CN=MY SECURE BOOT KEYS DB
Issuer:
CN=MY SECURE BOOT KEYS DB
Variable dbx has no entries
Variable MokList has no entriesCode: Select all
# mount /boot/
# cd /boot/EFI/
# lal
insgesamt 68
drwxr-xr-x 4 root root 4096 14. Mär 00:39 .
drwxr-xr-x 4 root root 4096 1. Jan 1970 ..
drwxr-xr-x 2 root root 4096 13. Mär 20:58 Boot
-rwxr-xr-x 1 root root 2102 14. Mär 00:39 DB.auth
-rwxr-xr-x 1 root root 807 14. Mär 00:39 DB.cer
-rwxr-xr-x 1 root root 1147 14. Mär 00:39 DB.crt
-rwxr-xr-x 1 root root 851 14. Mär 00:39 DB.esl
drwxr-xr-x 2 root root 4096 11. Feb 2017 gentoo
-rwxr-xr-x 1 root root 2101 14. Mär 00:39 KEK.auth
-rwxr-xr-x 1 root root 809 14. Mär 00:39 KEK.cer
-rwxr-xr-x 1 root root 1151 14. Mär 00:39 KEK.crt
-rwxr-xr-x 1 root root 853 14. Mär 00:39 KEK.esl
-rwxr-xr-x 1 root root 1248 14. Mär 00:39 noPK.auth
-rwxr-xr-x 1 root root 0 14. Mär 00:39 noPK.esl
-rwxr-xr-x 1 root root 2099 14. Mär 00:39 PK.auth
-rwxr-xr-x 1 root root 807 14. Mär 00:39 PK.cer
-rwxr-xr-x 1 root root 1147 14. Mär 00:39 PK.crt
-rwxr-xr-x 1 root root 851 14. Mär 00:39 PK.esl
EFI # rm *
rm: das Entfernen von 'Boot' ist nicht möglich: Ist ein Verzeichnis
rm: das Entfernen von 'gentoo' ist nicht möglich: Ist ein VerzeichnisCode: Select all
Neue Kernel-Version:
--------------------
# emerge -1uvDp gentoo-sources
# mount /boot
# cd /usr/src/linux-X.Y.Z-gentoo
# cp /usr/src/linux/.config .
# make oldconfig
# make -j 8
# sbsign --key /etc/MY/efikeys/DB.key --cert /etc/MY/efikeys/DB.crt --output /boot/EFI/Boot/bzImage.efi arch/x86/boot/bzImage
(# make modules_install)
# cp .config /etc/MY/config-X-Y-Z
# eselect kernel list
# eselect kernel set
# umount /boot
Änderung der Konfiguration des bestehenden Kernels:
---------------------------------------------------
# mount /boot
# cd /usr/src/linux
# make menuconfig
# make -j 8
# sbsign --key /etc/MY/efikeys/DB.key --cert /etc/MY/efikeys/DB.crt --output /boot/EFI/Boot/bzImage.efi arch/x86/boot/bzImage
(# make modules_install)
# cp .config /etc/MY/config-X-Y-Z-revA
# umount /boot
Nach erfolgreichem Boot eines neuen Kernels:
--------------------------------------------
# mount /boot
# cd /usr/src/linux
# make install
# grub-mkconfig -o /boot/grub/grub.cfg
# umount /boot... aber das brauche ich Dir wohl nicht mehr zu sagen. Genausowenig muss ich Dir noch sagen, dass Du natürlich SecureBoot im BIOS wieder disabeln musst, falls Du mal in die Verlegenheit kommst, einen vorherigen Kernel mit Grub starten zu müssen. Ja, man könnte auch den Grub signieren, aber dazu bin ich einfach zu faul. Ich muß ja eh ins BIOS um die Boot-Reihenfole zu ändern. Außerdem musste ich bis jetzt noch nie über Grub starten ... neuer Kernel war immer gut.
