#!/bin/bash # win-ci Windows VM 기동 (.9 안 중첩 KVM) # # 이 스크립트를 직접 실행하지 말 것. start-vm.sh 가 systemd 트랜지언트 유닛으로 # 띄운다. 에이전트 턴에서 그냥 qemu 를 띄우면 ejclaw.service 의 cgroup 안에서 # 돌아 MemoryHigh=16G 상한을 쳐서 봇이 OOM 으로 죽는다 (2026-07-26 전례). set -euo pipefail D=/home/claude/win-ci cd "$D" # TPM 2.0 - Windows 11 요구사항 if [ ! -S "$D/swtpm/sock" ]; then swtpm socket --tpmstate "dir=$D/swtpm" \ --ctrl "type=unixio,path=$D/swtpm/sock" --tpm2 -d for i in $(seq 1 20); do [ -S "$D/swtpm/sock" ] && break; sleep 0.3; done fi rm -f "$D/qmp.sock" # 설치가 끝나면 Windows ISO(4.8GB)는 필요 없어서 지운다. 그래도 유닛이 뜨도록 # 없는 ISO 는 그냥 건너뛴다. 없는 파일을 -drive 로 주면 qemu 가 기동에 실패해 # 재부팅 후 러너 호스트가 조용히 사라진다. CDROMS=() add_cd() { # 파일 버스 [bootindex] [ -f "$1" ] || { echo "cdrom 건너뜀 (없음): $1" >&2; return; } local id="cd$(basename "$1" | tr -cd 'a-z0-9')" CDROMS+=( -drive "file=$1,if=none,id=$id,media=cdrom,readonly=on" ) if [ -n "${3:-}" ]; then CDROMS+=( -device "ide-cd,drive=$id,bus=$2,bootindex=$3" ) else CDROMS+=( -device "ide-cd,drive=$id,bus=$2" ) fi } add_cd "$D/iso/win11-ltsc.iso" ide.1 1 add_cd "$D/iso/virtio-win.iso" ide.2 add_cd "$D/unattend.iso" ide.3 exec qemu-system-x86_64 \ -name win-ci,process=win-ci \ -machine q35,smm=on,vmport=off \ -accel kvm \ -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \ -smp 4,sockets=1,cores=4,threads=1 \ -m 8192 \ -rtc base=localtime,driftfix=slew \ -global driver=cfi.pflash01,property=secure,value=on \ -global ICH9-LPC.disable_s3=1 \ -drive if=pflash,format=raw,unit=0,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.secboot.fd \ -drive if=pflash,format=raw,unit=1,file="$D/OVMF_VARS.fd" \ -chardev "socket,id=chrtpm,path=$D/swtpm/sock" \ -tpmdev emulator,id=tpm0,chardev=chrtpm \ -device tpm-tis,tpmdev=tpm0 \ -device virtio-vga,max_outputs=2,xres=1920,yres=1080 \ -audiodev none,id=aud0 \ -device intel-hda \ -device hda-duplex,audiodev=aud0 \ -netdev user,id=net0,hostfwd=tcp:127.0.0.1:13389-:3389 \ -device virtio-net-pci,netdev=net0 \ -device qemu-xhci,id=xhci \ -device usb-kbd -device usb-tablet \ -drive "file=$D/win-ci.qcow2,if=none,id=sysdisk,format=qcow2,cache=writeback,discard=unmap,aio=threads" \ -device ide-hd,drive=sysdisk,bus=ide.0,bootindex=2 \ "${CDROMS[@]}" \ -serial "file:$D/serial.log" \ -qmp "unix:$D/qmp.sock,server=on,wait=off" \ -vnc 127.0.0.1:19 \ -boot menu=off,strict=on