From b296a37d65a1680677ccd3ca46ff10c2c6785fe1 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 5 Aug 2026 04:43:37 +0200 Subject: [PATCH] fix: Use XML capability checks for image preparation (#2047) --- src/answer.sh | 2 +- src/define.sh | 12 +-- src/image.sh | 11 +-- src/install.sh | 234 ++++++++++++++++++++++++------------------------- 4 files changed, 129 insertions(+), 130 deletions(-) diff --git a/src/answer.sh b/src/answer.sh index 1b13c116..debda73a 100644 --- a/src/answer.sh +++ b/src/answer.sh @@ -131,7 +131,7 @@ hasAnswerFile() { return 1 } -stageAnswer() { +addAnswerFile() { local asset="$1" local language="$2" diff --git a/src/define.sh b/src/define.sh index 48c4d783..a85cd41c 100644 --- a/src/define.sh +++ b/src/define.sh @@ -938,7 +938,7 @@ isLegacy() { local id="$1" case "${id,,}" in - "win9"* | "win2k"* | "winxp"* | "win2003"* | \ + "win9"* | "winnt4"* | "win2k"* | "winxp"* | "win2003"* | \ "winvista"* | "win7"* | "win2008"* | "reactos" ) return 0 ;; esac @@ -946,24 +946,26 @@ isLegacy() { return 1 } -supportsXML() { +supportsUnattended() { local id="$1" case "${id,,}" in - "win9"* | "winxp"* | "win2k"* | "win2003"* | "reactos" ) + "win9"* | "winnt4"* | "reactos" ) return 1 ;; esac return 0 } -supportsUnattended() { +supportsXML() { local id="$1" + supportsUnattended "$id" || return 1 + case "${id,,}" in - "win9"* | "reactos" ) + "win2k"* | "winxp"* | "win2003"* ) return 1 ;; esac diff --git a/src/image.sh b/src/image.sh index 6ec6f465..48ccd535 100644 --- a/src/image.sh +++ b/src/image.sh @@ -614,14 +614,10 @@ canUseSetupImage() { local id="$1" local iso="$2" - # Legacy installers and ReactOS require modifying or directly booting their - # media. Standalone ESDs and nested archives are not directly bootable ISOs. - case "${id,,}" in - "win9"* | "winxp"* | "win2k"* | "win2003"* | "reactos" ) - return 1 ;; - esac + supportsXML "$id" || return 1 + [[ "${iso,,}" == *".esd" ]] && return 1 - [[ "${iso,,}" != *".esd" ]] && ! enabled "${UNPACK:-}" + return 0 } createImageDirectory() { @@ -1748,6 +1744,7 @@ buildImage() { desc=$(printVariant "$DETECTED" "ISO") local msg="Building $desc image" + [[ "${ISO,,}" == *.esd ]] && msg+=" from ESD file" info "$msg..." && html "$msg..." [ -z "$LABEL" ] && LABEL="Windows" diff --git a/src/install.sh b/src/install.sh index b63a4175..e78a5694 100644 --- a/src/install.sh +++ b/src/install.sh @@ -142,7 +142,7 @@ prepareWindowsImage() { # Prefer the original ISO with a small setup image whenever possible. if canUseSetupImage "$DETECTED" "$iso"; then - if ! stageSetup "$XML" "$LANGUAGE" "$TMP/setup"; then + if ! createOverlay "$XML" "$LANGUAGE" "$TMP/setup"; then skipUnattended "$dir" "$iso" "$boot" || return 84 handled=1 return 0 @@ -913,118 +913,6 @@ extractImage() { return 0 } -setMachine() { - - local id="$1" - local iso="$2" - local dir="$3" - local desc="$4" - - ETFS="boot/etfsboot.com" - - local version="" - case "${id,,}" in - "win2k"* ) version="2k" ;; - "winxp"* ) version="xp" ;; - "win2003"* ) version="2k3" ;; - esac - - if [ -n "$version" ]; then - - if ! legacyInstall "$iso" "$dir" "$desc" "$version"; then - error "Failed to prepare $desc ISO!" - return 1 - fi - - fi - - if isLegacy "$id"; then - - writeState "mode" "windows_legacy" || return 1 - - case "${id,,}" in - "win9"* | "win2k"* | "reactos" ) - writeState "vga" "cirrus" || return 1 ;; - * ) - writeState "vga" "std" || return 1 ;; - esac - - fi - - restoreBootMode || return 1 - - case "${id,,}" in - - "win9"* ) - - writeState "usb" "N" || return 1 - writeState "net" "pcnet" || return 1 - writeState "type" "auto" || return 1 - writeState "old" "pc-i440fx-2.4" || return 1 ;; - - "win2k"* ) - - writeState "old" "pc" || return 1 - writeState "type" "auto" || return 1 - writeState "net" "rtl8139" || return 1 - writeState "usb" "pci-ohci" || return 1 ;; - - "winxpx"* | "win2003"* ) - - writeState "type" "blk" || return 1 - writeState "net" "rtl8139" || return 1 - writeState "sound" "usb-audio" || return 1 ;; - - "reactos" ) - - writeState "old" "pc" || return 1 - writeState "type" "auto" || return 1 - writeState "net" "rtl8139" || return 1 - writeState "usb" "pci-ohci" || return 1 ;; - - esac - - if [[ "${id,,}" == "reactos" ]] && [ -z "$CUSTOM" ]; then - # The ISO is a Live-CD so we need to disable the data disk - # as it will be always wiped during the next runs currently. - REMOVE="N" - DISK_DISABLE="Y" - fi - - restoreMachine || return 1 - - case "${id,,}" in - - "win9"* | "win2k"* | *"x86"* | "reactos" ) - - # Legacy 32-bit Windows may enter an incompatible PAE/DEP path when the - # NX flag is exposed, causing installation failures or repeated resets. - - writeState "flag" "nx=off" || return 1 ;; - - esac - - case "${id,,}" in - - "win9"* | "win2k"* | "winxp"* | "win2003"* | \ - "winvistax86"* | "win7x86"* | "reactos" ) - - if isQ35 "$MACHINE"; then - - # pc-q35-2.11 began advertising a synthetic 64-bit PCI MMIO aperture. - # Older Windows ACPI implementations may reject that resource layout, - # so retain the pre-2.11 behavior for these guests to prevent a - # blue screen on XP and others if the 64 bit PCI hole size is >2G. - - writeState "args" "-global q35-pcihost.x-pci-hole64-fix=false" || return 1 - - fi ;; - - esac - - return 0 -} - prepareImage() { local iso="$1" @@ -1318,13 +1206,13 @@ addDrivers() { return 0 } -stageSetup() { +createOverlay() { local asset="$1" local language="$2" local stage="$3" - supportsUnattended "${DETECTED,,}" || return 0 + supportsXML "${DETECTED,,}" || return 0 local msg="Creating overlay image..." info "$msg" && html "$msg" @@ -1349,7 +1237,7 @@ stageSetup() { return 1 fi - stageAnswer "$asset" "$language" "$stage" || return 1 + addAnswerFile "$asset" "$language" "$stage" || return 1 return 0 } @@ -1367,7 +1255,7 @@ updateImage() { local dat="${xml//.xml/.dat}" local desc path src wim name info - supportsUnattended "${DETECTED,,}" || return 0 + supportsXML "${DETECTED,,}" || return 0 if [ ! -s "$asset" ] || [ ! -f "$asset" ]; then asset="" @@ -1656,6 +1544,118 @@ restoreMachineState() { return 0 } +setMachine() { + + local id="$1" + local iso="$2" + local dir="$3" + local desc="$4" + + ETFS="boot/etfsboot.com" + + local version="" + case "${id,,}" in + "win2k"* ) version="2k" ;; + "winxp"* ) version="xp" ;; + "win2003"* ) version="2k3" ;; + esac + + if [ -n "$version" ]; then + + if ! legacyInstall "$iso" "$dir" "$desc" "$version"; then + error "Failed to prepare $desc ISO!" + return 1 + fi + + fi + + if isLegacy "$id"; then + + writeState "mode" "windows_legacy" || return 1 + + case "${id,,}" in + "win9"* | "win2k"* | "reactos" ) + writeState "vga" "cirrus" || return 1 ;; + * ) + writeState "vga" "std" || return 1 ;; + esac + + fi + + restoreBootMode || return 1 + + case "${id,,}" in + + "win9"* ) + + writeState "usb" "N" || return 1 + writeState "net" "pcnet" || return 1 + writeState "type" "auto" || return 1 + writeState "old" "pc-i440fx-2.4" || return 1 ;; + + "win2k"* ) + + writeState "old" "pc" || return 1 + writeState "type" "auto" || return 1 + writeState "net" "rtl8139" || return 1 + writeState "usb" "pci-ohci" || return 1 ;; + + "winxpx"* | "win2003"* ) + + writeState "type" "blk" || return 1 + writeState "net" "rtl8139" || return 1 + writeState "sound" "usb-audio" || return 1 ;; + + "reactos" ) + + writeState "old" "pc" || return 1 + writeState "type" "auto" || return 1 + writeState "net" "rtl8139" || return 1 + writeState "usb" "pci-ohci" || return 1 ;; + + esac + + if [[ "${id,,}" == "reactos" ]] && [ -z "$CUSTOM" ]; then + # The ISO is a Live-CD so we need to disable the data disk + # as it will be always wiped during the next runs currently. + REMOVE="N" + DISK_DISABLE="Y" + fi + + restoreMachine || return 1 + + case "${id,,}" in + + "win9"* | "win2k"* | *"x86"* | "reactos" ) + + # Legacy 32-bit Windows may enter an incompatible PAE/DEP path when the + # NX flag is exposed, causing installation failures or repeated resets. + + writeState "flag" "nx=off" || return 1 ;; + + esac + + case "${id,,}" in + + "win9"* | "win2k"* | "winxp"* | "win2003"* | \ + "winvistax86"* | "win7x86"* | "reactos" ) + + if isQ35 "$MACHINE"; then + + # pc-q35-2.11 began advertising a synthetic 64-bit PCI MMIO aperture. + # Older Windows ACPI implementations may reject that resource layout, + # so retain the pre-2.11 behavior for these guests to prevent a + # blue screen on XP and others if the 64 bit PCI hole size is >2G. + + writeState "args" "-global q35-pcihost.x-pci-hole64-fix=false" || return 1 + + fi ;; + + esac + + return 0 +} + startWindows return 0