Attach a non-boot disk to a VM Stay organized with collections Save and categorize content based on your preferences.
To create or change a VM's boot disk, seeCreate a boot diskandDetach and reattach a boot disk,respectively.
To create a new disk, seeCreate a new Persistent Disk volumeandCreate a new Hyperdisk volume.
Required roles and permissions
To get the permissions that you need to attach a disk to a VM, ask your administrator to grant you the following IAM roles on the project:
- Compute Instance Admin (v1) (
roles/compute.instanceAdmin.v1) - To connect to a VM instance that can run as a service account: Service Account User (v1) (
roles/iam.serviceAccountUserrole)
For more information about granting roles, seeManage access to projects, folders, and organizations.
These predefined roles contain the permissions required to attach a disk to a VM. To see the exact permissions that are required, expand theRequired permissions section:
Required permissions
The following permissions are required to attach a disk to a VM:
- To attach a disk to a VM:
compute.instances.attachDiskon the VMcompute.instances.attachDiskon the VMcompute.disks.useon the disk that you want to attach to the VM
- To format and mount the attached volume:
compute.instances.setMetadataon the VM
You might also be able to get these permissions withcustom roles or otherpredefined roles.
Disk attachment mode
When you attach a disk to a VM, you indicate how the VM can access the data onthe disk by specifying the disk attachment mode. You can choose read-onlyor read-write mode.
The default mode is read-write.
Share a disk between VMs
You can share the same disk between VMs so that each VM can simultaneouslyaccess the disk by attaching the disk to each VM. You can attach a disk to multipleVMs if the disk's type and the VM's machine type support it.
To attach a disk to multiple VMs, follow the procedure inAttach a non-boot disk to your VM for each VM.
You must use the same disk attachment mode for all VMs that you attach the diskto. For example, you can't attach a disk to one VM in read-write mode andattach it at the same time to another VM in read-only mode.
For information about attaching a disk to multiple VMs, including the supporteddisk types, seeShare a disk between VMs.
Attaching a Hyperdisk volume to multiple VMs
To attach a Hyperdisk volume to multiple VMs, make sure thedisk's access mode is set to an appropriate value for your use case. Forinstructions on setting the access mode, seeset the disk's access mode.
When you attach a Hyperdisk volume to a VM, you must choose adisk attachment mode that doesn't conflict with the disk's access mode. For example,you can't use read-only attachment mode with a disk that's in single-writer ormulti-writer mode.
Limitations
When attaching a disk to a VM, be aware of the following limitations:
A disk must be in the same zone as the VM that you want to attach it to.For regional disks, the VM must be in the same zone as one of thedisk's replicas.
You can attach up to 127 secondary, non-boot, zonal disks to a VM.
You can't attach a disk to a VM if doing so will exceed theHyperdisk size and attachment limits.
The following disk types don't support read-only mode:
- Hyperdisk Balanced
- Hyperdisk Balanced High Availability
- Hyperdisk Throughput
- Hyperdisk Extreme
When you attach a disk to multiple VMs, you must use the same disk attachmentmode for all the VMs.
When you attach a disk to multiple VMs, additional restrictions apply. See therestrictions for sharing a disk between VMs inread-only mode andmulti-writer mode.
Disks attached to multiple VMs don't support auto-delete, that is, theycan't be automatically deleted when the VM is deleted.
Attach a non-boot disk to a VM
You can attach a non-boot zonal disk to a VM by using the Google Cloud console,the Google Cloud CLI, or REST.
When attaching a disk to a VM, keep the following points in mind:
Use a custom device name: Google recommends that you specify a customdevice name when attaching a disk to a VM. The name you specify is used togenerate asymlink for the disk in theguest OS, which makes it easier to identify and manage disks on the VM.
Caution: If you add a custom device name to a disk after you attach the diskto a VM, Compute Engine temporarily detaches the disk from the VM, whichmight disrupt your workloads.Attaching a disk to multiple VMs: To attach a disk to multiple VMs, repeatthe procedure in this section for each VM. You must use the same disk attachmentmode for all VMs that you attach the disk to.
To attach aRegional Persistent Disk orHyperdisk Balanced High Availability volume to your VM,see insteadAttach a regional disk to your VM.
Console
Go to theVM instances page.
Click the name of the VM where you want to add a disk.
On the details page, clickEdit.
In theStorage section, underAdditional disks, click+ Attach existing disk.
In theDisk list, select the disk you want to attach. If the disk isn'tlisted, make sure it's in the same location as the VM. This means the samezone for a zonal disk and the same region for a regional disk.
ForDisk attachment mode, selectRead-only to only allow the VMto read from the disk. To allow the VM read-write access, selectRead/write.
UnderDeletion rule, specify whether to delete the disk whenthe VM is deleted. To keep the disk when the VM is deleted, selectKeep disk.To delete the disk when the VM is deleted, selectDelete disk. Ifyou're attaching the disk to multiple VMs, you must selectKeep disk.
Optional: Under the headingDevice name, select the optionUse a custom device name. The name you enter is used to generatea symlink for the disk, which makes disk identification easier.
To apply the changes to the disk, clickDone.
ClickSave to apply your changes and attach the disk to the VM.
gcloud
To attach a disk to a VM, use thegcloud compute instances attach-disk command.Use themode flag to specify the disk attachment mode.
gcloud compute instances attach-diskVM_NAME \ --diskDISK_NAME --device-name=DEVICE_NAME --modeDISK_ATTACHMENT_MODE
Replace the following:
VM_NAME: the name of the VM whereyou are adding the new zonal persistent diskDISK_NAME: the name of the new disk that youare attaching to the VM.DEVICE_NAME: Optional: a name that the guestOS uses to identify the disk.DISK_ATTACHMENT_MODE: Optional: how to attach the diskto the VM. For read-only mode, set toro. For read-write mode, set torw,or omit this flag becauserwis the default.
Terraform
To attach the disk to a VM, use thegoogle_compute_instance resource.
resource "google_compute_instance" "test_node" { name = "test-node" machine_type = "f1-micro" zone = "us-west1-a" boot_disk { initialize_params { image = "debian-cloud/debian-11" } } attached_disk { source = google_compute_disk.default.id device_name = google_compute_disk.default.name } network_interface { network = "default" access_config { # Ephemeral IP } } # Ignore changes for persistent disk attachments lifecycle { ignore_changes = [attached_disk] }}To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.
REST
To attach a disk to a VM, construct aPOST request to thecompute.instances.attachDisk method,and include the URL to the disk that you want to attach.
To specify the disk attachment mode, use themode parameter.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/attachDisk{ "source": "/compute/v1/projects/PROJECT_ID/zones/ZONE/disks/DISK_NAME", "deviceName":DEVICE_NAME, "mode" : "DISK_ATTACHMENT_MODE"}Replace the following:
PROJECT_ID: your project IDZONE: the zone where the VM and disk are locatedVM_NAME: the name of the VM that you want toattach the disk toDISK_NAME: the name of the disk to attachDEVICE_NAME: Optional: a name that the guestOS uses to create a symlink, which helps identify the disk.DISK_ATTACHMENT_MODE: Optional: how the disk should beattached to the VM. For read-only mode, useREAD_ONLY. For read-writemode, set toREAD_WRITE, or omit becauseREAD_WRITEisthe default.
After you attach a disk to a VM, connect to the VM and enable the VM's operatingsystem (OS) to use the disk:
- If you attached a blank disk, format and mount the disk
- If you attached a non-empty disk, mount the disk
Learn how to format and mount your new disks onLinuxorWindows VMs.
What's next
- Prevent data loss by regularlybacking up your disks with snapshots
- Useregional persistent disksfor synchronous replication between two zones.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.