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
- If you want to use the command-line examples in this guide:
- Install or update to the latest version of the gcloud command-line tool.
- Set a default region and zone.
- If you want to use the API examples in this guide, set up API access.
- Understand the differences between different types of persistent disks.
- Read about Regional persistent disk failover.
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.
- 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.
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.
In the Google Cloud Console, go to the Disks page.
Select your project.
Click Create disk.
Specify a Name for your disk.
Choose a disk Type.
Select the Replicate this disk within region checkbox.
Select the region.
Make a note of the region because you must select the same region when you create your instance.
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.
Choose the Source type.
Select the Encryption.
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:
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 specifypd-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
.
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 disksDISK_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
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 diskname
andreplicaZones
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 IDDISK_NAME
: the name of the new disk[ZONE1
,ZONE2
: the zones where replicas of the new disk should be located
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 IDZONE
: the location of your instanceINSTANCE_NAME
: the name of the instance where you are adding the new persistent diskDISK_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.
In the Google Cloud Console, go to the Disks page.
Select the disk you want to resize.
Click Edit at the top of the page.
Enter the size, in GB, for the disk.
You can only increase the size of the disk. You cannot decrease a disk's size.
Click Save.
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 resizingREGION
: the region where the disk is locatedDISK_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 IDREGION
: the region where your disk is locatedDISK_NAME
: the name of the disk that you are resizingDISK_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 read-only 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 allows you to 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 need to share dynamic storage space between multiple instances, you can use one of the following options:
- Connect your instances to Cloud Storage.
- Connect your instances to Filestore.
- Create a network file server on Compute Engine.
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
In the Google Cloud Console, go to the VM instances page.
Click the name of the instance where you want to attach the disk. The instance details page opens.
At the top of the instance details page, click Edit.
In the Additional disks section, click Attach existing disk.
Select the regional persistent disk from the list.
In the Mode section, select Read only.
Click Done.
At the bottom of the instance details page, click Save to apply your changes to the instance.
Connect to the instance and mount the disk.
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 diskDISK_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 IDZONE
: the zone of the instanceINSTANCE_NAME
: the name of the instance where you want to attach the persistent disk.REGION
: the region where your disk is locatedDISK_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 snapshotZONE
: where your source zonal disk is locatedSNAPSHOT_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 diskREGION
: the region where the disk will resideZONE1
,ZONE2
: the zones where the replicas of the new regional persistent disks will resideSNAPSHOT_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 IDZONE
: the zone where your disk is locatedDISK_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 IDREGION
: the region where the disk will resideDISK_NAME
: the name of the new diskSNAPSHOT_NAME
: the snapshot to restoreZONE1
,ZONE2
: the zones where the replicas of the new regional persistent disks will reside
What's next
- Learn about persistent disk pricing.
- Learn how to create a snapshot of a persistent disk.
- Use instance groups to create your instances.
- Build scalable and resilient web applications on Google Cloud.
- See the Google Cloud disaster recovery cookbook.