mirror of
https://github.com/dockur/windows.git
synced 2026-07-28 21:53:34 +07:00
fix: Persistence of automatic Windows machine settings (#2009)
This commit is contained in:
+142
-86
@@ -329,55 +329,31 @@ finishInstall() {
|
||||
|
||||
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
||||
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
||||
|
||||
writeState "mode" "$BOOT_MODE" || return 1
|
||||
if [[ "${MACHINE,,}" != "q35" ]]; then
|
||||
writeState "old" "$MACHINE" || return 1
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
local secure=""
|
||||
|
||||
# Enable secure boot + TPM on manual installs as Win11 requires
|
||||
if enabled "$MANUAL" || [[ "$aborted" == [Yy1]* ]]; then
|
||||
if [[ "${DETECTED,,}" == "win11"* ]]; then
|
||||
BOOT_MODE="windows_secure"
|
||||
writeState "mode" "$BOOT_MODE" || return 1
|
||||
fi
|
||||
[[ "${DETECTED,,}" == "win11"* ]] && secure="Y"
|
||||
fi
|
||||
|
||||
# Enable secure boot on multi-socket systems to workaround freeze
|
||||
if [ -n "$SOCKETS" ] && [[ "$SOCKETS" != "1" ]]; then
|
||||
secure="Y"
|
||||
fi
|
||||
|
||||
if [ -n "$secure" ]; then
|
||||
BOOT_MODE="windows_secure"
|
||||
writeState "mode" "$BOOT_MODE" || return 1
|
||||
fi
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${ARGS:-}" ]; then
|
||||
ARGUMENTS="$ARGS ${ARGUMENTS:-}"
|
||||
writeState "args" "$ARGS" || return 1
|
||||
fi
|
||||
|
||||
if [ -n "${VGA:-}" ] && [[ "${VGA:-}" != "virtio"* ]]; then
|
||||
writeState "vga" "$VGA" || return 1
|
||||
fi
|
||||
|
||||
if [ -n "${USB:-}" ] && [[ "${USB:-}" != "qemu-xhci"* ]]; then
|
||||
writeState "usb" "$USB" || return 1
|
||||
fi
|
||||
|
||||
if [ -n "${DISK_TYPE:-}" ] && [[ "${DISK_TYPE:-}" != "scsi" ]]; then
|
||||
writeState "type" "$DISK_TYPE" || return 1
|
||||
fi
|
||||
|
||||
if [ -n "${ADAPTER:-}" ] && [[ "${ADAPTER:-}" != "virtio-net-pci" ]]; then
|
||||
writeState "net" "$ADAPTER" || return 1
|
||||
fi
|
||||
|
||||
if [ -n "${SOUND:-}" ] && [[ "${SOUND:-}" != "intel-hda" ]]; then
|
||||
writeState "sound" "$SOUND" || return 1
|
||||
fi
|
||||
|
||||
if [ -n "${CPU_MODEL:-}" ] && [[ "${CPU_MODEL,,}" != "host" ]]; then
|
||||
writeState "cpu" "$CPU_MODEL" || return 1
|
||||
fi
|
||||
|
||||
rm -rf "$TMP"
|
||||
return 0
|
||||
}
|
||||
@@ -401,7 +377,10 @@ abortInstall() {
|
||||
|
||||
if [ -z "$efi" ] ||
|
||||
{ [ -n "$efi32" ] && [ -z "$efi64" ]; }; then
|
||||
BOOT_MODE="windows_legacy"
|
||||
|
||||
writeState "mode" "windows_legacy" || return 1
|
||||
restoreBootMode || return 1
|
||||
|
||||
fi
|
||||
|
||||
fi
|
||||
@@ -736,59 +715,80 @@ setMachine() {
|
||||
|
||||
"win9"* | "win2k"* | "winxp"* | "win2003"* | \
|
||||
"winvista"* | "win7"* | "win2008"* | "reactos" )
|
||||
BOOT_MODE="windows_legacy" ;;
|
||||
|
||||
writeState "mode" "windows_legacy" || return 1 ;;
|
||||
|
||||
esac
|
||||
|
||||
restoreBootMode || return 1
|
||||
|
||||
case "${id,,}" in
|
||||
|
||||
"win9"* )
|
||||
isQ35 && MACHINE="pc-i440fx-2.4"
|
||||
[ -z "${USB:-}" ] && USB="no"
|
||||
[ -z "${VGA:-}" ] && VGA="cirrus"
|
||||
[ -z "${ADAPTER:-}" ] && ADAPTER="pcnet"
|
||||
[ -z "${DISK_TYPE:-}" ] && DISK_TYPE="auto" ;;
|
||||
|
||||
writeState "usb" "no" || return 1
|
||||
writeState "net" "pcnet" || return 1
|
||||
writeState "type" "auto" || return 1
|
||||
writeState "vga" "cirrus" || return 1
|
||||
writeState "old" "pc-i440fx-2.4" || return 1 ;;
|
||||
|
||||
"win2k"* )
|
||||
isQ35 && MACHINE="pc"
|
||||
[ -z "${VGA:-}" ] && VGA="cirrus"
|
||||
[ -z "${USB:-}" ] && USB="pci-ohci"
|
||||
[ -z "${ADAPTER:-}" ] && ADAPTER="rtl8139"
|
||||
[ -z "${DISK_TYPE:-}" ] && DISK_TYPE="auto" ;;
|
||||
|
||||
"winxp"* | "win2003"* )
|
||||
[ -z "${SOUND:-}" ] && SOUND="usb-audio"
|
||||
[ -z "${DISK_TYPE:-}" ] && DISK_TYPE="blk" ;;
|
||||
writeState "old" "pc" || return 1
|
||||
writeState "vga" "cirrus" || return 1
|
||||
writeState "type" "auto" || return 1
|
||||
writeState "net" "rtl8139" || return 1
|
||||
writeState "usb" "pci-ohci" || return 1 ;;
|
||||
|
||||
"winxpx86"* )
|
||||
|
||||
writeState "type" "blk" || return 1
|
||||
writeState "net" "rtl8139" || return 1
|
||||
writeState "sound" "usb-audio" || return 1 ;;
|
||||
|
||||
"winxpx64"* | "win2003"* )
|
||||
|
||||
writeState "type" "blk" || return 1
|
||||
writeState "sound" "usb-audio" || return 1 ;;
|
||||
|
||||
"reactos" )
|
||||
isQ35 && MACHINE="pc"
|
||||
[ -z "${VGA:-}" ] && VGA="cirrus"
|
||||
|
||||
[ -z "${REMOVE:-}" ] && REMOVE="N"
|
||||
[ -z "${USB:-}" ] && USB="pci-ohci"
|
||||
[ -z "${REBUILD:-}" ] && REBUILD="N"
|
||||
[ -z "${ADAPTER:-}" ] && ADAPTER="rtl8139"
|
||||
[ -z "${DISK_TYPE:-}" ] && DISK_TYPE="auto" ;;
|
||||
|
||||
writeState "old" "pc" || return 1
|
||||
writeState "type" "auto" || return 1
|
||||
writeState "vga" "cirrus" || return 1
|
||||
writeState "net" "rtl8139" || return 1
|
||||
writeState "usb" "pci-ohci" || return 1 ;;
|
||||
|
||||
esac
|
||||
|
||||
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
|
||||
|
||||
"winvistax86"* | "win7x86"* )
|
||||
"win9"* | "win2k"* | "winxp"* | "win2003"* | "reactos" )
|
||||
|
||||
# Fix boot loop issue on AMD EPYC processors
|
||||
[ -z "${CPU_MODEL:-}" ] && CPU_MODEL="qemu32" ;;
|
||||
if isQ35 "$MACHINE"; then
|
||||
|
||||
esac
|
||||
# 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.
|
||||
|
||||
case "${id,,}" in
|
||||
|
||||
"winxp"* | "win2003"* | "winvistax86"* | \
|
||||
"win7x86"* | "win2008r2x86"* | "reactos")
|
||||
|
||||
if isQ35 "${MACHINE:-q35}"; then
|
||||
|
||||
# Prevent bluescreen if 64 bit PCI hole size is >2G.
|
||||
ARGS="-global q35-pcihost.x-pci-hole64-fix=false"
|
||||
writeState "args" "-global q35-pcihost.x-pci-hole64-fix=false" || return 1
|
||||
|
||||
fi ;;
|
||||
|
||||
@@ -807,6 +807,7 @@ prepareImage() {
|
||||
|
||||
# Adjust QEMU machine configuration for legacy versions
|
||||
setMachine "$DETECTED" "$iso" "$dir" "$desc" || return 1
|
||||
restoreMachineState || return 1
|
||||
|
||||
disabled "$REBUILD" && return 0
|
||||
|
||||
@@ -1160,25 +1161,80 @@ removeImage() {
|
||||
return 0
|
||||
}
|
||||
|
||||
mergeState() {
|
||||
|
||||
local var="$1"
|
||||
local name="$2"
|
||||
local separator="${3:-,}"
|
||||
local prefix="${4:-$PROCESS}"
|
||||
local current="${!var:-}"
|
||||
local value
|
||||
|
||||
value=$(readState "$name" "$prefix") || return 1
|
||||
[ -n "$value" ] || return 0
|
||||
|
||||
if [ -n "$current" ]; then
|
||||
value="$current$separator$value"
|
||||
fi
|
||||
|
||||
printf -v "$var" '%s' "$value" || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
restoreBootMode() {
|
||||
|
||||
local current="${BOOT_MODE:-}"
|
||||
|
||||
local mode
|
||||
mode=$(readState "mode") || return 1
|
||||
|
||||
[ -n "$mode" ] || return 0
|
||||
|
||||
if [[ "${mode,,}" == "windows_legacy" ]]; then
|
||||
BOOT_MODE="$mode"
|
||||
return 0
|
||||
fi
|
||||
|
||||
case "${current,,}" in
|
||||
"" | "windows" | "windows_plain" )
|
||||
BOOT_MODE="$mode" ;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
restoreMachine() {
|
||||
|
||||
[[ "${PLATFORM,,}" != "x64" ]] && return 0
|
||||
[[ "${MACHINE,,}" != "q35" ]] && return 0
|
||||
|
||||
MACHINE=""
|
||||
restoreState "MACHINE" "old" || return 1
|
||||
[ -z "$MACHINE" ] && MACHINE="q35"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
restoreMachineState() {
|
||||
|
||||
restoreState "VGA" "vga" || return 1
|
||||
restoreState "USB" "usb" || return 1
|
||||
restoreState "SOUND" "sound" || return 1
|
||||
restoreState "ADAPTER" "net" || return 1
|
||||
restoreState "CPU_MODEL" "cpu" || return 1
|
||||
restoreState "DISK_TYPE" "type" || return 1
|
||||
|
||||
mergeState "CPU_FLAGS" "flag" "," || return 1
|
||||
mergeState "ARGUMENTS" "args" " " || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
bootWindows() {
|
||||
|
||||
ARGS=$(readState "$STORAGE/windows.args") || return 1
|
||||
|
||||
if [ -n "$ARGS" ]; then
|
||||
ARGUMENTS="$ARGS ${ARGUMENTS:-}"
|
||||
fi
|
||||
|
||||
restoreState "VGA" "$STORAGE/windows.vga" || return 1
|
||||
restoreState "USB" "$STORAGE/windows.usb" || return 1
|
||||
restoreState "SOUND" "$STORAGE/windows.sound" || return 1
|
||||
restoreState "ADAPTER" "$STORAGE/windows.net" || return 1
|
||||
restoreState "CPU_MODEL" "$STORAGE/windows.cpu" || return 1
|
||||
restoreState "DISK_TYPE" "$STORAGE/windows.type" || return 1
|
||||
restoreState "BOOT_MODE" "$STORAGE/windows.mode" "Y" || return 1
|
||||
|
||||
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
||||
restoreState "MACHINE" "$STORAGE/windows.old" "Y" || return 1
|
||||
fi
|
||||
restoreMachineState || return 1
|
||||
restoreBootMode || return 1
|
||||
restoreMachine || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user