Duplicate a disk with clones (original) (raw)

Skip to main content

Duplicate a disk with clones

Stay organized with collections Save and categorize content based on your preferences.


This document provides information about how disk clones work and how to create a disk clone. Disk cloning lets you make instantly usable duplicates of existing disks. Create a disk clone in scenarios where you want to create an identical copy of an existing disk that you can instantly attach to a VM, such as the following:

To protect against disaster recovery, back up your disk withstandard snapshots instead of using disk clones. To capture disk contents at regular intervals without creating new disks, use instant snapshots because they're more storage-efficient than clones. For additional disk protection options, see Data protection options.

Before you begin

Console

When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

gcloud

  1. After installing the Google Cloud CLI,initialize it by running the following command:
    gcloud init
    If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  2. 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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. To initialize the gcloud CLI, run the following command:
    gcloud init
  4. 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.
    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
    For more information, see Set up authentication for a local development environment.

Go

To use the Go 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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. To initialize the gcloud CLI, run the following command:
    gcloud init
  4. 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.
    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
    For more information, see Set up authentication for a local development environment.

Java

To use the Java 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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. To initialize the gcloud CLI, run the following command:
    gcloud init
  4. 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.
    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
    For more information, see Set up authentication for a local development environment.

Python

To use the Python 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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. To initialize the gcloud CLI, run the following command:
    gcloud init
  4. 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.
    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
    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.
After installing the Google Cloud CLI,initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, seeAuthenticate for using REST in the Google Cloud authentication documentation.

How disk cloning works

When you clone a disk, you create a new disk that contains all the data on the source disk. You can create a disk clone even if the existing disk is attached to a VM instance.

The disk type of the clone must be the same as that of the source disk. However, you can modify properties on the clone, such as the disk size. You can also delete the source disk without any risk of deleting the clone.

Supported disk types

You can create disk clones only for the following disk types:

Restrictions

Depending on the type of disk, disk clones have the following restrictions:

General restrictions

The following restrictions apply to clones of all disk types:

Restrictions for Persistent Disk clones

Disk clones for Persistent Disk have the following restrictions:

Restrictions for Google Cloud Hyperdisk clones

Error messages

If you exceed the cloning frequency limits, the request fails with the following error:

RATE LIMIT: ERROR: (gcloud.compute.disks.create) Could not fetch resource:

Create disk clones

This section explains how you can duplicate an existing disk and create a disk clone.

For detailed steps, depending on the type of disk clone creation, see one of the following sections in this document:

Permissions required for this task

To perform this task, you must have the followingpermissions:

Create a zonal disk clone

You can create zonal disk clones of an existing disk in the same zone as the source disk by using the Google Cloud console, the Google Cloud CLI, or REST.

Console

  1. In the Google Cloud console, go to the Disks page.
    Go to Disks
  2. In the list of disks, navigate to the disk that you want to clone.
  3. In the Actions column, click the menu button and select Clone disk.
    Create clone.
    In the Clone disk panel that appears, do the following:
    1. In the Name field, specify a name for the cloned disk.
    2. For Location, verify that Single zone is selected.
    3. Under Properties, review other details for the cloned disk.
    4. To finish creating the cloned disk, click Create.

gcloud

To clone a zonal source disk and create a new zonal disk, run thedisks create commandand specify the --source-disk flag:

gcloud compute disks create TARGET_DISK_NAME
--description="cloned disk"
--source-disk=projects/PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME

Replace the following:

Terraform

To create a disk clone, use the google_compute_disk resource.

To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.

Go

Go

Before trying this sample, follow the Go setup instructions in theCompute Engine quickstart using client libraries. For more information, see theCompute Engine Go API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Java

Java

Before trying this sample, follow the Java setup instructions in theCompute Engine quickstart using client libraries. For more information, see theCompute Engine Java API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Python

Python

Before trying this sample, follow the Python setup instructions in theCompute Engine quickstart using client libraries. For more information, see theCompute Engine Python API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

REST

To clone a zonal source disk and create a new zonal disk, make a POSTrequest to thecompute.disks.insert method. In the request body, specify the name and sourceDisk parameters. The disk clone inherits all omitted properties from the source disk.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks

{ "name": "TARGET_DISK_NAME" "sourceDisk": "projects/PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME" }

Replace the following:

Create a regional disk clone from a zonal disk

You can create a new regional Persistent Disk disk by cloning an existing zonal Persistent Disk volume. To migrate a zonal disk to a regional disk, Google recommends this option instead of creating a snapshot of the zonal disk and restoring the snapshot to a new regional disk.

Console

  1. In the Google Cloud console, go to the Disks page.
    Go to Disks
  2. In the list of disks, navigate to the zonal Persistent Disk volume that you want to clone.
  3. In the Actions column, click the menu button and select Clone disk.
    Create clone.
    In the Clone disk panel that appears, do the following:
    1. In the Name field, specify a name for the cloned disk.
    2. For Location, select Regional and then select the secondary replica zone for the new regional cloned disk.
    3. Under Properties, review other details for the cloned disk.
    4. To finish creating the cloned disk, click Create.

gcloud

To create a regional disk clone from a zonal disk, run thegcloud compute disks create commandand specify the --region and --replica-zones parameters.

gcloud compute disks create TARGET_DISK_NAME
--description="zonal to regional cloned disk"
--region=CLONED_REGION
--source-disk=SOURCE_DISK_NAME
--source-disk-zone=SOURCE_DISK_ZONE
--replica-zones=SOURCE_DISK_ZONE,REPLICA_ZONE_2
--project=PROJECT_ID

Replace the following:

Terraform

To create a regional disk clone from a zonal disk, you can optionally create a snapshot of the zonal disk and then clone the snapshot. To do this, use the following resources:

To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.

Go

Go

Before trying this sample, follow the Go setup instructions in theCompute Engine quickstart using client libraries. For more information, see theCompute Engine Go API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Java

Java

Before trying this sample, follow the Java setup instructions in theCompute Engine quickstart using client libraries. For more information, see theCompute Engine Java API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Python

Python

Before trying this sample, follow the Python setup instructions in theCompute Engine quickstart using client libraries. For more information, see theCompute Engine Python API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

REST

To create a regional disk clone from a zonal disk, make a POST request to the compute.disks.insert methodand specify the sourceDisk and replicaZone parameters.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/CLONED_REGION/disks

{ "name": "TARGET_DISK_NAME" "sourceDisk": "projects/PROJECT_ID/zones/SOURCE_DISK_ZONE/disks/SOURCE_DISK_NAME" "replicaZone": "SOURCE_DISK_ZONE,REPLICA_ZONE_2" }

Replace the following:

Create a disk clone of an encrypted source disk

You can use acustomer-supplied encryption key (CSEK)or a customer-managed encryption keyto encrypt your disks.

Create disk clones for CSEK-encrypted disks

If you use a CSEK to encrypt your source disk, you must also use the same key to encrypt the clone.

Console

  1. In the Google Cloud console, go to the Disks page.
    Go to Disks
  2. In the list of zonal persistent disks, find the disk that you want to clone.
  3. In the Actions column, click the menu button and select Clone disk.
    Create clone.
    In the Clone disk panel that appears, do the following:
    1. In the Name field, specify a name for the cloned disk.
    2. In the Decryption and encryption field, provide the source disk encryption key.
    3. Under Properties, review other details for the cloned disk.
    4. To finish creating the cloned disk, click Create.

gcloud

To create a disk clone for a CSEK-encrypted source disk, run thegcloud compute disks create commandand provide the source disk encryption key using the --csek-key-fileflag. If you are using an RSA-wrapped key, use thegcloud beta compute disks create command.

gcloud compute disks create TARGET_DISK_NAME
--description="cloned disk"
--source-disk=projects/PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME
--csek-key-file example-key-file.json

Replace the following:

Go

Go

Before trying this sample, follow the Go setup instructions in theCompute Engine quickstart using client libraries. For more information, see theCompute Engine Go API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Java

Java

Before trying this sample, follow the Java setup instructions in theCompute Engine quickstart using client libraries. For more information, see theCompute Engine Java API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Python

Python

Before trying this sample, follow the Python setup instructions in theCompute Engine quickstart using client libraries. For more information, see theCompute Engine Python API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

REST

To create a disk clone for a CSEK-encrypted source disk, make a POST request to the compute.disks.insert methodand provide the source disk encryption key using the diskEncryptionKeyproperty. If you are using an RSA-wrapped key, usethe beta version of the method.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks

{ "name": "TARGET_DISK_NAME" "sourceDisk": "projects/PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME" "diskEncryptionKey": { "rsaEncryptedKey": "ieCx/NcW06PcT7Ep1X6LUTc/hLvUDYyzSZPPVCVPTVEohpeHASqC8uw5TzyO9U+Fka9JFHz0mBibXUInrC/jEk014kCK/NPjYgEMOyssZ4ZINPKxlUh2zn1bV+MCaTICrdmuSBTWlUUiFoDD6PYznLwh8ZNdaheCeZ8ewEXgFQ8V+sDroLaN3Xs3MDTXQEMMoNUXMCZEIpg9Vtp9x2oeQ5lAbtt7bYAAHf5l+gJWw3sUfs0/Glw5fpdjT8Uggrr+RMZezGrltJEF293rvTIjWOEB3z5OHyHwQkvdrPDFcTqsLfh+8Hr8g+mf+7zVPEC8nEbqpdl3GPv3A7AwpFp7MA==" }, }

Replace the following:

Create disk clones for CMEK-encrypted disks

If you use a CMEK to encrypt your source disk, you must also use the same key to encrypt the clone.

Console

Compute Engine automatically encrypts the clone using the source disk encryption key.

gcloud

To create a disk clone for a CMEK-encrypted source disk, run thegcloud compute disks create commandand provide the source disk encryption key using the --kms-key flag. If you are using an RSA-wrapped key, use thegcloud beta compute disks create command.

gcloud compute disks create TARGET_DISK_NAME
--description="cloned disk"
--source-disk=projects/PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME
--kms-key projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY

Replace the following:

Go

Go

Before trying this sample, follow the Go setup instructions in theCompute Engine quickstart using client libraries. For more information, see theCompute Engine Go API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Java

Java

Before trying this sample, follow the Java setup instructions in theCompute Engine quickstart using client libraries. For more information, see theCompute Engine Java API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Python

Python

Before trying this sample, follow the Python setup instructions in theCompute Engine quickstart using client libraries. For more information, see theCompute Engine Python API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

REST

To create a disk clone for a CMEK-encrypted source disk, make a POST request to the compute.disks.insert methodand provide the source disk encryption key using the kmsKeyName property. If you are using an RSA-wrapped key, usethe beta version of the method.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks

{ "name": "TARGET_DISK_NAME" "sourceDisk": "projects/PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME" "diskEncryptionKey": { "kmsKeyName": "projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY" }, }

Replace the following:

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-05-06 UTC.