Modify a persistent disk


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.

Changing 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

  1. Create a snapshot of your standard persistent disk.
  2. Create a new persistent disk based on the snapshot. From the Type drop-down list, select "SSD persistent disk".

gcloud

  1. Create a snapshot of your standard persistent disk.
  2. Create a new persistent disk based on the snapshot. Include the --type flag and specify pd-ssd.

API

  1. Create a snapshot of your standard persistent disk.
  2. Create a new persistent disk based on the snapshot. In the type field, specify "zones/ZONE/diskTypes/pd-ssd" and replace ZONE with the zone where your instance and new disk are located.

Setting 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

  1. In the Google Cloud console, go to the VM instances page.

    Go to VM instances

  2. Select the instance that has the disks associated with it.

  3. Click the instance name. The VM instance details page appears.

  4. Click Edit.

  5. Scroll to Additional disks.

  6. Click the pencil to edit the disk's Deletion Rule.

  7. Click Done to save your changes.

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

API

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 ID
  • ZONE: the zone where your instance and disk are located
  • VM_NAME: the name of your instance
  • DISK_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