Files
windows-unattend/QUICKSTART.md
Timmy c84e18bd9d 新增 Setup.ps1(13 段 post-install);FirstLogonCommands 改從 Ventoy USB 拷腳本
把分散在 unattend.xml inline 的網路相依步驟(OpenSSH/Telegram/RemoveAI)和
新加入的 10 個 post-install 動作整合進獨立的 Setup.ps1,由 FirstLogonCommands
Order 4 從 Ventoy USB(/ventoy/script/Setup.ps1)掃磁碟複製到 C:\Scripts\,
Order 5 執行。腳本分兩 phase:

Phase 1(不需網路):SSH 22 防火牆、RDP+3389、ICMP Echo、WinRM TrustedHosts=*、
移 OneDrive、關 Cortana/WebSearch、套 UI/IME 預設到 Default profile、user→User
改名 + 從登入畫面隱藏 Admin。

Phase 2(要網路,wait-network 後):OpenSSH Server FoD、KMS 啟用(先試
$InternalKmsServers 後 fallback 公開 KMS)、winget Chrome、RemoveWindowsAI、
Win11Debloat、22 個 UWP 移除、Telegram、刪 Panther 殘留。

每段以 Section 包裝寫獨立 START/DONE/ERR 到 C:\Windows\Temp\setup.log,方便逐段
重跑與排查。

文件全部同步:DEPLOY/QUICKSTART/SUMMARY/README/CLAUDE 都加上 Setup.ps1 的
USB 部署、cp 步驟、Order 表、排查指引。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:36:13 +08:00

200 lines
10 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# QUICKSTART — 從零到自動安裝 Windows
照著做一次就能跑出一個「Ventoy 開機 → 選 ISO → 自動裝完 Windows → 自動登入 → 跑 Setup.ps1 → 重開機」的流程。
> 預設情境x64、UEFI+GPT、繁體中文、**Ventoy USB**[ventoy.net](https://www.ventoy.net/))載入多個 ISO。
---
## 0. 事前準備
需要準備:
- [ ] Windows 10 或 11 官方 ISO從 [microsoft.com](https://www.microsoft.com/software-download) 取得)
- [ ] 已刷好 Ventoy 的 USB 隨身碟(≥ 16 GB 建議,因為會同時放 ISO 與 script
- [ ] 一台測試機或 VM強烈建議先在 VM 驗證)
- [ ] 本專案的 `unattend.xml``Setup.ps1``ventoy.json`
**編輯 `unattend.xml` 的必改項目:**
| 行為 | 原值 | 要改成 |
|---|---|---|
| 產品序號 | Win11/10 Pro GVLK`W269N-WFGWX-...` | 你的序號,或留 GVLK 用 KMS或整個 `<ProductKey>` 節點刪掉 |
| 管理員密碼 | `P@ssw0rd!`(兩處:`LocalAccount``AutoLogon` | 你的密碼 |
| 組織名 | `YourCompany` | 你的組織 |
| `DiskID` | `$$VT_WINDOWS_DISK_1ST_NONVTOY$$`Ventoy 變數) | **保留不動**。Ventoy 會在執行期替換成「第一顆非 Ventoy USB 的磁碟」 |
**編輯 `Setup.ps1` 的常改項目(在檔案頂部):**
| 變數 | 預設 | 要改成 |
|---|---|---|
| `$InternalKmsServers` | `@()` 空陣列 | 你內網 KMS 主機,例:`@('kms.your-corp.com')`;空陣列就 fallback 到公開 KMS |
| `$UwpRemoveList` | 22 個 Microsoft 預載 app | 想多移/少移就改這個陣列 |
| `$Win11DebloatConfigJson` | toolkit 的預設(暗色、工作列靠左、停 Bing/Copilot/Recall… | 不喜歡哪個 tweak 就把該行 `Value` 改成 `false` |
**編輯 `ventoy.json` 的必改項目:**
| 欄位 | 原值 | 要改成 |
|---|---|---|
| `image` | `/Win11.iso` | USB 上實際的 ISO 路徑(相對 USB 根目錄,開頭要有 `/` |
---
## 1. 佈置 Ventoy USB
假設 Ventoy 已刷好(若還沒,從 [ventoy.net](https://www.ventoy.net/) 下載 `Ventoy2Disk` 跑一次即可。Ventoy USB 通常有兩個分割區,資料分割區掛上後會是一個大容量 exFAT/NTFS 碟。
把檔案放到 Ventoy 資料分割區:
```
<Ventoy USB 根目錄>/
├── Win11.iso ← 你的 Windows ISO檔名要對上 ventoy.json 的 image
└── ventoy/
├── ventoy.json ← 本 repo 的 ventoy.json
└── script/
├── unattend.xml ← 本 repo 的 unattend.xml改完的
└── Setup.ps1 ← 本 repo 的 Setup.ps1首次登入會被自動複製到 C:\Scripts\
```
macOS / Linux 範例:
```bash
# 假設 Ventoy 資料分割區掛在 /Volumes/Ventoy
cp Windows.iso /Volumes/Ventoy/Win11.iso
mkdir -p /Volumes/Ventoy/ventoy/script
cp ventoy.json /Volumes/Ventoy/ventoy/ventoy.json
cp unattend.xml /Volumes/Ventoy/ventoy/script/unattend.xml
cp Setup.ps1 /Volumes/Ventoy/ventoy/script/Setup.ps1
```
> **改 `Setup.ps1` 後記得重 `cp`**。`unattend.xml` 的 FirstLogonCommands 從 USB 上的 `/ventoy/script/Setup.ps1` 抓檔案,不是從 repo。沒同步的話部署到的 Windows 會跑舊版。
> 不用改名成 `autounattend.xml`,也不用把 XML 塞進 ISO 根目錄。Ventoy 的 Auto Install plugin 會在開機時依 `ventoy.json` 把 XML 注入給 Windows Setup。
**多個 ISO / 多套範本**`ventoy.json``auto_install` 是陣列,每個 ISO 一條目;`template` 也可以是陣列,開機時 Ventoy 會顯示選單讓你挑。
**選單上的提示文字**`ventoy.json` 可加一個 `menu_tip` 區塊,光標停在某個 ISO 時,畫面下方會顯示該 ISO 對應的一行說明([Ventoy 文件](https://www.ventoy.net/en/plugin_menutip.html))。本 repo 的 `ventoy.json` 範例已示範單一 tip實機部署版本`DEPLOY.md`)會對每個 ISO 寫明「自動安裝流程+會清碟+預設帳密」作為開機前最後提醒。`tip` 是單行的,不支援 `\n`
驗證USB 插上目標機開機 → Ventoy 選單選 ISO → 如果 `ventoy.json` 寫對畫面會出現「Select Auto Install Template」→ 選 `unattend.xml`
---
## 2. 先在 VM 試跑(強烈建議)
跳過這步 = 在真機上賭運氣。最關鍵的是驗證 `$$VT_WINDOWS_DISK_1ST_NONVTOY$$` 有沒有挑對磁碟。
### 最省事:直接把 Ventoy USB 傳入 VM
- **VirtualBox**(裝 Extension PackVM 設定 → USB → 加上你的 Ventoy USB開機順序把 USB 放最前。
- **VMware Workstation / Fusion**VM → Removable Devices → 連接 Ventoy USBBIOS 改開機順序。
- **QEMU**`-drive file=/dev/diskN,format=raw,if=none,id=usb ...`macOS 先 `diskutil unmountDisk`)。
VM 要 UEFI 開機、建議 ≥ 60 GB 虛擬硬碟(才能看到分割成功)、測試時可先關 Secure Boot。
### 另一種:用 Ventoy 的 VHD 模式
Ventoy 支援寫進 VHD/VDI可直接掛進 Hyper-V / VirtualBox 當第一顆硬碟,不用實體 USB。細節看 Ventoy 官方文件「Install Ventoy to Local Disk」。
### 驗證重點
1. Ventoy 選單正確顯示 ISO
2. 選了 ISO 後有跳「Auto Install Template」選單
3. 安裝過程中**沒有跳語系或分割畫面**
4. 裝完後看 `C:\` 的磁碟編號 — 不是 Ventoy USB 的那顆
---
## 3. 跑起來會看到什麼
| 階段 | 畫面 | 時間 |
|---|---|---|
| WinPE 啟動 | Windows 標誌、載入條 | 3060 秒 |
| 磁碟分割 + 映像展開 | 「正在安裝 Windows」百分比 | 515 分鐘 |
| 第一次重開 | 黑屏 → 「請稍候」 | 12 分鐘 |
| OOBE 略過 | **不該出現任何選單**;直接跳過 | 秒殺 |
| AutoLogon | 以 `Admin` 自動登入到桌面顯示名稱是「Administrator」 | — |
| FirstLogonCommands | 閃過一連串 PowerShell / cmd 黑視窗(密碼永不過期、改主機名、建 user 帳號、從 USB 拷 Setup.ps1、跑 Setup.ps1 的 13 段 post-install | 515 分鐘(含 FoD 下載、Win11Debloat 解壓、winget Chrome、AI 元件移除) |
| 重開機 | 5 秒倒數後重啟 | — |
| 第二次開機 | 看到登入畫面,有 `User` 一個選項(`Admin` 已被 SpecialAccounts 隱藏;輸入帳號名仍可登入) | — |
**正常就是全程不需要碰鍵盤滑鼠。** 如果中途卡在 OOBE 畫面要你選語系/建帳號 → 去看第 5 節除錯。
---
## 4. 部署後善後
第一次自動登入完成後,建議做這幾件事:
1. **刪除殘留的回應檔**(含明碼密碼):
```powershell
Remove-Item C:\Windows\Panther\unattend.xml -Force -ErrorAction SilentlyContinue
Remove-Item C:\Windows\Panther\Unattend\unattend.xml -Force -ErrorAction SilentlyContinue
```
建議加到 `Setup.ps1` 結尾。
2. **關掉 AutoLogon**(本範本靠 `LogonCount=1` 會自動失效,驗證一下):
```powershell
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon
```
3. **改密碼**:範本的 `Admin/P@ssw0rd!` 和 `User/1234` 都是給自動化用的,上線前換掉。`User` 登入時會被強制改密,`Admin` 要自己 `net user Admin *` 改。
4. **看一下 FirstLogon / Setup log**
```powershell
notepad C:\Windows\Temp\firstlogon-copysetup.log # Order 4Setup.ps1 是否從 Ventoy USB 複製成功
notepad C:\Windows\Temp\firstlogon-runsetup.log # Order 5Setup.ps1 找不到才會有此檔
notepad C:\Windows\Temp\setup.log # Setup.ps1 主 log13 段每段都寫 START/DONE/ERR
```
找 `=== <name> ERR: ... ===` 行就是失敗段;`Setup.ps1` 每段都冪等,可以登入 `Admin` 後 `powershell -ExecutionPolicy Bypass -File C:\Scripts\Setup.ps1` 整支重跑,或挑特定段貼進視窗。
5. **驗證遠端管理可用**(從別台機器試):
```bash
ping <機器 IP> # ICMP 應該回應
ssh Admin@<機器 IP> # OpenSSH 22/TCP密碼 P@ssw0rd!(金鑰要先放 administrators_authorized_keys
# RDP用任何 RDP client 連 <機器 IP>:3389
# WinRM5985HTTPAllowUnencrypted=trueTrustedHosts=*
```
---
## 5. 除錯:沒跑完或卡住時
### 看日誌
Windows Setup 把所有 unattend 執行記錄放在:
| 階段 | 路徑 |
|---|---|
| WinPE | `X:\Windows\Panther\setupact.log`WinPE 執行期間) |
| 安裝中 | `C:\Windows\Panther\setupact.log` |
| OOBE/Specialize | `C:\Windows\Panther\UnattendGC\setupact.log` |
| FirstLogonCommands 錯誤 | 開 Event Viewer → Windows Logs → Application |
Shift + F10 在任何安裝畫面會開出命令提示字元,可以 `notepad` 看 log。
### 常見錯誤
| 現象 | 原因 | 解法 |
|---|---|---|
| Ventoy 沒跳「Auto Install Template」選單 | `ventoy.json` 的 `image` 路徑對不上 ISO 實際路徑 | 路徑以 `/` 開頭、相對 USB 根目錄;或改用 fuzzy / `parent` 比對 |
| 跳了選單但跳過後仍停在選語系畫面 | `unattend.xml` 路徑錯誤或 XML schema 有誤 | 用 Windows SIM 驗證 XML確認 `template` 指到的檔案真的存在 |
| 磁碟分割失敗或裝到 Ventoy USB 上 | `DiskID` 挑到 Ventoy USB | 確認用的是 `$$VT_WINDOWS_DISK_1ST_NONVTOY$$`,不是硬寫 `0`;多硬碟環境可改用 `$$VT_WINDOWS_DISK_MAX_SIZE$$` |
| 磁碟分割失敗(所有硬碟都試過) | 目標機是 BIOS/MBR | 改 `<DiskConfiguration>`:拿掉 EFI/MSR用 MBR + System Reserved |
| `ProductKey` 錯誤 | 序號無效 | 改正確序號、用 KMS 通用金鑰、或刪掉整個 `<ProductKey>` 節點 |
| OOBE 沒略過 | Windows 版本不支援該欄位 | 比對當前版本 SIM 可用欄位 |
| FirstLogonCommands 沒跑 | `AutoLogon` 沒設或 `Order` 重複 | 確認 `AutoLogon.Enabled=true` 且 `Order` 不重複 |
| `Setup.ps1` 找不到(`firstlogon-copysetup.log` 寫 `NOT FOUND` | Ventoy USB 太早被拔掉,或 `Setup.ps1` 沒 cp 到 `/ventoy/script/` | 等到第二次重開機進登入畫面後才拔;或重新 `cp Setup.ps1 /Volumes/Ventoy/ventoy/script/` |
| `Setup.ps1` 跑了但某段 ERR | 看 `C:\Windows\Temp\setup.log` 的 `=== <name> ERR: ... ===` | 修一修對應段,登入 `Admin` 後 `powershell -ExecutionPolicy Bypass -File C:\Scripts\Setup.ps1` 整支重跑 |
### 驗證 XML 語法
用 Windows SIM 開啟(會 schema-validate或任何支援 XSD 的編輯器。
---
## 6. 下一步
- 讀 `README.md` 了解每個欄位在做什麼
- 看 `SUMMARY.md` 了解整體設計脈絡
- 改完記得 Commit 一份給自己留底