Adding or resizing regional persistent disks

This page explains how to add and manage regional persistent disk storage resources. To check the status of your regional disks, use the compute disks describe DISK_NAME command and include the --region NEW_DISK_REGION flag, or use the compute.regionDisks.list command.

Before you begin

Limitations

Regional persistent disks have the following limitations:

  • Regional persistent disks can't be used 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.
  • You can't use a regional persistent disk with a memory-optimized machine type or a compute-optimized machine type.
  • Regional persistent disks support force attachment to another virtual machine (VM) instance in the event of a zone failure. See failure scenarios.
  • When resizing a regional persistent disk, you can only increase its size. You cannot reduce the size of a persistent disk.
  • There are performance differences from zonal persistent disks. For more information, see Block storage performance.

Adding a regional persistent disk to your instance

Create a regional persistent disk and attach it to an instance. If you do not have any instances, you must first create and start a new instance. You must create your instance in the same region as your disks.

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 your project.

  3. Click Create disk.

  4. Specify a Name for your disk.

  5. Choose a disk Type.

  6. Select the Replicate this disk within region checkbox.

  7. Select the region.

    Make a note of the region because you must select the same region when you create your instance.

  8. Select two zones in that region, and click OK.

    You must select two zones. Make a note of the zones that you select because you must attach the disk to your instance in one of those zones.

  9. Choose the Source type.

  10. Select the Encryption.

  11. Click Create to finish creating your disk.

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

When attaching a disk to an instance, you might receive an error message if the disk is already attached to another instance. You might have to force-attach the disk to the instance by checking the Force-attach disk box after you click Attach existing disk.

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

gcloud

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

  1. To create regional persistent disk, use 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 where the regional disk will reside. Example: europe-west1.
    • ZONE1,ZONE2: the zones within the region where the two disk replicas are located.
      You must select two zones. Example: europe-west1-a,europe-west1-b.
  2. After you create the disk, attach it to any running or stopped instance. Use the compute instances attach-disk command and include the --disk flag.

    gcloud compute instances attach-disk INSTANCE_NAME \
        --disk DISK_NAME
    

    Replace the following:

    • INSTANCE_NAME: the name of the instance where you are adding the new regional persistent disks
    • DISK_NAME: the name of the new disk that you are attaching to the instance

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

API

  1. In the API, construct a POST request to create a regional persistent disk. In the compute.regionDisks.insert request body, initialize a new disk with a disk name and replicaZones properties. To create a blank disk, do not 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. In the API, construct a POST request to the compute.instances.attachDisk method, and include the URL to the persistent disk that you just 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 instance
    • INSTANCE_NAME: the name of the instance where you are adding the new persistent disk
    • DISK_NAME: the name of the new disk

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

Resizing a regional persistent disk

If instances 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 instance. You can resize disks at any time, regardless of whether the disk is attached to a running instance.

The command for resizing a regional persistent disk is identical to that of resizing a standard persistent disk, however there is an additional flag for the region.

Console

Resizing 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 the size of the disk. You cannot decrease a disk's size.

  5. Click Save.

  6. After you resize the disk, you must resize the file system so that the operating system can access the additional space.

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

gcloud

In the gcloud tool, use the compute disks resize command. Specify the --size flag with the disk size, in GB, that you want and the --region flag with the region where the disk is located.

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

Replace the following:

  • DISK_NAME: the name of the disk that you are resizing
  • REGION: the region where the disk is located
  • 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.

API

In the API, construct a POST request to the compute.regionDisks.resize method. In the request body, specify the sizeGb parameter and set it to the disk size, in GB, that you want.

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 are 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.

Sharing a regional persistent disk between multiple instances

You can attach a non-boot persistent disk to more than one virtual machine instance in read-only mode, which lets you share static data between multiple instances. Sharing static data between multiple instances from one persistent disk is cheaper than replicating your data to unique disks for individual instances.

If you attach a persistent disk to multiple instances, all of those instances must attach the persistent disk in read-only mode. It is not possible to attach the persistent disk to multiple instances in read/write mode. If you need to share dynamic storage space between multiple instances, you can use one of the following options:

If you have a persistent disk with data that you want to share between multiple instances, detach it from any read/write instances and attach it to one or more instances in read-only mode.

Console

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

    Go to Instances

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

  3. At the top of the instance details 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 the instance details page, click Save to apply your changes to the instance.

  9. Connect to the instance and mount the disk.

  10. Repeat this process to add the disk to other instances in read-only mode.

gcloud

In the gcloud tool, use the compute instances attach-disk command and specify the --mode flag with the ro option.

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 instance where you want to attach the persistent disk
  • DISK_NAME: the name of the disk that you want to attach

After you attach the disk, connect to the instance and mount the disk.

Repeat this command for each instance where you want to add this disk in read-only mode.

API

In the API, 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 instance
  • INSTANCE_NAME: the name of the instance where you want to attach the persistent disk.
  • REGION: the region where your disk is located
  • DISK_NAME: the name of the disk that you are attaching

After you attach the disk, connect to the instance and mount the disk.

Repeat this request for each instance where you want to add this disk in read-only mode.

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

In the gcloud tool, use the compute disks snapshot command and specify the --zone flag and --snapshot-names flag.

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

Create a regional disk from a snapshot of the zonal disk using compute disks create. Specify the disk name, the --region, --replica-zones, and --source-snapshot flags.

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 where the disk will reside
  • ZONE1,ZONE2: the zones where the replicas of the new regional persistent disks will reside
  • SNAPSHOT_DISK_NAME: the name of the source snapshot disk

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

API

In the API, construct a POST request to the compute.disk.createSnapshot method to create a snapshot of a disk. In the request body, specify the zone where the disk resides, the name of the disk you are snapshotting, and createSnapshot.

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 are snapshotting

In the API, construct a POST request to create a regional persistent disk. In the compute.regionDisks.insert request body, initialize a new disk and specify the disk name and replica-zones properties. Because this is a data disk, do not 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 where the disk will reside
  • DISK_NAME: the name of the new disk
  • SNAPSHOT_NAME: the snapshot to restore
  • ZONE1,ZONE2: the zones where the replicas of the new regional persistent disks will reside

What's next