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 Persistent Disk volume
You can automatically delete read/write Persistent Disk volumes when the
associated VM instance is deleted. This behavior is controlled by the
autoDelete
property on the VM instance for a given attached disk
and can be updated at any time. Similarly, you can prevent a
Persistent Disk volume from being deleted 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
Set the auto-delete state of a Persistent Disk with the
gcloud compute instances set-disk-auto-delete
command. To keep the disk, use the --no-auto-delete
flag.
To delete the disk,
use the --auto-delete
flag.
gcloud compute instances set-disk-auto-delete VM_NAME \ AUTO_DELETE_SETTING \ --disk DISK_NAME
Replace the following:
VM_NAME
: the name of the instanceAUTO_DELETE_SETTING
: whether or not to automatically delete the disk. Specify--no-auto-delete
to keep the disk after deleting the VM, and--auto-delete
to delete the disk at the same time as the VMDISK_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/VM_NAME/setDiskAutoDelete?deviceName=DISK_NAME,autoDelete=AUTO_DELETE_OPTION
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 the disk attached to the instance.AUTO_DELETE_OPTION
: whether or not to automatically delete the disk when the VM is deleted. To delete the disk, set totrue
. Set tofalse
to keep the disk after deleting the VM.
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.