fix: Improve Windows boot key timing (#2113)

This commit is contained in:
Kroese
2026-08-08 06:27:10 +02:00
committed by GitHub
parent eb2207dff9
commit 6c4e167915
2 changed files with 30 additions and 29 deletions
+5 -5
View File
@@ -658,6 +658,11 @@ needsExtraction() {
local id="$1" local id="$1"
local iso="$2" local iso="$2"
# Nested archives must be extracted to expose their contained ISO.
if enabled "${UNPACK:-}"; then
return 0
fi
# Media without unattended support boots directly from the original ISO. # Media without unattended support boots directly from the original ISO.
if ! supportsUnattended "$id"; then if ! supportsUnattended "$id"; then
return 1 return 1
@@ -673,11 +678,6 @@ needsExtraction() {
return 0 return 0
fi fi
# Nested archives must be extracted to expose their contained ISO.
if enabled "${UNPACK:-}"; then
return 0
fi
# Modern bootable ISOs can use the original media with a setup overlay. # Modern bootable ISOs can use the original media with a setup overlay.
return 1 return 1
} }
+24 -23
View File
@@ -108,31 +108,42 @@ waitForBoot() {
local pid="$1" local pid="$1"
local timeout="${2:-30}" local timeout="${2:-30}"
local keySent=0 local keySent=0
local keyWait=0
local pendingType=0 local pendingType=0
local pendingLine="" local pendingLine=""
local pendingDeadline=0 local pendingDeadline=0
local keyDelay status marker local status marker
local deadline=$((SECONDS + timeout)) local deadline=$((SECONDS + timeout))
local screen="visit http://127.0.0.1:$WEB_PORT/ to view the screen..." local screen="visit http://127.0.0.1:$WEB_PORT/ to view the screen..."
while isAlive "$pid"; do while isAlive "$pid"; do
# Send the boot key once, either immediately after the prompt appears or # The boot prompt is only an opportunistic early trigger because some
# shortly after firmware starts the DVD when the prompt is not logged. # Windows versions do not expose it on the PTY until much later.
if (( ! keySent )) && needsBootKey; then if (( ! keySent )) && needsBootKey; then
if keyDelay=$(bootKeyDelay); then if [ -s "$QEMU_PTY" ] && grep -Fq "Press any key to" "$QEMU_PTY"; then
if [[ "$keyDelay" == "0" ]]; then
if sendKey spc 0 500; then if sendKey spc 0 500; then
keySent=1 keySent=1
fi fi
else elif bootKeyReady; then
if sendKey spc "$keyDelay" 250 4 0.75; then (( keyWait += 1 ))
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
# Keep the legacy fallback at about one second after the DVD marker.
if (( keyWait >= 5 )); then
if sendKey spc 0 100 6 0.25; then
keySent=1 keySent=1
fi fi
fi fi
elif (( keyWait >= 1 )); then
# Modern Windows usually needs blind timing, so start earlier.
if sendKey spc 0 100 6 0.25; then
keySent=1
fi
fi
else
keyWait=0
fi fi
fi fi
@@ -347,26 +358,16 @@ needsBootKey() {
supportsBootKey "$DETECTED" supportsBootKey "$DETECTED"
} }
bootKeyDelay() { bootKeyReady() {
[ ! -s "$QEMU_PTY" ] && return 1 [ ! -s "$QEMU_PTY" ] && return 1
# A visible prompt is the safest trigger and should be answered immediately.
if grep -Fq "Press any key to" "$QEMU_PTY"; then
echo 0
return 0
fi
# Some firmware or Windows versions do not log the prompt. In that case wait
# briefly after the DVD boot attempt and send several short key presses.
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
grep -Fq "Booting from DVD/CD" "$QEMU_PTY" || return 1 grep -Fq "Booting from DVD/CD" "$QEMU_PTY"
else return $?
grep -Eq "$UEFI_DVD_BOOT_PATTERN" "$QEMU_PTY" || return 1
fi fi
echo 0.5 grep -Eq "$UEFI_DVD_BOOT_PATTERN" "$QEMU_PTY"
return 0
} }
getBootMarker() { getBootMarker() {