fix(boot): never write NVRAM on Intel RST machines
Seen on real RST hardware: the installed system boots once, then never again, the firmware no longer finding a bootable disk. What is established. In the installer's chroot efivars is not reachable, so nothing is written to NVRAM and the firmware boots EFI/BOOT/BOOTX64.EFI, which it finds by scanning the ESP. That first boot works. Then fws-grub-finalize runs grub-install again, and this time efivars answers: it creates a "FWS" entry and puts it first in the boot order. That is the only thing this chain changes at firmware level between the two boots, and firmware level is where the second one fails. What is assumed, not verified for lack of a VMD machine: why that entry is unusable. Under VMD, Linux sees the NVMe in a synthetic PCI domain (10000:...) that the vmd module creates and the firmware knows nothing about, so a device path computed from that view resolves to nothing. "efibootmgr -v" on an affected machine would settle it. On any machine with an Intel VMD controller, FWS now relies solely on the --removable path, which the first boot proves works. Detection goes through fws-intel-rst (exit codes 10/11/12), the project's single VMD logic. Machines without VMD are untouched and keep their NVRAM entry. There were three NVRAM writers, and all three are gated: - the kickstart %post, where the write fails anyway today but would break even the first boot in an environment that exposed efivars to the chroot; - fws-grub-finalize, both grub-install and the efibootmgr -c fallback; - fws-recovery, which was the worst of them. It goes through arch-chroot, and unlike Anaconda's chroot, arch-chroot mounts efivars, so the write succeeded there, from the ISO as well as from the installed system. A user whose RST machine would not boot would run "Réparer FWS", and the repair would recreate exactly the entry that stops it from booting. Also in fws-grub-finalize: two lsblk calls took the disk from "lsblk -s", which draws a tree, and got "└─/dev/nvme0n1" (checked on a real NVMe). The efibootmgr fallback therefore always received a garbage device and never created its entry, and the ESP search could fall back to the first ESP on the system, Windows' on a dual-boot. The kickstart had already fixed this very trap in its BIOS branch; the UEFI branch here had been missed. Fixing it alone would have re-armed the efibootmgr writer on VMD, which is why it lands together with the gate. Tested by replacing the system tools with recording stubs: fws-grub-finalize and fws-recovery each over five cases (no VMD, VMD in its three states, engine missing), plus the engine's six detection cases. In every case the --removable path is still installed, since on these machines it becomes the only way in. Signed-off-by: nocode <suzuku295@gmail.com>
This commit is contained in:
1 parent
3b0bd2ccda
commit
90167c54b6
3 files changed
+73
-7
No files matched your search
@@ -80,12 +80,48 @@ find_esp() {
|
||||
# l'ESP d'un autre OS (cas dual-boot vu en réel : ESP Windows sur le 1er
|
||||
# disque), on retombe sur la première ESP FAT32 trouvée.
|
||||
OK=1
|
||||
|
||||
# --- Intel RST / VMD : NE JAMAIS ÉCRIRE DANS LA NVRAM ------------------------
|
||||
# SYMPTÔME (vu sur du vrai matériel RST) : 1er démarrage OK, plus jamais ensuite,
|
||||
# le firmware ne trouvant plus de disque démarrable.
|
||||
#
|
||||
# CE QUI EST ÉTABLI. Dans le chroot de l'installateur, efivars est inaccessible :
|
||||
# rien n'est écrit en NVRAM et le firmware démarre par EFI/BOOT/BOOTX64.EFI, qu'il
|
||||
# trouve en parcourant l'ESP. Ici, au 1er démarrage, efivars répond : grub-install
|
||||
# crée l'entrée « FWS » et la place EN TÊTE de l'ordre de démarrage. C'est la
|
||||
# seule chose que ce script change AU NIVEAU DU FIRMWARE entre les deux
|
||||
# démarrages — et c'est au niveau du firmware que le 2e échoue.
|
||||
#
|
||||
# CE QUI EST SUPPOSÉ, pas vérifié faute de machine VMD : pourquoi cette entrée
|
||||
# est inutilisable. Sous VMD, Linux voit le NVMe dans un domaine PCI synthétique
|
||||
# (10000:…) créé par le module vmd, que le firmware ne connaît pas ; un chemin de
|
||||
# périphérique calculé depuis cette vue ne se résout pas côté firmware. Pour
|
||||
# trancher : « efibootmgr -v » montre le chemin de l'entrée FWS, et la supprimer
|
||||
# (« efibootmgr -b XXXX -B ») doit suffire à rendre la machine démarrable.
|
||||
#
|
||||
# Sur VMD on s'appuie donc UNIQUEMENT sur le chemin --removable, que le 1er
|
||||
# démarrage prouve fonctionnel. Détection déléguée à fws-intel-rst (codes
|
||||
# 10/11/12 = contrôleur VMD présent), seule logique VMD du projet.
|
||||
VMD=0
|
||||
if [ -x /usr/local/bin/fws-intel-rst ]; then
|
||||
/usr/local/bin/fws-intel-rst --detect >/dev/null 2>&1
|
||||
case $? in 10|11|12) VMD=1 ;; esac
|
||||
fi
|
||||
NVRAM_OPT=""
|
||||
if [ "$VMD" = 1 ]; then
|
||||
NVRAM_OPT="--no-nvram"
|
||||
echo "[FWS] contrôleur Intel VMD/RST : aucune écriture NVRAM, chemin --removable seul"
|
||||
fi
|
||||
|
||||
if [ -d /sys/firmware/efi ]; then
|
||||
esp=""
|
||||
if ! mountpoint -q /boot/efi; then
|
||||
# /boot/efi pas monté (ou pas dans le fstab) : on cherche.
|
||||
rootsrc="$(findmnt -no SOURCE / 2>/dev/null)"
|
||||
rootdisk="$(lsblk -spno NAME,TYPE "$rootsrc" 2>/dev/null | awk '$2=="disk"{print $1; exit}')"
|
||||
# « lsblk -s » dessine un ARBRE : sans le grep, $1 vaut « └─/dev/nvme0n1 »
|
||||
# (vérifié), find_esp ne trouve rien et on retombe sur la PREMIÈRE ESP du
|
||||
# système — celle de Windows sur un dual-boot. Même filtre que la ligne BIOS.
|
||||
rootdisk="$(lsblk -spno NAME,TYPE "$rootsrc" 2>/dev/null | awk '$2=="disk"{print $1; exit}' | grep -oE '/dev/[a-z0-9]+')"
|
||||
if [ -n "$rootdisk" ]; then
|
||||
esp="$(find_esp "$rootdisk")"
|
||||
fi
|
||||
@@ -104,7 +140,7 @@ if [ -d /sys/firmware/efi ]; then
|
||||
# (a) Entrée NVRAM « FWS » + fichiers EFI/FWS (best effort : grub-install
|
||||
# crée lui-même l'entrée si efivars est accessible) :
|
||||
grub-install --target=x86_64-efi --efi-directory=/boot/efi \
|
||||
--bootloader-id=FWS --recheck || echo "[FWS] grub-install (NVRAM) : échec, ignoré"
|
||||
--bootloader-id=FWS $NVRAM_OPT --recheck || echo "[FWS] grub-install (NVRAM) : échec, ignoré"
|
||||
# (b) Chemin de SECOURS EFI/BOOT/BOOTX64.EFI (--removable) : boote SANS
|
||||
# aucune entrée NVRAM. INDISPENSABLE sur firmware qui « oublie »
|
||||
# l'entrée (ASUS…) — c'est lui qui garantit le 1er boot.
|
||||
@@ -121,11 +157,16 @@ if [ -d /sys/firmware/efi ]; then
|
||||
fi
|
||||
# (c) Rafraîchir l'entrée NVRAM si elle manque (efibootmgr). GRUB booté
|
||||
# a déjà créé « FWS » ; on ne duplique pas si l'entrée existe.
|
||||
if command -v efibootmgr >/dev/null 2>&1 \
|
||||
# Coupé sur VMD pour la même raison que --no-nvram ci-dessus : ce bloc
|
||||
# écrirait la même entrée au chemin irrésoluble.
|
||||
if [ "$VMD" = 0 ] && command -v efibootmgr >/dev/null 2>&1 \
|
||||
&& [ -d /sys/firmware/efi/efivars ]; then
|
||||
espdev="$(findmnt -no SOURCE /boot/efi 2>/dev/null)"
|
||||
if [ -n "$espdev" ]; then
|
||||
disk="$(lsblk -spno NAME,TYPE "$espdev" | awk '$2=="disk"{print $1; exit}')"
|
||||
# Même piège d'arbre : sans le grep, efibootmgr reçoit
|
||||
# « └─/dev/nvme0n1 », échoue en silence, et l'entrée NVRAM de
|
||||
# secours n'est JAMAIS créée.
|
||||
disk="$(lsblk -spno NAME,TYPE "$espdev" | awk '$2=="disk"{print $1; exit}' | grep -oE '/dev/[a-z0-9]+')"
|
||||
part="$(printf '%s' "$espdev" | grep -oE '[0-9]+$')"
|
||||
if ! efibootmgr 2>/dev/null | grep -qi 'FWS'; then
|
||||
efibootmgr -c -d "${disk:-/dev/null}" -p "${part:-1}" \
|
||||
|
||||
@@ -90,8 +90,23 @@ mount_target() {
|
||||
fix_grub() {
|
||||
say "Réinstallation de GRUB…"
|
||||
if [ -d /sys/firmware/efi ]; then
|
||||
# Intel VMD/RST : pas d'entrée NVRAM (cf. fws-grub-finalize, qui détaille
|
||||
# le pourquoi). C'est ICI que ça compte le plus : in_target passe par
|
||||
# arch-chroot, qui MONTE efivars — contrairement au chroot d'Anaconda,
|
||||
# l'écriture NVRAM réussirait donc, et la réparation recréerait
|
||||
# précisément l'entrée qui empêche la machine de démarrer.
|
||||
# fws-intel-rst est appelé sur l'HÔTE, pas via in_target : il lit le
|
||||
# matériel, qui est le même depuis l'ISO que depuis le système installé.
|
||||
local nvram=""
|
||||
if [ -x /usr/local/bin/fws-intel-rst ]; then
|
||||
/usr/local/bin/fws-intel-rst --detect >/dev/null 2>&1
|
||||
case $? in 10|11|12)
|
||||
nvram="--no-nvram"
|
||||
say "Contrôleur Intel VMD/RST : pas d'entrée NVRAM, chemin de secours seul." ;;
|
||||
esac
|
||||
fi
|
||||
in_target grub-install --target=x86_64-efi \
|
||||
--efi-directory=/boot/efi --bootloader-id=FWS --recheck || true
|
||||
--efi-directory=/boot/efi --bootloader-id=FWS $nvram --recheck || true
|
||||
in_target grub-install --target=x86_64-efi \
|
||||
--efi-directory=/boot/efi --bootloader-id=FWS --removable --recheck
|
||||
else
|
||||
|
||||
@@ -394,9 +394,19 @@ install_grub() {
|
||||
echo "[FWS] aucune ESP accessible dans le chroot — le 1er démarrage finalisera GRUB"
|
||||
return 1
|
||||
fi
|
||||
# (a) Entrée NVRAM dédiée (best effort, si efibootmgr dispo) :
|
||||
# (a) Entrée NVRAM dédiée (best effort, si efibootmgr dispo) — SAUF sur
|
||||
# Intel VMD/RST : le chemin écrit depuis Linux vise un domaine PCI
|
||||
# que le firmware ne connaît pas (cf. fws-grub-finalize). Dans ce
|
||||
# chroot efivars est normalement inaccessible et l'écriture échoue
|
||||
# de toute façon ; --no-nvram garantit qu'un environnement où il le
|
||||
# serait ne casse pas dès le 1er démarrage.
|
||||
_nvram=""
|
||||
if [ -x /usr/local/bin/fws-intel-rst ]; then
|
||||
/usr/local/bin/fws-intel-rst --detect >/dev/null 2>&1
|
||||
case $? in 10|11|12) _nvram="--no-nvram" ;; esac
|
||||
fi
|
||||
grub-install --target=x86_64-efi --efi-directory=/boot/efi \
|
||||
--bootloader-id=FWS --recheck || true
|
||||
--bootloader-id=FWS $_nvram --recheck || true
|
||||
# (b) Chemin de SECOURS EFI/BOOT/BOOTX64.EFI (--removable) : boote SANS
|
||||
# aucune entrée NVRAM. INDISPENSABLE en VM / sans réseau / firmware
|
||||
# qui « oublie » l'entrée — c'est lui qui garantit le 1er boot UEFI.
|
||||
|
||||
Reference in new issue
Block a user