How to move a VM instance between projects on Google Cloud Platform

Robert Kubis
May 20, 2015 · 4 min read

Currently there is no one-line command to move a Linux VM instance between Google Cloud Platform projects, but I’ve created an easy to follow step-by-step guide that you can use. (Note: This guide does not cover Windows.)

Quick summary of steps needed

  • Detach the boot disk from the VM that you intend to move by deselecting “Delete boot disk on instance delete” and terminating the VM
  • Create an image from the detached boot disk
  • Upload the image to Google Cloud Storage and share it with the new project
  • Create a custom image under the new project based on the image you uploaded to Google Cloud Storage
  • Create a new VM instance under the new project based on the custom image

Detailed steps of moving a VM between projects

Deselect boot disk deletion (Important!) and terminate the VM that you want to move (I recommend shutting down gracefully before termination)

Create a temporary disk in the same zone as the disk from your terminated VM. Make it large enough to fit your VM image (use at least twice the size of the persistent disk of your VM - larger means faster)

Create a VM instance with full access to Google Cloud Storage under the old project. Use the same zone the temporary and terminated VM disks are in. Don’t attach the temporary and terminated VM disks yet.

Select Full access to Storage

Attach the temporary disk and the disk from your terminated VM to the running VM we just created for the image preparation. This attaches the disks after boot and avoids boot complications.

SSH into the preparation VM, format and mount the temporary disk

Use gcimagebundle to create a compressed image of the boot disk from your terminated VM. Once that is done upload it to a bucket in Google Cloud Storage with gsutil. Jump to the next step for instructions on how to create a bucket in Google Cloud Storage for the upload.

While gcimagebundle is running create a Google Cloud Storage bucket in your old project where the preparation VM is running

Make the Google Cloud Storage Object accessible to you in your new project by adding your email to the object permissions

Create a custom image from the Google Cloud Storage object in your new project

Create a VM instance from your custom image and voilà! ☺

Last but not least, cleanup all the resource you don’t need anymore. Once you’ve verified that the move of your VM was successful you can delete the temporary disk, the disk from the terminated VM, the preparation VM and the bucket in Google Cloud Storage from the old project.

This blog post used information from https://cloud.google.com/compute/docs/images#export_an_image_to_google_cloud_storage

Google Cloud Platform - Community

A collection of technical articles published or curated by Google Cloud Platform Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Robert Kubis

Written by

Google Cloud DA, Developer, Do-it mentality, Enthusiast. Enjoying tech trends, food, travel, all kinds of outdoor activities, flying. Views are my own.

Google Cloud Platform - Community

A collection of technical articles published or curated by Google Cloud Platform Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade