You can either create a blank Persistent Disk volume, or create a disk from a data source. You can use Persistent Disk as a boot disk for a virtual machine (VM) instance, or as a data disk that you attach to a VM.
This document explains how to create a blank, non-boot zonal Persistent Disk volume and attach it to your VM.
For other types of disk creation and addition, see the following:
To create a boot disk that you can later use to create a VM, see Create a customized boot disk.
To add a Google Cloud Hyperdisk disk to your VM, see Add Hyperdisk storage to a VM.
To add a disk to a VM that is part of a managed instance group (MIG), see Updating VM configuration in a MIG.
Before you begin
-
If you haven't already, then set up authentication.
Authentication is
the process by which your identity is verified for access to Google Cloud services and APIs.
To run code or samples from a local development environment, you can authenticate to
Compute Engine by selecting one of the following options:
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
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
Terraform
To use the Terraform samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
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.
For more information, see Set up authentication for a local development environment.
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.
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
Restrictions
- During VM creation, you can attach up to 127 secondary non-boot zonal Persistent Disk volumes.
- You can have a total attached capacity of 257 TB per VM. For information about how to ensure maximum performance with large volumes, see Logical volume size.
Adding a non-boot disk to your VM
Create and attach a non-boot zonal disk by using the Google Cloud console, the Google Cloud CLI, or REST.
If you create a disk in the Google Cloud console, the default
disk type is pd-balanced
. If you
create a disk using the gcloud CLI or
REST, the default disk type is pd-standard
.
You should specify a custom device name when attaching the disk to a VM. The name you specify is used to generate a symlink for the disk in the guest OS, making identification easier.
Console
Go to the VM instances page.
Click the name of the VM where you want to add a disk.
On the details page, click Edit.
Under Additional disks, click Add new disk.
Specify a name for the disk, configure the disk's properties, and select Blank as the Source type.
Optional: Under the heading Device name, select the option Use a custom device name. The name you enter is used to generate a symlink for the disk, which makes disk identification easier.
Click Done to complete the disk's configuration.
Click Save to apply your changes to the VM and add the new disk.
gcloud
-
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.
Use the
gcloud compute disks create
command to create the zonal Persistent Disk volume.gcloud compute disks create DISK_NAME \ --size DISK_SIZE \ --type DISK_TYPE
Replace the following:
DISK_NAME
: the name of the new disk.DISK_SIZE
: the size, in gigabytes, of the new disk. Acceptable sizes range, in 1 GB increments, from 10 GB to 65,536 GB inclusive.DISK_TYPE
: full or partial URL for the type of the Persistent Disk volume. For example,https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/diskTypes/pd-ssd
.
After you create the disk, attach it to any running or stopped VM. Use the
gcloud compute instances attach-disk
command:gcloud compute instances attach-disk VM_NAME \ --disk DISK_NAME --device-name=DEVICE_NAME
Replace the following:
VM_NAME
: the name of the VM where you are adding the new zonal Persistent Disk volumeDISK_NAME
: the name of the new disk that you are attaching to the VM.DEVICE_NAME
: Optional: a name that the guest OS uses to identify the disk.
Use the
gcloud compute disks describe
command to see a description of your disk.
Terraform
To create a disk, use the google_compute_disk
resource.
To attach the disk to a VM, use the google_compute_instance
resource.
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
REST
Construct a
POST
request to create a zonal Persistent Disk by using thedisks.insert
method. Include thename
,sizeGb
, andtype
properties. To create this disk as an empty and unformatted non-boot disk, don't specify a source image or a source snapshot.POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks { "name": "DISK_NAME", "sizeGb": "DISK_SIZE", "type": "DISK_TYPE" }
Replace the following:
PROJECT_ID
: your project ID.ZONE
: the zone where your VM and new disk are located.DISK_NAME
: the name of the new disk.DISK_SIZE
: the size, in gigabytes, of the new disk. Acceptable sizes range, in 1 GB increments, from 10 GB to 65,536 GB inclusive.DISK_TYPE
: full or partial URL for the type of Persistent Disk. For example,https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/diskTypes/pd-ssd
.
Construct a POST request to the
compute.instances.attachDisk
method, and include the URL to the zonal Persistent Disk volume that you just created: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 }
Replace the following:
PROJECT_ID
: your project IDZONE
: the zone where your VM and new disk are locatedVM_NAME
: the name of the VM where you are adding the new Persistent Disk volumeDISK_NAME
: the name of the new diskDEVICE_NAME
: Optional: a name that the guest OS uses to identify the disk.
After you create the new disk and attach it to a VM, you must format and mount the disk, so that the operating system can use the available storage space.
What's next
- Learn how to format and mount your new disks on a Linux VM.
- Learn how to format and mount your new disks on a Windows VM.
- Learn how to resize your Persistent Disk volumes.
- Learn how to regularly back up your disks using snapshots to prevent unintended data loss.
- Learn about regional Persistent Disk, which provide synchronous replication between two zones.