diff --git a/configs/releng/airootfs/usr/local/bin/fws-secureboot-setup b/configs/releng/airootfs/usr/local/bin/fws-secureboot-setup index 8462012..3c3ca2f 100644 --- a/configs/releng/airootfs/usr/local/bin/fws-secureboot-setup +++ b/configs/releng/airootfs/usr/local/bin/fws-secureboot-setup @@ -26,21 +26,32 @@ die() { printf '\e[31m[ERREUR] %s\e[0m\n' "$*"; exit 1; } command -v sbctl >/dev/null 2>&1 || { log "Installation de sbctl…"; pacman -S --noconfirm --needed sbctl || die "sbctl introuvable (réseau ?)"; } command -v objdump >/dev/null 2>&1 || pacman -S --noconfirm --needed binutils || true -# Localiser l'ESP et grubx64.efi (layout Arch : /boot/efi ; layout /boot-ESP : /boot). +# Localiser l'ESP et grubx64.efi. IDENTITÉ = FWS, cohérente avec le kickstart +# install_grub (--bootloader-id=FWS + --removable → \EFI\FWS\ ET \EFI\BOOT\). +# Signer un \EFI\GRUB\ séparé ne servirait à RIEN : le firmware charge \EFI\FWS\ +# (ou le secours \EFI\BOOT\BOOTX64.EFI) → ce sont EUX qu'il faut signer. ESP_DIR=/boot/efi; [ -d "$ESP_DIR/EFI" ] || ESP_DIR=/boot -GRUB_EFI="$ESP_DIR/EFI/GRUB/grubx64.efi" +GRUB_EFI="$ESP_DIR/EFI/FWS/grubx64.efi" [ -f "$GRUB_EFI" ] || GRUB_EFI="$(find "$ESP_DIR/EFI" -iname 'grubx64.efi' 2>/dev/null | head -1)" [ -n "$GRUB_EFI" ] && [ -f "$GRUB_EFI" ] || die "grubx64.efi introuvable sous $ESP_DIR/EFI" +BOOTX64="$ESP_DIR/EFI/BOOT/BOOTX64.EFI" # chemin de secours removable (à signer aussi) # 1) GRUB doit embarquer SBAT (+ shim_lock), sinon shim refusera de le charger. -# Un grub-install « nu » produit un binaire sans .sbat → on réinstalle. -if ! objdump -h "$GRUB_EFI" 2>/dev/null | grep -q '\.sbat'; then - warn "grubx64.efi sans section .sbat → réinstallation de GRUB (avec --sbat + modules)." - grub-install --target=x86_64-efi --efi-directory="$ESP_DIR" --bootloader-id=GRUB \ - --sbat /usr/share/grub/sbat.csv \ - --modules='normal search part_gpt part_msdos fat ext2 configfile linux echo test true loadenv all_video efi_gop tpm' \ - || die "grub-install a échoué" - GRUB_EFI="$ESP_DIR/EFI/GRUB/grubx64.efi" +# Un grub-install « nu » produit un binaire sans .sbat → on réinstalle EN FWS +# (et on régénère le secours removable \EFI\BOOT\BOOTX64.EFI avec le même SBAT). +if ! command -v objdump >/dev/null 2>&1; then + warn "objdump (binutils) absent → SBAT non vérifiable, réinstallation de GRUB SAUTÉE (on suppose GRUB déjà correct)." +elif ! objdump -h "$GRUB_EFI" 2>/dev/null | grep -q '\.sbat'; then + [ -f /usr/share/grub/sbat.csv ] || die "sbat.csv introuvable — impossible d'ajouter SBAT" + warn "grubx64.efi sans section .sbat → réinstallation de GRUB (--bootloader-id=FWS + --sbat)." + GRUB_MODULES='normal search part_gpt part_msdos fat ext2 configfile linux echo test true loadenv all_video efi_gop tpm' + grub-install --target=x86_64-efi --efi-directory="$ESP_DIR" --bootloader-id=FWS \ + --sbat /usr/share/grub/sbat.csv --modules="$GRUB_MODULES" \ + || die "grub-install (FWS) a échoué" + grub-install --target=x86_64-efi --efi-directory="$ESP_DIR" --bootloader-id=FWS --removable \ + --sbat /usr/share/grub/sbat.csv --modules="$GRUB_MODULES" \ + || warn "grub-install --removable (secours) a échoué" + GRUB_EFI="$ESP_DIR/EFI/FWS/grubx64.efi" objdump -h "$GRUB_EFI" 2>/dev/null | grep -q '\.sbat' || die "SBAT toujours absent après réinstallation" grub-mkconfig -o /boot/grub/grub.cfg 2>/dev/null || true fi @@ -56,9 +67,11 @@ log "Enrôlement des clés (avec Microsoft)…" sbctl enroll-keys --microsoft \ || warn "enroll-keys a échoué (firmware pas en Setup Mode ?) — à refaire une fois en Setup Mode." -# 4) Signer GRUB + noyau(x) présents. -log "Signature de GRUB et des noyaux…" -sbctl sign -s "$GRUB_EFI" || die "signature de GRUB échouée" +# 4) Signer les TROIS chemins réellement chargés par le firmware + les noyaux : +# \EFI\FWS\grubx64.efi, le secours \EFI\BOOT\BOOTX64.EFI, et chaque vmlinuz. +log "Signature de GRUB (FWS + secours removable) et des noyaux…" +sbctl sign -s "$GRUB_EFI" || die "signature de $GRUB_EFI échouée" +[ -f "$BOOTX64" ] && { sbctl sign -s "$BOOTX64" || warn "signature de $BOOTX64 échouée"; } for k in /boot/vmlinuz-linux /boot/vmlinuz-linux-lts /boot/vmlinuz-linux-zen /boot/vmlinuz-linux-hardened; do [ -f "$k" ] && { sbctl sign -s "$k" || warn "signature de $k échouée"; } done