Create and manage regional Persistent Disk volumes
Stay organized with collectionsSave and categorize content based on your preferences.
Regional Persistent Diskis a
storage option that lets you implement high availability (HA) services in
Compute Engine. Regional Persistent Disk synchronously replicates data
between two zones in the same region and ensures HA for disk data for up to one
zonal failure. You can use regional Persistent Disk with your virtual machine (VM)
in one of the following ways:
If you haven't already, set up authentication.Authenticationis
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 as follows.
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
Installthe Google Cloud CLI, theninitializeit by running the following command:
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.
You can attach regional Persistent Disk only to VMs that useE2,N1,N2, andN2Dmachine types.
You cannot create a regional Persistent Disk from an image.
When using read-only mode, you can attach a regional balanced Persistent Disk to a maximum of 10
VM instances.
The minimum size of a regional standard Persistent Disk is 200 GiB.
You can only increase the size of a regional Persistent Disk volume; you can't decrease its size.
Regional Persistent Disk volumes have different performance characteristics than zonal Persistent Disk
volumes. For more information, seeBlock storage performance.
If you create a regional Persistent Disk by cloning a zonal disk, then the two zonal replicas
aren't fully in sync at the time of creation. After creation, you can use the regional disk
clone within 3 minutes, on average. However, you might need to wait for tens of minutes
before the disk reaches a fully replicated state and therecovery point objective (RPO)is close to zero. Learn how tocheck if your regional Persistent Disk is fully replicated.
Create a new VM with regional Persistent Disk
When creating a VM, you can optionally include regional Persistent Disk volumes as
additional disks.
Create a regional Persistent Disk volume and attach it to a VM.
The VM must be in the same region as your disks.
If you create a disk in the Google Cloud console, the defaultdisk typeispd-balanced. If you create a disk using the gcloud CLI or
REST, the default disk type ispd-standard.
Permissions required for this task
To perform this task, you must have the followingpermissions:
compute.disks.createon the project, to be able to create
a new disk
compute.instances.attachDiskon the VM
compute.disks.useon the disk to attach
Console
You must first create the regional Persistent Disk volume and then attach it to
an existing VM instance. You can't create regional Persistent Disk volumes as
boot disks because they can't be force-attached during a failover.
Choose the regional Persistent Disk to add to your VM.
If you see a warning that indicates the selected disk is already attached
to another instance, select theForce-attach diskbox to
force-attach the disk to the VM that you are currently editing.
Create and attach a regional Persistent Disk volume by using theGoogle Cloud CLI:
Create a regional Persistent Disk volume by using thecompute disks createcommand.
If you need a regional SSD Persistent Disk for additional
throughput or IOPS, include the--typeflag and specifypd-ssd.
resource "google_compute_region_disk" "regiondisk" {
name = "region-disk-name"
snapshot = google_compute_snapshot.snapdisk.id
type = "pd-ssd"
region = "us-central1"
physical_block_size_bytes = 4096
size = 11
replica_zones = ["us-central1-a", "us-central1-f"]
}
REST
To create a regional Persistent Disk volume, construct aPOSTrequest to thecompute.regionDisks.insertmethod.
To create a blank disk, don't specify any image or snapshot sources.
REGION: the region for the regional disk
to reside in, for example:europe-west1
DISK_NAME: the name of the new disk
ZONE1,ZONE2: the
zones where replicas of the new disk should be located
DISK_SIZE: the size, in GiB, of the new disk
DISK_TYPE: thetypeof the Persistent Disk. The
default value ispd-standard.
To attach the disk, construct aPOSTrequest to thecompute.instances.attachDiskmethodand include the URL to the Persistent Disk volume that you created.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/attachDisk
{
"source": "/projects/PROJECT_ID/regions/REGION/disks/DISK_NAME"
}
Replace the following:
PROJECT_ID: your project ID
ZONE: the location of your VM
VM_NAME: the name of the VM
to which you're adding the new Persistent Disk volume
REGION: the region where the regional disk
is located
DISK_NAME: the name of the new disk
After you create and attach a new disk to a VM, you mustformat and mount the disk,
so that the operating system can use the available storage space.
Use regional Persistent Disk as a VM boot disk
Attach a regional Persistent Disk as a boot disk for stateful workloads that are
provisioned ahead of time, before you provision a production workload. Regional
Persistent Disk is not intended for hot standbys, because regional boot disks cannot
be attached simultaneously to two VMs.
You can only create regional Persistent Disk from snapshots; it is not possible to
create a regional Persistent Disk from an image.
To use a regional Persistent Disk as a VM boot disk:
Attach the disk as a boot disk using the following instructions.
Create a new VM with regional Persistent Disk boot disks
When setting up a highly available VM, you can create the primary VM with
regional Persistent Disk boot disks. This lets you restart the VM in case of
a zonal outage.
In a high availability setup, where the boot device is a regional Persistent Disk,
Google recommends that you don't pre-create and pre-run the standby instance.
Instead, at the failover stage, attach the existing regional disk when you
create the standby instance by using theforceAttachoption.
To create a VM with a boot disk that is a regional Persistent Disk:
When specifying the disk parameters, the characters^:^specify
that the separation character between parameters is a colon (:). This
lets you use a comma (,) when specifying the replica-zones parameter.
Replace the following:
PRIMARY_INSTANCE_NAMEwith a name for the VM
ZONEwith the name of the zone where you want to create the
VM
REPD_DISK_NAMEwith a name for the regional Persistent Disk
SNAPSHOT_NAMEwith the name of the snapshot you created for
the boot disk
REMOTE_ZONEwith the alternate zone for the regional
Persistent Disk
REST
To create a new VM with regional disk duringVM creation, specifyboot: 'true'andreplicaZones. For example:
ZONEwith the name of the zone where the
regional Persistent Disk is replicated to
DISK_NAMEwith the name of the regional
Persistent Disk that you want to attach.
Optional: If you can't successfully detach the regional Persistent Disk boot disk
from the VM that it was originally attached to due to an outage or failure,
includeforce-attach=true.
Attach a regional Persistent Disk as a boot disk to an existing VM
Use the following steps to failover to a secondary VM that is running in the
backup zone, by attaching the regional Persistent Disk to the VM as the boot disk.
These steps assume you have already created the regional Persistent Disk from a
standard snapshot.
Replace the variables in the previous commands with the following:
STANDBY_VM_NAME: the name of the VM to which
you want to attach the regional Persistent Disk
ZONE: the zone in which the VM is located
CURRENT_BOOT_DEVICE_NAME: the name of the boot
disk being used by the VM. This is usually the same as the name of
the VM.
REPD_DISK_NAME: the name of the regional
Persistent Disk that you want to attach to the VM as a boot disk
Optional: If you can't successfully detach the regional Persistent Disk boot disk
from the VM that was originally attached to due to an outage or failure,
include the flag--force-attach.
REST
Stop the VM.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/STANDBY_VM_NAME/stop
Detach the current boot disk from the VM.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/STANDBY_VM_NAME/detachDisk?deviceName=CURRENT_BOOT_DEVICE_NAME
Attach the regional Persistent Disk to the VM.
Construct aPOSTrequest to thecompute.instances.attachDiskmethod,
and include the URL to the regional Persistent Disk volume:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/STANDBY_VM_NAME/attachDisk
{
"source": "compute/v1/projects/PROJECT_ID/regions/REGION/disks/REPD_DISK_NAME",
"boot": true
}
Restart the VM.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/STANDBY_VM_NAME/start
Replace the variables in the previous commands with the following:
PROJECT_ID: your project ID
STANDBY_VM_NAME: the name of the VM to which
you want to attach the regional Persistent Disk
ZONE: the zone in which the VM is located
CURRENT_BOOT_DEVICE_NAME: the name of the boot
disk being used by the VM. This is usually the same as the name of
the VM.
REGION: the region in which the regional
Persistent Disk is located
REPD_DISK_NAME: the name of the regional
Persistent Disk that you want to attach to the VM as a boot disk
Optional: If you can't successfully detach the regional Persistent Disk boot disk
from the VM that was originally attached to due to an outage or failure,
include"forceAttach": truein the request body.
List and describe your regional Persistent Disk volumes
You can view a list of all your configured regional Persistent Disk volumes, and
information about their properties, including the following:
Disk ID
Disk name
Size
Disk type
Region
Zonal replicas
To view detailed information about your regional Persistent Disk volumes, use one of
the following: REST and the gcloud CLI.
To view the details of all regional Persistent Disk volumes in
a specific region and project, use thecompute.regionDisks.listmethod.
To view the details of a specific regional Persistent Disk volume, run thegcloud compute disks describecommandwith the--regionflag, and specify the name of your disk and its region.
Resize a regional Persistent Disk
If VMs with regional Persistent Disks require additional storage
space, IOPS, or throughput, you can resize the disks. If you need to separate
your data into unique volumes,create multiple secondary disksfor the VM. You can resize disks at any time, regardless of whether the
disk is attached to a running VM.
The command for resizing a regional Persistent Disk is identical to that for
resizing a standard Persistent Disk. However, there is an additional flag for the
region.
You can only increase, and not decrease, the size of a disk. To decrease the
disk size, you must create a new disk with a smaller size. Until you delete the
original, larger disk, you are charged for both disks.
Permissions required for this task
To perform this task, you must have the followingpermissions:
resource "google_compute_region_disk" "regiondisk" {
name = "region-disk-name"
snapshot = google_compute_snapshot.snapdisk.id
type = "pd-ssd"
region = "us-central1"
physical_block_size_bytes = 4096
size = 11
replica_zones = ["us-central1-a", "us-central1-f"]
}
If you include thesizeparameter along with theimageorsnapshotparameter, thesizevalue must be equal to or greater than the size of the
image or snapshot.
If you omit theimageandsnapshotparameters, you can set thesizeparameter to less than the existing disk size. If you do this,
Terraform destroys the disk and creates a new empty Persistent Disk. During
the re-creation, Terraform doesn't copy over other data that isn't also
included in the Terraform configuration, such as labels or snapshot
schedules. To prevent Terraform from destroying and re-creating a disk, you
can add thelifecycle.prevent_destroy = truesettingto the Terraform configuration.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/disks/DISK_NAME/resize
{
"sizeGb": "DISK_SIZE"
}
Replace the following:
PROJECT_ID: your project ID
REGION: the region where your disk is located
DISK_NAME: the name of the disk that you're
resizing
DISK_SIZE: the new size, in GiB, of the disk.
After you resize the disk, you mustresize the file systemso that the operating system can access the additional space.
Share a read-only Persistent Disk between multiple VMs
You can attach a non-boot Persistent Disk to more than one VM
in read-only mode, which lets you share static data between
multiple VMs. Sharing static data between multiple VMs from one
Persistent Disk is cheaper than replicating your data to unique disks for
individual VMs.
If you need to share dynamic storage space between multiple VMs, you can
use one of the following options:
If you have a Persistent Disk with data that you want to share between
multiple VMs, detach it from any read/write VMs and attach it to
one or more VMs in read-only mode.
Permissions required for this task
To perform this task, you must have the followingpermissions:
compute.disks.createon the project to be able to create a
new disk
compute.instances.attachDiskon the VM
compute.disks.usepermission on the disk to attach
Console
Share a read-only Persistent Disk between multiple VMs.
In the Google Cloud console, go to theVM instancespage.
Click the name of the VM to which you want to attach the disk. The
VM instance details page opens.
At the top of the page, clickEdit.
In theAdditional diskssection, clickAttach existing disk.
Select the regional Persistent Disk from the list.
In theModesection, selectRead only.
ClickDone.
At the bottom of page, clickSaveto apply your
changes to the VM.
gcloud
In the gcloud CLI, share a read-only Persistent Disk between multiple VMs by using thecompute instances attach-diskcommandwith the--disk-scopeflag set toregionaland the--modeflag set
toro.
VM_NAME: the name of the VM to which
you want to attach the Persistent Disk
DISK_NAME: the name of the disk that you want
to attach
REST
To share a read-only Persistent Disk between multiple VMs, construct aPOSTrequest to thecompute.instances.attachDiskmethod.
In the request body, specify themodeparameter asREAD_ONLY.
POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/attachDisk
{
"source": "regions/REGION/disks/DISK_NAME",
"mode": "READ_ONLY"
}
Replace the following:
PROJECT_ID: your project ID
ZONE: the zone of the VM
VM_NAME: the name of the VM to which
you want to attach the Persistent Disk.
REGION: the region where your disk is located
DISK_NAME: the name of the disk that you're
attaching
After you attach the disk, connect to each VM to which you want to attach this
disk in read-only mode and then mount the disk.
Migrate a zonal Persistent Disk to a regional Persistent Disk
To convert an existing zonal Persistent Disk to a regional Persistent Disk,
create a new regional disk by cloning an existing zonal disk. For more
information, seeCreating a regional disk clone from a zonal disk.