如要在 Trusted Cloud by S3NS上建立 Windows VM,您必須使用預先安裝 Windows 或 Windows Server 的 VM 映像檔。 Trusted Cloud 提供常用 Windows Server 版本的公開映像檔,但這些映像檔僅適用於隨選授權。如要自備 Windows 授權 (BYOL),您必須匯入現有映像檔,或建立自訂映像檔。
本指南說明如何使用 Trusted Cloud 建立公開映像檔時採用的相同工具和程序,建立自訂映像檔。
如要完成本指南,您需要:
- 內含 Windows 或 Windows Server 安裝媒體的 ISO 檔案。
- (選用) 一或多個要套用至映像檔的 Windows 更新套件 (
.msu
格式)。
事前準備
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Trusted Cloud by S3NS 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
- Set a default region and zone.
瞭解建構程序
如要從頭安裝 Windows,一般做法是從包含 Windows 安裝檔案的 DVD 或 ISO 檔案啟動電腦。與某些地端管理程序不同,Compute Engine 不允許您從 ISO 檔案啟動。
因此,如要從頭安裝 Windows,必須採取不同的做法,包括下列步驟:
- 建立新磁碟。
- 將 Windows 映像檔 (
install.wim
安裝媒體) 擷取至磁碟。 - 新增必要驅動程式、設定 Windows 安裝程式,使其在無人看管的情況下執行,以及讓磁碟可啟動。
- 從新磁碟開機,執行 Windows 安裝程式。
- 安裝其他軟體,包括 Guest OS 代理程式。
- 從磁碟建立映像檔。
本指南將說明如何使用 Cloud Build、
daisy
工具,以及 GitHub 上提供的參考工作流程,自動執行這些步驟,不必手動操作。daisy
是開放原始碼指令列工具,可讓您執行工作流程。工作流程會以 JSON 檔案的形式編寫,並包含一連串步驟。每個步驟都說明一項 Compute Engine 作業,例如建立磁碟或關閉 VM 執行個體。因此,Daisy 工作流程適合自動執行從頭建構 Windows 映像檔所需的步驟。建立自訂 Windows 映像檔的 Daisy 工作流程會建立兩個臨時 VM 執行個體。第一個 VM 執行個體 (前置字元為
bootstrap
) 會執行必要步驟,建立可啟動的磁碟。第二個 VM 執行個體 (前置字元為install
) 會執行 Windows 安裝程式,並完成所有剩餘步驟。準備專案以建構映像檔
為避免 Daisy 工具干擾現有的 VM 執行個體或基礎架構,請建立專屬專案來建構映像檔:
- 在本機電腦上開啟 Windows PowerShell 視窗。
初始化變數:
$PROJECT_ID = "
PROJECT_ID
"其中
PROJECT_ID
是您在上一節中建立的Trusted Cloud 專案 ID。初始化另一個變數,使其包含專案的專案編號:
$PROJECT_NUMBER = gcloud projects describe $PROJECT_ID --format=value`(projectNumber`)
- 在本機電腦上開啟終端機視窗。
初始化變數:
PROJECT_ID=
PROJECT_ID
其中
PROJECT_ID
是您在上一節中建立的Trusted Cloud 專案 ID。初始化另一個變數,使其包含專案的專案編號:
PROJECT_NUMBER=`gcloud projects describe $PROJECT_ID --format=value\(projectNumber\)`
在本機電腦上下載必要的安裝套件:
建立新的 Cloud Storage bucket 來儲存安裝檔案:
gcloud storage buckets create gs://$PROJECT_ID-media --project=$PROJECT_ID
將 Storage 物件檢視者角色授予 Cloud Build,讓 Cloud Build 可以讀取安裝檔案:
gcloud storage buckets add-iam-policy-binding gs://$PROJECT_ID-media --member=serviceAccount:$PROJECT_NUMBER@cloudbuild.s3ns-system.iam.gserviceaccount.com --role=roles/storage.objectViewer
上傳 PowerShell 安裝套件:
gcloud storage cp
POWERSHELL_PACKAGE
gs://$PROJECT_ID-media/PowerShell.msi其中
POWERSHELL_PACKAGE
是 PowerShell 安裝套件的路徑。上傳 .NET Framework 安裝套件:
gcloud storage cp
DOTNET_PACKAGE
gs://$PROJECT_ID-media/dotnet-sdk.exe其中
DOTNET_PACKAGE
是指 .NET Framework 安裝套件的路徑。上傳 gcloud CLI 安裝套件:
gcloud storage cp
CLOUDSDK_PACKAGE
gs://$PROJECT_ID-media/GoogleCloudSDKInstaller.exe其中
CLOUDSDK_PACKAGE
是 gcloud CLI 安裝套件的路徑。上傳內含 Windows 安裝媒體的 ISO 檔案:
gcloud storage cp
ISO
gs://$PROJECT_ID-media/其中
ISO
是 ISO 檔案的名稱。(選用) 上傳其他更新套件:
gcloud storage cp
UPDATE_DIR
/*.msu gs://$PROJECT_ID-media/updates/其中
UPDATE_DIR
是包含更新套件的目錄。在本機電腦上,複製包含用於建構 Windows 映像檔的
daisy
工作流程的 Git 存放區:git clone https://github.com/GoogleCloudPlatform/compute-image-tools.git
切換至
windows
目錄:cd compute-image-tools/daisy_workflows/image_build/windows/
在
windows
目錄中,您會看到一系列以.wf.json
為後置字元的檔案。這些檔案包含常用 Windows 版本的 Daisy 工作流程定義:Windows 版本 工作流程檔案 Windows Server Core 2022 (64 位元) windows-server-2022-dc-core-uefi-byol.wf.json
Windows Server 2019 (64 位元) windows-server-2019-dc-uefi-byol.wf.json
Windows Server Core 2019 (64 位元) windows-server-2019-dc-core-uefi-byol.wf.json
Windows Server 2016 (64 位元) windows-server-2016-dc-uefi-byol.wf.json
Windows Server Core 2016 (64 位元) windows-server-2016-dc-core-uefi-byol.wf.json
Windows 11 21H2 (64 位元) windows-11-21h2-ent-x64-uefi.wf.json
Windows 11 22H2 (64 位元) windows-11-22h2-ent-x64-uefi.wf.json
Windows 11 23H2 (64 位元) windows-11-23h2-ent-x64-uefi.wf.json
Windows 10 21H2 (64 位元) windows-10-21h2-ent-x64-uefi.wf.json
Windows 10 22H2 (64 位元) windows-10-22h2-ent-x64-uefi.wf.json
開啟與要安裝的 Windows 版本最相符的工作流程檔案。視需要變更工作流程檔案中的 Windows 版本 (
edition
) 和授權金鑰 (product_key
) 設定,確保與安裝媒體相符。如果不確定正確的版次名稱,請開啟提升權限的 PowerShell 提示,然後執行下列指令,列出安裝媒體支援的所有版次:
$IsoFile = "
ISO
" $Mount = Mount-DiskImage -ImagePath (Resolve-Path $IsoFile) $DriveLetter = ($Mount | Get-Volume).DriveLetter Get-WindowsImage -ImagePath "$($DriveLetter):\sources\install.wim" | select ImageName Dismount-DiskImage -InputObject $Mount | Out-Null將
ISO
替換為 ISO 映像檔的本機路徑。在
windows
目錄中,建立名為cloudbuild.yaml
的新檔案,然後貼上下列程式碼:timeout: 14400s # 4 hour timeout for entire build steps: - name: 'gcr.io/compute-image-tools/daisy' timeout: 14400s # 4 hour timeout for build step waitFor: ['-'] args: - -project=$PROJECT_ID - -zone=us-central1-a - -var:updates=gs://$PROJECT_ID-media/updates/ - -var:pwsh=gs://$PROJECT_ID-media/PowerShell.msi - -var:dotnet48=gs://$PROJECT_ID-media/dotnet-sdk.exe - -var:cloudsdk=gs://$PROJECT_ID-media/GoogleCloudSDKInstaller.exe - -var:media=gs://$PROJECT_ID-media/
ISO
-WORKFLOW
取代:
ISO
:Cloud Storage 中的 ISO 檔案名稱。WORKFLOW
:與您使用的 Windows 版本對應的工作流程檔案名稱。
將建構提交至 Cloud Build:
gcloud builds submit --project $PROJECT_ID --async
建構作業最多需要 4 小時才會完成。您可以在 Trusted Cloud 控制台的「Cloud Build」>「History」(記錄) 下追蹤建構狀態。
- 確認您已上傳正確的安裝套件和 ISO 檔案。
- 確認選取的工作流程與 ISO 檔案的 Windows 版本相符。
- 查看 Cloud Build 中的建構記錄 ,並檢查是否有任何錯誤訊息。
- 如果建構作業似乎停滯,請查看建構作業建立的 VM 執行個體序列埠輸出,並檢查是否有錯誤訊息。
- 進一步瞭解 Daisy 工具。
- 進一步瞭解用於建構映像檔的 Daisy 工作流程。
- 瞭解如何將現有授權加入 Compute Engine。
- 請參閱使用映像檔系列的最佳做法。
In the Trusted Cloud console, on the project selector page, select or create a Trusted Cloud project.
Verify that billing is enabled for your Trusted Cloud project.
Enable the Compute Engine API, Cloud Build API, and Cloud Storage API APIs.
後續步驟會因本機電腦使用的作業系統 (Windows 或 Linux) 而異:
Windows
Linux
上傳安裝檔
現在請收集自訂映像檔所需的所有安裝檔案,並上傳至 Cloud Storage bucket。將檔案儲存在 Cloud Storage bucket 中,可確保
daisy
和daisy
用於建構映像檔的暫時 VM 執行個體都能存取檔案。現在可以開始建構自訂映像檔。
建構映像檔
執行
daisy
工作流程來建構自訂映像檔最多需要四小時。現在您不必在本機執行daisy
,而是建立 Cloud Build 設定,讓 Cloud Build 在背景執行工作流程。使用自訂圖片
建構完成後,您可以在Trusted Cloud 控制台的「Compute Engine」>「映像檔」下方找到自訂 BYOL 映像檔。
為協助區分同一張圖片的多個版本,建構程序會在圖片名稱中嵌入時間戳記,例如
windows-server-2019-dc-v1613488342
。此外,這個程序會將映像檔與自訂映像檔系列建立關聯,例如windows-server-2019
。如要建立使用自訂 BYOL 映像檔的 VM 執行個體,您必須在單一用戶群節點上佈建 VM 執行個體。
疑難排解
如果您懷疑建構程序失敗或沒有進行,請使用以下方法來診斷情況:
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-08 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-08 (世界標準時間)。"],[[["Google Cloud provides public Windows Server images for on-demand licensing, but custom images are required for Bring Your Own License (BYOL) scenarios."],["Creating a custom Windows image on Google Cloud involves extracting the Windows image to a disk, adding drivers, configuring setup, and making the disk bootable, steps that are automated with Cloud Build and the `daisy` tool."],["To prepare for building images, you need to set up a dedicated Google Cloud project and upload necessary installation files, including the Windows ISO and any update packages, to a Cloud Storage bucket."],["The `daisy` tool uses temporary VM instances and predefined workflows (JSON files) to automate the complex process of building custom Windows images from scratch, for a variety of Windows versions."],["After a successful build, the custom BYOL image is available in Compute Engine, with a timestamp in the name, and can be used to create VM instances, however, if using a volume license, a KMS server will need to be configured."]]],[]] -