從 Ubuntu 升級至 Ubuntu Pro


Ubuntu LTS 映像檔的生命週期結束後,就不再受到支援,也不會收到安全性更新。如果您升級至 Ubuntu Pro,在延長安全維護 (ESM) 期間,您仍可繼續收到安全性更新。

本文說明如何為每個 VM 執行下列操作,從 Ubuntu 升級至 Ubuntu Pro:

  1. 安裝更新和依附元件
  2. 附加 Ubuntu Pro 授權
  3. 驗證執照

支援的升級路徑

下表列出支援的升級路徑:

初始版本 最終版本
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 名稱:

    1. 使用下列指令更新套件索引:
      gcloud compute ssh VM_NAME --command "sudo apt update"
    2. 請使用下列指令安裝最新版本的套件:
      gcloud compute ssh VM_NAME --command "sudo apt -f upgrade"
    3. 請使用下列指令安裝 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

    1. 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.

    2. Set a default region and zone.

附加執照

請按照下列程序附加 Ubuntu Pro 授權:

  1. 使用 gcloud compute instances stop 指令停止 VM:

    gcloud compute instances stop VM_NAME \
       --zone=ZONE
    

    更改下列內容:

    • VM_NAME:要停止的 VM 名稱
    • ZONE:包含要停止的 VM 的可用區
  2. 使用 gcloud compute instances describe 指令取得與 VM 相關聯的磁碟清單:

    gcloud compute instances describe VM_NAME \
       --zone=ZONE \
       --format="yaml(disks)"
    

    更改下列內容:

    • VM_NAME:要取得相關聯磁碟清單的 VM 名稱

    • ZONE:包含 VM 的可用區,用於取得相關聯磁碟的清單

  3. 確認輸出內容類似下列內容:

    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
    

    請注意,系統不會附加 userLicenses

  4. 執行 gcloud compute disks list 指令,取得開機磁碟的名稱:

    gcloud compute disks list
    
  5. 使用 gcloud beta compute disks update 指令更新開機磁碟,並加入 Ubuntu Pro 授權 URI:

    gcloud beta compute disks update BOOT_DISK_NAME \
       --zone=ZONE \
       --update-user-licenses="LICENSE_URI"
    

    更改下列內容:

    • BOOT_DISK_NAME:要附加授權的開機磁碟名稱。

    • ZONE:包含要附加授權的啟動磁碟區。

    • LICENSE_URI:您要升級至的 Ubuntu Pro 版本的授權 URI。下表列出支援的 Ubuntu Pro 版本授權 URI:

      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 授權:

  1. 執行 gcloud beta compute disks describe 指令,取得開機磁碟的相關資訊:

    gcloud beta compute disks describe BOOT_DISK_NAME \
       --zone=ZONE
    

    更改下列內容:

    • BOOT_DISK_NAME:要驗證授權的開機磁碟名稱

    • ZONE:包含啟動磁碟的可用區,用於驗證授權

  2. 確認輸出內容類似以下:

    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
    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
    userLicenses:
    - https://www.googleapis.com/compute/v1/projects/ubuntu-os-pro-cloud/global/licenses/ubuntu-pro-1604-lts
    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
    
  3. 檢查上一個步驟的輸出內容,確認 userLicenses 欄位是否有適當的授權字串,藉此驗證 Ubuntu Pro 授權已附加至開機磁碟。

    如果 userLicenses 欄位未包含所需的授權字串,您可能需要清除並更新使用者授權。詳情請參閱 gcloud beta compute disks update 指令

  4. 使用 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) 檔案路徑

  5. VM 啟動後,請執行 gcloud compute ssh 指令,確認 Ubuntu ESM 已獲授權並啟用:

    gcloud compute ssh VM_NAME --command "sudo ua status --wait" \
       --zone=ZONE
    

    更改下列內容:

    • VM_NAME:要驗證的 VM 名稱

    • ZONE:包含要驗證的 VM 的可用區

  6. 確認 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
    

查看稽核記錄

請按照下列程序查看授權更新記錄:

  1. 前往 Google Cloud 控制台中的「活動」頁面。

    前往「活動」

  2. 在「類別」的「篩選器」窗格中,針對「活動類型」選取「設定」

  3. 在「Categories」的「Filters」窗格中,針對「Resource type」選取「Disk」