You can use a persistent disk as a boot disk for a virtual machine (VM) instance, or as a data disk that you attach to a VM. This document explains how to modify existing persistent disks to do the following:
- Switch to a different disk type.
- Auto-delete disks when attached VMs are deleted.
For general information about persistent disks and the types of disks that are available, read the persistent disk overview.
Change the type of your persistent disk
You can change the type of your persistent disk at any time. Persistent disk types differ in terms of pricing and performance characteristics, so you might need to change the type of an existing persistent disk to better suit your workload.
You can change the type of your persistent disk using snapshots. For example, to change your standard persistent disk to an SSD persistent disk, use the following process:
Console
- Create a snapshot of your standard persistent disk.
- Create a new persistent disk based on the snapshot. From the Type drop-down list, select "SSD persistent disk".
gcloud
- Create a snapshot of your standard persistent disk.
- Create a new persistent disk based on the snapshot.
Include the
--type
flag and specifypd-ssd
.
REST
- Create a snapshot of your standard persistent disk.
- Create a new persistent disk based on the snapshot.
In the
type
field, specify"zones/ZONE/diskTypes/pd-ssd"
and replaceZONE
with the zone where your instance and new disk are located.
Set the auto-delete state of a zonal persistent disk
You can automatically delete read/write zonal persistent disks when the
associated VM instance is deleted. This behavior is controlled by the
autoDelete
property on the VM instance for a given attached zonal persistent
disk and can be updated at any time. Similarly, you can also prevent a zonal
persistent disk from being deleted as well by marking the autoDelete
value as
false.
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.
In the Storage section, under the heading Additional disks, click the pencil icon
to change the disk's Deletion Rule.Click Save to update your instance.
gcloud
To set the auto-delete state of a zonal persistent disk, use the
gcloud compute instances set-disk-auto-delete
command
command:
gcloud compute instances set-disk-auto-delete example-instance \ [--auto-delete|--no-auto-delete] \ --disk DISK_NAME
Replace DISK_NAME with 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
If you are using the API, make a POST
request to the following URI:
https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/setDiskAutoDelete?deviceName=DISK_NAME,autoDelete=true
Replace the following:
PROJECT_ID
: your project IDZONE
: the zone where your instance and disk are locatedVM_NAME
: the name of your instanceDISK_NAME
: the name of your disk
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.