建立自訂開機磁碟


建立 Compute Engine 執行個體時,您也必須為該執行個體建立開機磁碟。您可以使用公開映像檔、自訂映像檔或從其他開機磁碟取得的快照。建立開機磁碟時,請將磁碟大小限制為 2 TiB,以符合 MBR 分區的限制。

當您建立執行個體時,Compute Engine 會自動建立開機磁碟。如果您的執行個體需要其他資料儲存空間,請為執行個體新增一或多個次要執行個體儲存磁碟

請按照本文件所述的程序建立可用於日後建立 VM 的開機磁碟。如要改善開機磁碟的效能,或為其他應用程式或作業系統檔案新增空間,您可以調整 永久磁碟Google Cloud Hyperdisk 開機磁碟的大小。

最佳做法是不要將地區磁碟用於開機磁碟。在容錯移轉的情況下,無法將這種磁碟強制附加至運算執行個體。

事前準備

  • 使用 Google Cloud CLI 或 REST 從映像檔或磁碟建立虛擬機器 (VM) 時,每秒最多只能建立 20 個 VM 執行個體。如果您需要每秒建立更多 VM,請要求提高圖像資源的配額限制
  • 如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 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.

    REST

    To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.

      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.

    For more information, see Authenticate for using REST in the Google Cloud authentication documentation.

使用映像檔建立開機磁碟

除了建立執行個體以外,您還可以建立獨立開機磁碟,並在日後將它附加至執行個體。

主控台

  1. 前往 Google Cloud 控制台中的「Create a disk」(建立磁碟) 頁面。

    前往「Create a disk」(建立磁碟) 頁面

  2. 選取「Disk source type」(磁碟來源類型) 底下的「Image」(映像檔)。從清單中選擇圖片。

  3. 按一下 [建立]。

gcloud

如要建立獨立的開機磁碟,請使用 gcloud compute disks create 指令:

gcloud compute disks create DISK_NAME --image IMAGE_NAME

REST

如要建立新的開機磁碟,請對 disks.insert 方法提出 POST 要求:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_NAME/zones/ZONE/disks?sourceImage=IMAGE

IMAGE 替換為來源映像檔的網址編碼完整 URI,以便套用至此引導磁碟。

要求主體必須包含這個新磁碟的名稱:

{
    "name": "DISK_NAME"
}

如果您建立的開機磁碟比映像檔大,建議您重新分割開機磁碟

使用快照建立開機磁碟

建立開機磁碟的快照後,您可以使用快照建立新的開機磁碟。

您只能在首次建立磁碟時套用快照中的資料。您無法將快照套用至現有磁碟,也無法將快照套用至所屬專案與這個快照不同的磁碟。

主控台

  1. 前往 Google Cloud 控制台中的「Create a disk」(建立磁碟) 頁面。

    前往「Create a disk」(建立磁碟) 頁面

  2. 在「Disk source type」(磁碟來源類型) 下方,選取「Snapshot」(快照)

  3. 從清單中選擇快照。

  4. 完成磁碟屬性的設定,然後按一下「建立」

gcloud

如要套用磁碟快照中的資料,請執行下列指令:

gcloud compute disks create DISK_NAME --source-snapshot SNAPSHOT_NAME

REST

如要透過快照建立開機磁碟,請對 disks.insert 方法發出 POST 要求:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_NAME/zones/ZONE/disks

要求主體必須包含這個新磁碟的名稱,以及建立磁碟時要使用的快照網址:

{
    "name": "DISK_NAME",
    "sourceSnapshot": "zones/ZONE/snapshots/SNAPSHOT_NAME"
}

後續步驟