您可以建立空白的永久磁碟區,或是從資料來源建立磁碟。 您可以將永久磁碟做為虛擬機器 (VM) 執行個體的開機磁碟,或是連結至 VM 的資料磁碟。
本文說明如何建立空白的非開機區域永久磁碟磁碟區,並將其連結至 VM。
如要瞭解其他磁碟的建立和新增方式,請參閱下列文章:
如要建立開機磁碟,以便日後建立 VM,請參閱「建立自訂開機磁碟」。
如要將 Google Cloud Hyperdisk 磁碟新增至 VM,請參閱「為 VM 新增 Hyperdisk 儲存空間」。
如要將磁碟新增至代管執行個體群組 (MIG) 中的 VM,請參閱「更新 MIG 中的 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
-
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.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
- 建立 VM 時,您最多可以連結 127 個次要非開機區域永久磁碟磁碟區。
- 每個 VM 的總連接容量為 257 TB。如要瞭解如何使用大型磁碟區來提高效能,請參閱「邏輯磁碟區大小」一文。
前往「VM instances」(VM 執行個體) 頁面。
按一下要新增磁碟的 VM 名稱。
在詳細資料頁面中,按一下「編輯」。
在「Additional disks」(其他磁碟) 下方,點選 [Add new disk] (增加新磁碟)。
指定磁碟的名稱,設定磁碟的屬性,然後選取「空白」做為「來源類型」。
選用:在「裝置名稱」標題下方,選取「使用自訂裝置名稱」選項。您輸入的名稱會用於產生磁碟的符號連結,方便識別磁碟。
按一下[Done] (完成) 即可完成磁碟的設定。
按一下「儲存」,將變更套用到 VM 並新增磁碟。
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
使用
gcloud compute disks create
指令建立區域永久磁碟卷宗。gcloud compute disks create DISK_NAME \ --size DISK_SIZE \ --type DISK_TYPE
更改下列內容:
DISK_NAME
:新磁碟的名稱。DISK_SIZE
:新磁碟的大小 (以 GB 為單位)。可接受的大小範圍為 10 GB 到 65,536 GB (含首尾),調整的單位為 1 GB。DISK_TYPE
:永久磁碟區的類型完整或部分網址。例如:https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/diskTypes/pd-ssd
。
建立磁碟之後,請將其連接至任何執行中或已停止的 VM。使用
gcloud compute instances attach-disk
指令:gcloud compute instances attach-disk VM_NAME \ --disk DISK_NAME --device-name=DEVICE_NAME
更改下列內容:
VM_NAME
:要新增區域永久磁碟卷宗的 VM 名稱DISK_NAME
:要連結至 VM 的新磁碟名稱。DEVICE_NAME
:(選用) 客體 OS 用來識別磁碟的名稱。
使用
gcloud compute disks describe
指令查看磁碟說明。使用
disks.insert
方法建構POST
要求,以建立區域永久磁碟。請包含name
、sizeGb
和type
屬性。如要將這個磁碟建立為空白且未格式化的非開機磁碟,請勿指定來源映像檔或來源快照。POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks { "name": "DISK_NAME", "sizeGb": "DISK_SIZE", "type": "DISK_TYPE" }
更改下列內容:
PROJECT_ID
:您的專案 ID。ZONE
:VM 和新磁碟所在的可用區。DISK_NAME
:新磁碟的名稱。DISK_SIZE
:新磁碟的大小 (以 GB 為單位)。可接受的大小範圍為 10 GB 到 65,536 GB (含首尾),調整的單位為 1 GB。DISK_TYPE
:永久磁碟類型的完整或部分網址。例如:https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/diskTypes/pd-ssd
。
對
compute.instances.attachDisk
方法建構 POST 要求,並包含您剛建立的區域永久磁碟磁碟區的網址:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/attachDisk { "source": "/compute/v1/projects/PROJECT_ID/zones/ZONE/disks/DISK_NAME", "deviceName": DEVICE_NAME }
更改下列內容:
PROJECT_ID
:您的專案 IDZONE
:VM 和新磁碟所在的可用區VM_NAME
:要新增永久磁碟磁碟區的 VM 名稱DISK_NAME
:新磁碟的名稱DEVICE_NAME
:(選用) 客體 OS 用來識別磁碟的名稱。
- 瞭解如何在 Linux VM 上格式化及掛接新磁碟。
- 瞭解如何在 Windows VM 上格式化及掛接新磁碟。
- 瞭解如何調整永久磁碟磁碟區的大小。
- 瞭解如何使用快照定期備份磁碟,以免不慎遺失資料。
- 瞭解地區永久磁碟,這類磁碟可在兩個區域之間提供同步複製功能。
Terraform
如要在本機開發環境中使用本頁的 Terraform 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Set up authentication for a local development environment。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 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.
詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。
限制
將非開機磁碟新增至 VM
使用 Google Cloud console、Google Cloud CLI 或 REST 建立及連結非開機區域磁碟。
永久磁碟類型變數
下表列出各類永續磁碟的參考值。使用 Google Cloud CLI、REST 或 Compute Engine 適用的 Cloud 用戶端程式庫建立永久磁碟卷時,請從下表提供對應值,指明要建立的永久磁碟類型。
如果您在 Google Cloud 控制台中建立磁碟,預設磁碟類型為
pd-balanced
。如果您使用 gcloud CLI 或 REST 建立磁碟,預設磁碟類型為pd-standard
。磁碟類型 參照名稱 已平衡的永久磁碟 pd-balanced
效能型 (SSD) 永久磁碟 pd-ssd
標準永久磁碟 pd-standard
極端永久磁碟 pd-extreme
將磁碟附加至 VM 時,請指定自訂裝置名稱。 您指定的名稱會用於在客體 OS 中產生磁碟的符號連結,方便識別。
主控台
gcloud
Terraform
如要建立磁碟,請使用
google_compute_disk
資源。如要將磁碟連接至 VM,請使用
google_compute_instance
資源。如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。
REST
建立新磁碟並連結至 VM 後,必須格式化並掛接磁碟,作業系統才能使用可用的儲存空間。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-09 (世界標準時間)。
-