Google Compute Engine (GCE) is a cloud-based virtual machine service that enables users to run their applications on Google’s infrastructure.
One of the critical features of GCE is the ability to use persistent disks, which retain their data even after the virtual machine is shut down.
This article will discuss attaching and detaching persistent disks in Google Compute Engine.
Before diving into the steps to attach and detach a persistent disk, let’s understand what a persistent disk is. A persistent disk is a storage device that can be attached to a virtual machine in GCE.
These disks are highly durable and reliable and can store data even if the virtual machine is terminated. Persistent disks can store operating system images, application data, and other data types.
Now that we understand a persistent disk let’s move on to attaching and detaching it in GCE.

Contents
- 1 How to Attach a Persistent Disk in Google Compute Engine
- 2 How to Detach a Persistent Disk in Google Compute Engine
- 3 How to Add a Persistent Disk in Google Compute Engine
- 4 How to Remove a Persistent Disk in Google Compute Engine
- 5 How to Mount a Persistent Disk in Google Compute Engine
- 6 How to Unmount a Persistent Disk in Google Compute Engine
How to Attach a Persistent Disk in Google Compute Engine

To attach a persistent disk in GCE, follow the steps below:
- Open the Google Cloud Console and navigate to the virtual machine where you want to attach the persistent disk.
- In the navigation pane on the screen’s left side, click “Disks.”
- Click on “Create Disk.”
- In the “Create a Disk” page, enter a name for the disk, select the disk type, and specify the disk size. You can also select the region and zone where you want to create the disk.
- Click on “Create.”
- Once the disk is created, click “Attach Disk” to attach it to the virtual machine.
- In the “Attach Existing Disk” page, select the disk you just created and specify the device name for the disk.
- Click on “Attach.”
- The disk is now attached to the virtual machine. You can verify this by navigating to the virtual machine and clicking “Edit.” In the “Edit Instance” page, you should see the attached disk listed under “Additional disks”.
You have successfully attached a persistent disk to a virtual machine in GCE.
How to Detach a Persistent Disk in Google Compute Engine

To detach a persistent disk in GCE, follow the steps below:
- Open the Google Cloud Console and navigate to the virtual machine with the attached persistent disk.
- In the navigation pane on the screen’s left side, click “Disks.”
- Click on the persistent disk you want to detach.
- Click on “Edit.”
- In the “Edit Disk” page, click on “Detach Disk.”
- On the “Detach Disk” page, confirm that you want to detach the disk by clicking “Detach.”
- The disk is now detached from the virtual machine. You can verify this by navigating to the virtual machine and clicking “Edit.” In the “Edit Instance” page, you should not see the detached disk listed under “Additional disks.”
You have successfully detached a persistent disk from a virtual machine in GCE.
How to Add a Persistent Disk in Google Compute Engine

To add a persistent disk in GCE, follow the steps below:
- Open the Google Cloud Console and navigate to the virtual machine where you want to add the persistent disk.
- In the navigation pane on the screen’s left side, click “Disks.”
- Click on “Create Disk.”
- In the “Create a Disk” page, enter a name for the disk, select the disk type, and specify the disk size. You can also select the region and zone where you want to create the disk.
- Click on “Create.”
- Once the disk is created, navigate to the virtual machine and click “Edit.”
- In the “Edit Instance” page, scroll down to the “Additional disks” section and click on “Add item.”
- In the “Add new attached disk” page, select the disk you just created and specify the device name for the disk.
- Click on “Save”.
- The disk is now added to the virtual machine and can be used to store data.
Congratulations! You have successfully added a persistent disk to a virtual machine in GCE.
How to Remove a Persistent Disk in Google Compute Engine

To remove a persistent disk in GCE, follow the steps below:
- Open the Google Cloud Console and navigate to the virtual machine with the attached persistent disk.
- In the navigation pane on the screen’s left side, click “Disks.”
- Click on the persistent disk you want to remove.
- Click on “Delete”.
- In the “Delete Disk” page, confirm that you want to delete the disk by typing the name of the disk in the “Name” field and clicking on “Delete.”
- The disk is now removed from the virtual machine.
You have successfully removed a persistent disk from a virtual machine in GCE.
How to Mount a Persistent Disk in Google Compute Engine
To mount a persistent disk in GCE, follow the steps below:
- Open the Google Cloud Console and navigate to the virtual machine with the attached persistent disk.
- Connect to the virtual machine using SSH.
- Create a directory where you want to mount the persistent disk using the following command: sudo mkdir /mnt/<directory>
- Mount the persistent disk using the following command: sudo mount /dev/sdb1 /mnt/<directory>. Replace “/dev/sdb1” with the device name of the persistent disk and “<directory>” with the name of the directory you created in Step 3.
- You can now access the persistent disk from the mounted directory.
You have successfully mounted a persistent disk in a virtual machine in GCE.
How to Unmount a Persistent Disk in Google Compute Engine
To unmount a persistent disk in GCE, follow the steps below:
- Open the Google Cloud Console and navigate to the virtual machine with the attached persistent disk.
- Connect to the virtual machine using SSH.
- Unmount the persistent disk using the following command: sudo umount /mnt/<directory>. Replace ” with the directory’s name where the persistent disk is mounted.
- You can now detach the persistent disk using the steps mentioned earlier in this article.
You have successfully unmounted a persistent disk from a virtual machine in GCE.
Conclusion
This article discussed how to attach, detach, add, remove, mount, and unmount a persistent disk in Google Compute Engine. Persistent disks are an essential feature of GCE and can store data even after a virtual machine is terminated.
Following the steps outlined in this article, you can easily manage your persistent disks and maximize your GCE instances.
Remember always to be cautious when working with persistent disks and back up your data regularly to avoid data loss.
It is also essential to monitor your disk usage to avoid running out of storage space.