Files
windows-unattend/QUICKSTART.md

152 lines
5.2 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
照著做一次就能跑出一個「插上 USB → 自動裝完 Windows → 自動登入 → 跑 Setup.ps1 → 重開機」的流程。
> 預設情境x64、UEFI+GPT、繁體中文、單一 Disk 0。
---
## 0. 事前準備
需要準備:
- [ ] Windows 10 或 11 官方 ISO從 [microsoft.com](https://www.microsoft.com/software-download) 取得)
- [ ] 一支 ≥ 8 GB 的 USB 隨身碟(會被格式化)
- [ ] 一台測試機或 VM強烈建議先在 VM 驗證)
- [ ] 本專案的 `unattend.xml`
**編輯 `unattend.xml` 的必改項目:**
| 行為 | 原值 | 要改成 |
|---|---|---|
| 產品序號 | `XXXXX-XXXXX-XXXXX-XXXXX-XXXXX` | 你的序號,或 KMS 通用金鑰,或整個 `<ProductKey>` 節點刪掉 |
| 管理員密碼 | `P@ssw0rd!`(兩處:`LocalAccount``AutoLogon` | 你的密碼 |
| 組織名 | `YourCompany` | 你的組織 |
| 腳本路徑 | `C:\Scripts\Setup.ps1` | 留著或改路徑;不要執行就刪 `<SynchronousCommand Order=1>` |
---
## 1. 做一支自動安裝 USB
### 選項 ARufus最快Windows 原生)
1. 下載 [Rufus](https://rufus.ie/) 並開啟
2. 選 ISO、選 USB、分割配置選 **GPT**、目標選 **UEFI**
3. 按「開始」寫入
4. 寫入完成後,把 `unattend.xml` **改名為 `autounattend.xml`** 放到 USB 根目錄
### 選項 BmacOS / Linux 手動方式
```bash
# macOS找到 USB
diskutil list
# 假設是 /dev/disk4
diskutil eraseDisk MS-DOS "WINUSB" GPT /dev/disk4
# 掛載 ISO 並複製
hdiutil mount Windows.iso
cp -R /Volumes/CCCOMA_X64FRE_ZH-TW_DV9/* /Volumes/WINUSB/
# 放入 autounattend.xml
cp unattend.xml /Volumes/WINUSB/autounattend.xml
```
> Linux 用 `wimlib-imagex split` 處理超過 FAT32 4GB 限制的 `install.wim`。
---
## 2. 先在 VM 試跑(強烈建議)
跳過這步 = 在真機上賭運氣。
### Hyper-V
```powershell
New-VM -Name "WinTest" -Generation 2 -MemoryStartupBytes 4GB -NewVHDPath "C:\VM\WinTest.vhdx" -NewVHDSizeBytes 60GB
Set-VMDvdDrive -VMName "WinTest" -Path "C:\ISO\Windows.iso"
Set-VMFirmware -VMName "WinTest" -EnableSecureBoot Off # 測試期間關掉比較省事
Start-VM "WinTest"
```
`autounattend.xml` 注入 ISO用 [AnyBurn](https://www.anyburn.com/) / `oscdimg` 在 ISO 根目錄加入該檔,或在 VM 掛第二顆 CD。
### VirtualBox / VMware
建一台 UEFI 開機的 VM掛改好的 ISO 開機即可。
---
## 3. 跑起來會看到什麼
| 階段 | 畫面 | 時間 |
|---|---|---|
| WinPE 啟動 | Windows 標誌、載入條 | 3060 秒 |
| 磁碟分割 + 映像展開 | 「正在安裝 Windows」百分比 | 515 分鐘 |
| 第一次重開 | 黑屏 → 「請稍候」 | 12 分鐘 |
| OOBE 略過 | **不該出現任何選單**;直接跳過 | 秒殺 |
| AutoLogon | 以 `Admin` 自動登入到桌面 | — |
| FirstLogonCommands | 閃出 PowerShell 視窗跑 `Setup.ps1` | 看腳本內容 |
| 重開機 | 5 秒倒數後重啟 | — |
**正常就是全程不需要碰鍵盤滑鼠。** 如果中途卡在 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. **改密碼**:範本密碼 `P@ssw0rd!` 是給自動化用的,上線前換掉。
---
## 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。
### 常見錯誤
| 現象 | 原因 | 解法 |
|---|---|---|
| 停在選語系畫面 | `autounattend.xml` 沒讀到 | 檔名拼錯/不在根目錄;確認 USB 格式 FAT32 |
| 磁碟分割失敗 | 目標機是 BIOS/MBR | 改 `<DiskConfiguration>`:拿掉 EFI/MSR用 MBR + System Reserved |
| `ProductKey` 錯誤 | 序號無效 | 改正確序號、用 KMS 通用金鑰、或刪掉整個 `<ProductKey>` 節點 |
| OOBE 沒略過 | Windows 版本不支援該欄位 | 比對當前版本 SIM 可用欄位 |
| FirstLogonCommands 沒跑 | `AutoLogon` 沒設或 `Order` 重複 | 確認 `AutoLogon.Enabled=true` 且 `Order` 不重複 |
| `Setup.ps1` 找不到 | 路徑不存在 | 先用其他方式把腳本放到 `C:\Scripts\`,或改用 `FirstLogonCommands` 從 USB 複製 |
### 驗證 XML 語法
用 Windows SIM 開啟(會 schema-validate或任何支援 XSD 的編輯器。
---
## 6. 下一步
-`README.md` 了解每個欄位在做什麼
-`SUMMARY.md` 了解整體設計脈絡
- 改完記得 Commit 一份給自己留底