Add --window option to build-windows-base.sh

Show the guest in a QEMU window instead of the VNC display.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
GuofangandClaude Sonnet 5.5 committed 2026-11-02 10:05:55 +08:00
1 parent 71c0c3d029
commit 1dc40655df
1 file changed
+18 -4
+18 -4
View File
@@ -19,7 +19,7 @@
# SSH_PRIVATE_KEY_FILE for this script).
#
# Usage: build-windows-base.sh [--force] [--no-sysprep] [--keep-work] [--compress]
# [--ssh-port PORT] [OUTPUT.qcow2]
# [--window] [--ssh-port PORT] [OUTPUT.qcow2]
# OUTPUT defaults to the path that "download-images.sh --print-path windows11"
# prints, which is where run-windows11.py looks for the base image.
set -euo pipefail
@@ -32,7 +32,7 @@ downloader="${images_dir}/download-images.sh"
usage() {
cat <<EOF
Usage: $(basename "$0") [--force] [--no-sysprep] [--keep-work] [--compress]
[--ssh-port PORT] [OUTPUT.qcow2]
[--window] [--ssh-port PORT] [OUTPUT.qcow2]
Install Windows 11 from the ISO, generalize it with sysprep and store the disk
as the read-only base image that run-windows11.py clones.
@@ -42,6 +42,8 @@ as the read-only base image that run-windows11.py clones.
the machine SID and host name (fine for stand-alone VMs)
--keep-work Keep the scratch state directory (also kept on failure)
--compress Compress the output (smaller, but clones read it slower)
--window Show the guest in a QEMU window (needs a desktop session)
instead of the VNC display on 127.0.0.1:5990
--ssh-port PORT Host port forwarded to the guest's SSH during the build
(default: 2299; overrides BASE_BUILD_SSH_PORT)
-h, --help Show this help
@@ -65,6 +67,7 @@ force=0
sysprep=1
keep_work=0
compress=0
window=0
ssh_port="${BASE_BUILD_SSH_PORT:-2299}"
output=""
while (($#)); do
@@ -74,6 +77,7 @@ while (($#)); do
--no-sysprep) sysprep=0 ;;
--keep-work) keep_work=1 ;;
--compress) compress=1 ;;
--window) window=1 ;;
--ssh-port) shift; ssh_port="${1:?--ssh-port needs a value}" ;;
--ssh-port=*) ssh_port="${1#*=}" ;;
-*) usage >&2; exit 2 ;;
@@ -151,11 +155,21 @@ wait_for() {
printf 'SSH %s 22\n' "$ssh_port" >"${work}/forwards.conf"
step "Installing Windows 11 from the ISO (unattended; takes a while)"
display_option=(--vnc=127.0.0.1:90)
if ((window)); then
[[ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" || "$(uname -s)" == Darwin ]] \
|| die "--window needs a desktop session (DISPLAY or WAYLAND_DISPLAY is not set)."
display_option=()
fi
WIN11_VM_FORWARDS="${work}/forwards.conf" "$launcher" \
--daemon --vnc=127.0.0.1:90 --install-from-iso --arch "$arch" --state-dir "$work"
--daemon "${display_option[@]}" --install-from-iso --arch "$arch" --state-dir "$work"
step "Waiting for the guest to finish its first-logon setup (SSH answers)"
note "Screen: VNC 127.0.0.1:5990; console log: ${work}/console.log"
if ((window)); then
note "Screen: QEMU window; console log: ${work}/console.log"
else
note "Screen: VNC 127.0.0.1:5990; console log: ${work}/console.log"
fi
if ! wait_for "${BASE_BUILD_TIMEOUT:-5400}" guest_ssh 'echo ready' >/dev/null 2>&1; then
die "SSH did not answer in time; inspect the guest over VNC."
fi