You can use Google Cloud Hyperdisk and Persistent Disk volumes as boot disks and data disks for Compute Engine instances.
This document explains how to complete the following tasks:
Convert a disk to a different Persistent Disk or Hyperdisk type by creating a new disk that contains the original disk's data. Depending on the new disk type you choose, you can gain the following benefits:
- Reach higher performance levels if you choose a faster disk type
- Reduce costs if you choose a more cost-efficient disk type
Configure whether or not Compute Engine deletes a compute instance's boot or data disks when you delete the instance. You incur costs for a disk until you delete it, even if the disk isn't attached to any instances. You can reduce costs by enabling automatic deletion of disks that you won't need after the attached instance is deleted.
To change a disk's size, see Modify the size or provisioned performance of a Hyperdisk volume and Modify the size of a Persistent Disk, respectively.
Change the type of a Persistent Disk volume
At times, you need to change the type of a particular Persistent Disk volume to meet your performance or pricing requirements. For example, you might want to change a workload's data disk from a Standard Persistent Disk to a Balanced Persistent Disk.
You can't directly change the type of an existing Persistent Disk volume. You must create a snapshot of the existing disk and then use that snapshot to create a disk of the new type.
To change a Persistent Disk volume (the source disk) to another Persistent Disk type (the new disk), use the following process:
If the source disk is attached to a compute instance, stop the instance.
Create a snapshot of the source disk.
Create the new disk from the snapshot of the source disk.
To start using the new disk, detach the source disk from the instance and attach the new disk that you just created.
If the source disk is a boot disk:
If the source disk is a non-boot disk:
Verify that new disk works as expected.
After you test the new disk, you can delete the snapshot and delete the source disk. You continue to incur charges for the source disk and snapshot until you delete them.
Modify a disk's auto-delete setting
To prevent accidental data loss, you can can control whether or not Compute Engine automatically deletes any of the Google Cloud Hyperdisk or Persistent Disk volumes that are attached to the instance when you delete the instance. Local SSD disks are always deleted with the instance.
The autoDelete property for each Google Cloud Hyperdisk or Persistent Disk volume
that is attached to the instance controls this behavior.
To keep a specific volume when you delete the instance, set the autoDelete
property for the volume to false. Conversely, to delete a volume when you
delete the instance, set the autoDelete property to true.
You can't automatically delete a disk if the disk is attached to the instance in read-only mode.
Console
In the Google Cloud console, go to the VM instances page.
Select the instance that has the disks associated with it.
Click the instance name. The VM instance details page appears.
Click Edit.
To update the auto-delete setting for your disks, in the Storage section, follow these steps:
- For the boot disk, under the heading Boot disk, select the boot disk's Deletion Rule.
- For an additional disk, find the disk in the Additional disks section, then follow these steps:
- Click Edit disk. The Existing disk pane opens.
- Under Attachment mode set the disk's Deletion Rule. To save the setting for the disk and close the pane, click Save.
To save your changes, click Save.
gcloud
Set the auto-delete state of a disk with the
gcloud compute instances set-disk-auto-delete command.
To keep the disk when you delete the instance, specify the --no-auto-delete
flag.
To delete the disk, specify the --auto-delete flag.
gcloud compute instances set-disk-auto-delete INSTANCE_NAME \ AUTO_DELETE_SETTING \ --disk DISK_NAME
Replace the following:
INSTANCE_NAME: the name of the instance.AUTO_DELETE_SETTING: whether or not to automatically delete the disk. Specify--no-auto-deleteto keep the disk after deleting the compute instance, and--auto-deleteto delete the disk at the same time as the instance.DISK_NAME: the name of the disk.
Go
Before trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Java API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Node.js API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Python API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
REST
To set the auto-delete state using the API, make a POST request to the
instances.setDiskAutoDelete
method.
Use the autoDelete parameter to indicate whether to delete the disk.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/setDiskAutoDelete?deviceName=DISK_NAME,autoDelete=AUTO_DELETE_OPTION
Replace the following:
PROJECT_ID: your project ID.ZONE: the zone where your instance and disk are located.INSTANCE_NAME: the name of your instanceDISK_NAME: the name of the disk attached to the instance.AUTO_DELETE_OPTION: whether or not to automatically delete the disk when you delete the instance. To delete the disk, set totrue. Set tofalseto keep the disk after deleting the instance.
Troubleshooting
To find methods for diagnosing and resolving issues related to full disks and disk resizing, see Troubleshooting full disks and disk resizing.
What's next
- Learn how to regularly back up your disks using snapshots to prevent unintended data loss.
- Use regional persistent disks for synchronous replication between two zones.
- Mount a RAM disk on your instance.