Ubuntu LTS 映像檔終止支援後,系統將不再提供支援,也不會再發布安全性更新。如果升級至 Ubuntu Pro,您將在延長安全性維護 (ESM) 期間持續收到安全性更新。
本文說明如何為每個 VM 執行下列操作,從 Ubuntu 升級至 Ubuntu Pro:
- 安裝更新和依附元件。
- 將 Ubuntu 授權換成 Ubuntu Pro 授權。
- 驗證授權。
支援的升級路徑
下表列出支援的升級路徑:
初始版本 | 最終版本 |
---|---|
Ubuntu 16.04 LTS | Ubuntu Pro 16.04 LTS |
Ubuntu 18.04 LTS | Ubuntu Pro 18.04 LTS |
Ubuntu 20.04 LTS | Ubuntu Pro 20.04 LTS |
Ubuntu 22.04 LTS | Ubuntu Pro 22.04 LTS |
Ubuntu 24.04 LTS | Ubuntu Pro 24.04 LTS |
限制
您必須先停止 VM,才能更換授權。
只有在 Ubuntu LTS 和 Ubuntu Pro LTS 版本相同時,才能升級。舉例來說,您可以從 Ubuntu 16.04 LTS 升級至 Ubuntu Pro 16.04 LTS,但無法從 Ubuntu 16.04 LTS 升級至 Ubuntu Pro 20.04 LTS。
帳單
系統會根據付費映像檔的定價,向您收取 Ubuntu Pro LTS 的費用。
如要進一步瞭解帳單相關資訊,請參閱 Cloud Billing。
事前準備
-
在每個 VM 上執行下列指令,將
VM_NAME
替換為要升級的 VM 名稱:-
使用下列指令更新套件索引:
gcloud compute ssh VM_NAME --command "sudo apt update"
-
使用下列指令安裝最新版本的套件:
gcloud compute ssh VM_NAME --command "sudo apt -f upgrade"
-
使用下列指令安裝 Ubuntu Pro:
gcloud compute ssh VM_NAME --command "sudo apt -f install ubuntu-advantage-pro"
-
使用下列指令更新套件索引:
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Google Cloud 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列其中一個選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
使用
gcloud compute instances stop
指令停止 VM:gcloud compute instances stop VM_NAME \ --zone=ZONE
更改下列內容:
VM_NAME
:要停止的 VM 名稱ZONE
:包含要停止的 VM 的可用區
使用
gcloud compute instances describe
指令取得與 VM 相關聯的磁碟清單:gcloud compute instances describe VM_NAME \ --zone=ZONE \ --format="yaml(disks)"
更改下列內容:
VM_NAME
:要取得相關聯磁碟清單的 VM 名稱ZONE
:包含 VM 的可用區,可從中取得相關聯的磁碟清單
確認輸出內容類似於:
disks: - autoDelete: true boot: true deviceName: ubuntu diskSizeGb: '10' guestOsFeatures: - type: VIRTIO_SCSI_MULTIQUEUE - type: SEV_CAPABLE - type: UEFI_COMPATIBLE - type: GVNIC index: 0 interface: SCSI kind: compute#attachedDisk licenses: - https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/licenses/ubuntu-1604-xenial mode: READ_WRITE shieldedInstanceInitialState: dbxs: - content: ... fileType: BIN source: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/zones/ZONE/disks/VM_NAME type: PERSISTENT
請注意,沒有任何
Licenses
遭到取代。執行
gcloud compute disks list
指令,取得開機磁碟的名稱:gcloud compute disks list
使用
gcloud compute disks update
指令,以 Ubuntu Pro 授權 URI 更新開機磁碟:gcloud compute disks update DISK_NAME \ --zone=ZONE \ --replace-licenses="PREVIOUS_LICENSE, NEW_LICENSE"
更改下列內容:
DISK_NAME
:要更換授權的開機磁碟名稱。ZONE
:包含要更換授權的開機磁碟的可用區。PREVIOUS_LICENSE
:Ubuntu 版本的授權 URINEW_LICENSE
:新的 Ubuntu Pro 授權 URI。
下表列出支援的 Ubuntu Pro 版本授權 URI:
執行
gcloud compute disks describe
指令,取得開機磁碟的相關資訊:gcloud compute disks describe DISK_NAME \ --zone=ZONE
更改下列內容:
DISK_NAME
:要驗證授權的開機磁碟名稱ZONE
:包含要驗證授權的開機磁碟的可用區
確認輸出內容類似於:
creationTimestamp: '2021-10-20T17:20:26.616-07:00' guestOsFeatures: - type: VIRTIO_SCSI_MULTIQUEUE - type: SEV_CAPABLE - type: UEFI_COMPATIBLE - type: GVNIC id: '7008232787326864549' kind: compute#disk labelFingerprint: 42WmSpB8rSM= lastAttachTimestamp: '2021-10-20T17:20:26.617-07:00' licenseCodes: - '1000201' - '8045211386737108299' licenses: - https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/licenses/ubuntu-1604-xenial - https://www.googleapis.com/compute/v1/projects/ubuntu-os-pro-cloud/global/licenses/ubuntu-pro-1604-lts name: ubuntu physicalBlockSizeBytes: '4096' selfLink: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/zones/ZONE/disks/DISK_NAME sizeGb: '10' sourceImage: https://www.googleapis.com/compute/v1/projects/IMAGE_PROJECT/global/images/IMAGE sourceImageId: '1233998915439563944' status: READY type: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/zones/ZONE/diskTypes/DISK_TYPE users: - https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/zones/ZONE/instances/VM_NAME zone: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/zones/ZONE
檢查上一步的輸出內容,確認開機磁碟已新增 Ubuntu Pro 授權,並在
licenses
欄位中找到適當的授權字串。如果「
licenses
」欄位未包含預期的授權字串,您可能需要清除並更新授權。詳情請參閱gcloud compute disks update
指令。使用
gcloud compute instances start
指令啟動 VM:gcloud compute instances start VM_NAME \ --zone=ZONE \ [--csek-key-file ENCRYPTION_KEY]
更改下列內容:
VM_NAME
:要啟動的 VM 名稱ZONE
:包含要啟動的 VM 的可用區ENCRYPTION_KEY
:選用:指定客戶提供的加密金鑰 (CSEK) 檔案路徑 (如果開機磁碟已加密)
虛擬機器啟動後,請執行
gcloud compute ssh
指令,確認 Ubuntu ESM 已獲得授權並啟用:gcloud compute ssh VM_NAME --command "sudo ua status --wait" \ --zone=ZONE
更改下列內容:
VM_NAME
:要驗證的 VM 名稱ZONE
:包含要驗證的 VM 的可用區
確認輸出內容類似下列內容,藉此驗證 Ubuntu ESM 是否已獲得授權並啟用:
SERVICE ENTITLED STATUS DESCRIPTION cis yes disabled Center for Internet Security Audit Tools esm-apps yes enabled UA Apps: Extended Security Maintenance (ESM) esm-infra yes enabled UA Infra: Extended Security Maintenance (ESM) fips yes n/a NIST-certified core packages fips-updates yes n/a NIST-certified core packages with priority security updates livepatch yes n/a Canonical Livepatch service
前往 Google Cloud 控制台的「Logs Explorer」頁面。
確認工具列中的「Show query」(顯示查詢) 已啟用。
將下列運算式複製到查詢編輯器:
resource.type="gce_disk" logName="projects/PROJECT_NAME/logs/cloudaudit.googleapis.com%2Factivity" severity>=NOTICE protoPayload.request.@type="type.googleapis.com/compute.disks.update" protoPayload.request.licenses:*
將
PROJECT_NAME
替換為您的專案名稱。點選「執行查詢」
更換授權
請按照下列程序,將 Ubuntu 授權替換為 Ubuntu Pro 授權:
Ubuntu Pro 版本 授權 URI Ubuntu Pro 16.04 LTS https://www.googleapis.com/compute/v1/projects/ubuntu-os-pro-cloud/global/licenses/ubuntu-pro-1604-lts
Ubuntu Pro 18.04 LTS https://www.googleapis.com/compute/v1/projects/ubuntu-os-pro-cloud/global/licenses/ubuntu-pro-1804-lts
Ubuntu Pro 20.04 LTS https://www.googleapis.com/compute/v1/projects/ubuntu-os-pro-cloud/global/licenses/ubuntu-pro-2004-lts
Ubuntu Pro 22.04 LTS https://www.googleapis.com/compute/v1/projects/ubuntu-os-pro-cloud/global/licenses/ubuntu-pro-2204-lts
Ubuntu Pro 24.04 LTS https://www.googleapis.com/compute/v1/projects/ubuntu-os-pro-cloud/global/licenses/ubuntu-pro-2404-lts
驗證授權
如要驗證 Ubuntu Pro 授權,請按照下列步驟操作:
查看活動記錄
如要查看專案中 VM 的授權更新記錄,請按照下列程序操作:
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-11 (世界標準時間)。
-