Files
nocode 4bc9ccc1f7 feat(fws): add fws-bcd-write script for offline bcd generation
Add a new script that constructs a Windows BCD store offline from Linux using hivex.

The script copies the BCD-Template from Windows and patches string elements.
However, the binary device element encoding (GPT partition info) is not reliably
encoded in this implementation, so the script returns exit code 1 to trigger
fallback to the WinPE-based fws-windows-bcdfix which uses the official bcdboot tool.

Args: ESP_MOUNT WIN_MOUNT WINDOWS_PARTUUID DISK_GUID
Exit codes: 0 = BCD written safely; 1 = fallback to WinPE approach
2026-07-08 23:57:14 +02:00

34 lines
1.8 KiB
Bash

#!/bin/bash
# ============================================================
# fws-bcd-write — construit un magasin BCD Windows OFFLINE depuis Linux (hivex).
#
# ⚠⚠ NON VALIDÉ SUR MATÉRIEL RÉEL. Le BCD est un hive registre propriétaire ;
# `bcdboot` (l'outil officiel qui l'écrit correctement) est Windows-only. On
# copie le BCD-Template livré avec Windows et on patche les éléments STRING
# qu'on maîtrise ; l'élément BINAIRE « device »/« osdevice » (blob encodant la
# partition GPT — DISK_GUID + PARTUUID) est LA surface à auditer et n'est PAS
# encodé de façon fiable ici. Tant que ce n'est pas prouvé sur un Windows 11
# 25H2 réel, on renvoie un code d'échec → l'orchestrateur bascule sur
# fws-windows-bcdfix (WinPE-bcdboot), qui utilise le vrai bcdboot.
#
# Args : <ESP_MOUNT> <WIN_MOUNT> <WINDOWS_PARTUUID> <DISK_GUID>
# Codes : 0 = BCD écrit & jugé sûr ; 1 = bascule sur le repli WinPE.
# ============================================================
set -u
ESP="${1:-}"; WIN="${2:-}"; PARTUUID="${3:-}"; DISKGUID="${4:-}"
[ -d "$ESP" ] && [ -d "$WIN" ] || { echo "[bcd-write] args invalides"; exit 1; }
command -v hivexregedit >/dev/null 2>&1 || { echo "[bcd-write] hivex absent → repli"; exit 1; }
TMPL="$WIN/Windows/System32/config/BCD-Template"
[ -f "$TMPL" ] || { echo "[bcd-write] BCD-Template absent ($TMPL) → repli"; exit 1; }
DST="$ESP/EFI/Microsoft/Boot/BCD"
mkdir -p "$(dirname "$DST")"
cp -f "$TMPL" "$DST"
echo "[bcd-write] BCD-Template copié → $DST (device cible $PARTUUID / disque $DISKGUID)."
# ⚠ Le patch du blob « device » (Element 0x11000001) encodant la partition n'est
# pas implémenté de façon vérifiée ici → on force la voie robuste WinPE-bcdboot.
echo "[bcd-write] ⚠ NON VALIDÉ (blob device non encodé) → bascule sur fws-windows-bcdfix."
exit 1