Sometimes an extra disk needs to leave a VM, so that another VM in the same zone can use it, or because the VM no longer needs it. The safe version of this task has three parts, stop using the disk inside the VM, tell the operating system to forget it, and only then detach it in Compute Engine. Skipping the first two can leave a VM that stalls at boot, or applications that lose files mid write.
It is also worth being clear about what detaching is not. It does not erase the data, and it does not delete the disk. The disk stays in your project with its contents intact, ready to attach somewhere else, and you keep paying for it until you delete it deliberately.
This walks through unmounting a data disk, removing its fstab entry, and detaching it in the console, then covers the boot disk difference and what to do with the disk afterward.
This page covers data disks.
Prerequisites:
Open the console, then the menu, then Compute Engine, then open VM instances from the Menu > Compute Engine > VM instances.
Open the SSH of instance from which you want to remove the extra disk.

lsblk
This lists the block devices, the disks, and shows where each is mounted. Find the disk you want to remove, and note its device name and its mount folder.

Stop any program that is using the disk first. Then unmount it, using the mount folder shown by lsblk, which is the safest thing to name:
sudo umount /mnt/disks/MOUNT_DIR
If the command says the target is busy, something is still using the disk. Find it, for example with the lsof command, close it, and try again.
Then make a backup of the fstab file and open it:
sudo cp /etc/fstab /etc/fstab.backup
sudo vi /etc/fstab

Delete the whole line for this disk, the one that names its mount folder. In vi, press escape, then type a colon, then wq, then press Enter to save and quit. Google’s guide says to remove the entry before you detach a disk, even if the entry uses the nofail option, so the VM is not left looking for a disk that is gone.

Run the listing command again and check that the disk no longer shows a mount folder:
lsblk
The original page used this spot for a screenshot of the fdisk command, which deletes a partition. Do not run that command. It is not needed to detach a disk, it makes the disk’s data unreachable, and it is exactly what you do not want if another VM is going to use the disk. I recommend replacing this screenshot with one of the lsblk output above, showing no mount folder.

Back in the console, open Compute Engine, then VM instances.

Click the instance that has the disk attached.


In the Additional disks section, find the disk you unmounted and click the button next to it that removes it. The original page calls this delete. It removes the disk from this VM, which is detaching, and the disk itself is not deleted.

Click Done, then Save. The disk is now detached from the instance.

The gcloud command for detaching a disk from a VM looks like this. I have not tested it, so check the names carefully:
gcloud compute instances detach-disk VM_NAME –disk=DISK_NAME –zone=ZONE
That covers removing a data disk from a VM safely, and what to do with it afterward. To go further, explore Prwatech’s Google Cloud training program, which includes placement assistance.