Working with regional persistent disks

This page explains how to add and manage regional persistent disk storage resources.

Before you begin

Restrictions

  • You can't use a regional persistent disk with a memory-optimized, compute-optimized, or accelerator-optimized machine type VM.
  • You cannot use regional persistent disks as boot disks.
  • You can create a regional persistent disk from a snapshot but not an image.
  • The minimum size of a regional standard persistent disk is 200 GB.
  • When resizing a regional persistent disk, you can only increase its size.
  • Regional persistent disks perform differently from zonal persistent disks. For more information, see Block storage performance.

Check the status of your regional disks

You can check the status of your regional disks by using either of these options:

Add a regional persistent disk to your VM

Create a regional persistent disk and attach it to a VM. If you don't have any VMs, you must first create and start a new VM. The VM must be in the same region as your disks.

If you create a disk in the Cloud Console, the default disk type is pd-balanced. If you create a disk using the gcloud tool or the Compute Engine API, the default disk type is pd-standard.

Console

You must first create the regional persistent disk and then attach it to an existing instance. You can't create regional persistent disks as boot disks because they can't be force-attached during a failover.

Create a regional persistent disk.

  1. In the Google Cloud Console, go to the Disks page.

    Go to Disks

  2. Select the required project.

  3. Click Create disk.

  4. Specify a Name for your disk.

  5. Select the Region and Zone. You must select the same region when you create your VM.

  6. Select the Enable regional disk replication box.

  7. Select the Replicate zone. Make a note of the zones that you select because you must attach the disk to your VM in one of those zones.

  8. Select the Disk source type.

  9. Select the Disk type.

  10. Click Create to finish creating your disk.

After you create your regional persistent disk, attach it to your instance.

When attaching a disk to a VM, if the disk is already attached to another VM, you can force-attach the disk to the VM by selecting the Force-attach disk box on the Attach existing disk page. For more information on use cases for force-attaching regional persistent disks, see Regional persistent disk failover.

gcloud

Create and attach a regional persistent disk by using the gcloud command-line tool:

  1. In the gcloud tool, create a regional persistent disk by using the compute disks create command. If you need a regional SSD persistent disk for additional throughput or IOPS, include the --type flag and specify pd-ssd.

    gcloud compute disks create DISK_NAME \
        --size=DISK_SIZE \
        --type=DISK_TYPE \
        --region=REGION \
        --replica-zones=ZONE1,ZONE2
    

    Replace the following:

    • DISK_NAME: the name of the new disk
    • DISK_SIZE: the size, in GB, of the new disk
    • DISK_TYPE: the type of the persistent disk, for example, pd-ssd
    • REGION: the region for the regional disk to reside in, for example: europe-west1
    • ZONE1,ZONE2: the zones within the region where the two disk replicas are located, for example: europe-west1-a,europe-west1-b
  2. Attach the disk to a running or stopped VM by using the compute instances attach-disk command with the --disk-scope flag set to regional.

    gcloud compute instances attach-disk INSTANCE_NAME \
        --disk=DISK_NAME \
        --disk-scope=regional
    

    Replace the following:

    • INSTANCE_NAME: the name of the VM to which you're adding the new regional persistent disks
    • DISK_NAME: the name of the new disk that you're attaching to the VM

API

  1. In the API, to create a regional persistent disk, construct a POST request to the compute.regionDisks.insert method. To create a blank disk, don't specify any image or snapshot sources.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/disks
    
    {
     "name": "DISK_NAME",
     "replicaZones": [
       "projects/PROJECT_ID/zones/ZONE1",
       "projects/PROJECT_ID/zones/ZONE2"
     ],
    }
    

    Replace the following:

    • PROJECT_ID: your project ID
    • DISK_NAME: the name of the new disk
    • ZONE1,ZONE2: the zones where replicas of the new disk should be located
  2. To attach the disk, construct a POST request to the compute.instances.attachDisk method and include the URL to the persistent disk that you created.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_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
    • INSTANCE_NAME: the name of the VM to which you're adding the new persistent disk
    • DISK_NAME: the name of the new disk

After you create and attach a new disk to a VM, you must format and mount the disk, so that the operating system can use the available storage space.

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 disks for 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.

Console

Resize a regional persistent disk.

  1. In the Google Cloud Console, go to the Disks page.

    Go to Disks

  2. Select the disk you want to resize.

  3. Click Edit at the top of the page.

  4. Enter the size, in GB, for the disk.

    You can only increase, and not decrease, the size of the disk.

  5. Click Save to finish resizing the disk.

The new disk size is displayed in the list of disks.

gcloud

In the gcloud tool, resize the regional persistent disk by using the compute disks resize command.

gcloud compute disks resize DISK_NAME \
    --region=REGION  \
    --size=DISK_SIZE

Replace the following:

  • DISK_NAME: the name of the disk that you're resizing
  • REGION: the region where the disk is located
  • DISK_SIZE: the new size, in GB, of the disk.

API

In the API, to resize the regional persistent disk, construct a POST request to the compute.regionDisks.resize method.

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 GB, of the disk.

After you resize the disk, you must resize the file system so 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.

Console

Share a read-only persistent disk between multiple VMs.

  1. In the Google Cloud Console, go to the VM instances page.

    Go to VM instances

  2. Click the name of the VM to which you want to attach the disk. The VM instance details page opens.

  3. At the top of the page, click Edit.

  4. In the Additional disks section, click Attach existing disk.

  5. Select the regional persistent disk from the list.

  6. In the Mode section, select Read only.

  7. Click Done.

  8. At the bottom of page, click Save to apply your changes to the VM.

gcloud

In the gcloud tool, share a read-only persistent disk between multiple VMs by using the compute instances attach-disk command with the --disk-scope flag set to regional and the --mode flag set to ro.

gcloud beta compute instances attach-disk INSTANCE_NAME \
    --disk=DISK_NAME \
    --disk-scope=regional \
    --mode=ro

Replace the following:

  • INSTANCE_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

API

In the API, share a read-only persistent disk between multiple VMs, construct a POST request to the compute.instances.attachDisk method. In the request body, specify the mode parameter as READ_ONLY.

POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_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
  • INSTANCE_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 add this disk in read-only mode and mount the disk.

Migrate a zonal persistent disk to a regional persistent disk

To convert your existing zonal persistent disks to regional persistent disks, snapshot the current persistent disk and create a regional persistent disk from the snapshot.

gcloud

Migrate a zonal persistent disk to regional by using the gcloud command-line tool:

  1. In the gcloud tool, snapshot the current persistent disk by using the compute disks snapshot command.

    gcloud compute disks snapshot DISK_NAME \
        --zone=ZONE \
        --snapshot-names=SNAPSHOT_DISK_NAME
    

    Replace the following:

    • DISK_NAME: the name of the disk you want to snapshot
    • ZONE: where your source zonal disk is located
    • SNAPSHOT_DISK_NAME: the name of the newly snapshotted disk
  2. Create a regional disk from a snapshot of the zonal disk by using the compute disks create command.

    gcloud compute disks create DISK_NAME \
       --region=REGION \
       --replica-zones=ZONE1,ZONE2 \
       --source-snapshot=SNAPSHOT_DISK_NAME
    

    Replace the following:

    • DISK_NAME: the name of the new disk
    • REGION: the region for the disk to reside in
    • ZONE1,ZONE2: the zones for the replicas of the new regional persistent disks to reside in
    • SNAPSHOT_DISK_NAME: the name of the source snapshot disk

You can use the same method to migrate regional disks to zonal disks.

API

  1. In the API, to snapshot the current persistent disk, construct a POST request to the compute.disk.createSnapshot method.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/disks/DISK_NAME/createSnapshot
    

    Replace the following:

    • PROJECT_ID: your project ID
    • ZONE: the zone where your disk is located
    • DISK_NAME: the name of the disk that you're snapshotting
  2. To create a regional disk from a snapshot of the zonal disk, construct a POST request to the compute.regionDisks.insert method. Because this is a data disk, don't include the sourceImage property, which creates a blank disk.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/disks
    
    {
     "name": "DISK_NAME",
     "sourceSnapshot": "global/snapshots/SNAPSHOT_NAME",
     "replicaZones": [
       "projects/PROJECT_ID/zones/ZONE1",
       "projects/PROJECT_ID/zones/ZONE2"
     ],
    }
    

    Replace the following:

    • PROJECT_ID: your project ID
    • REGION: the region for the disk to reside in
    • DISK_NAME: the name of the new disk
    • SNAPSHOT_NAME: the snapshot to restore
    • ZONE1,ZONE2: the zones for the replicas of the new regional persistent disks to reside in

What's next