Sam
Sam

Reputation: 51

How to download a Google Cloud Compute Engine VM instance

I have a GCE VM instance and I would like to download it so I can do some development using VirtualBox.

There seems to be a lot of information on how to upload VMs to Google Cloud, but there is nothing on how I can download it.

How can I download the GCE VM instance from Google Cloud?

Upvotes: 3

Views: 9091

Answers (1)

Maxim
Maxim

Reputation: 4441

The documentation explains this; you'd have to create an image from the boot disk first, export it to Cloud Storage as a tar.gz, and from there on, download it from Cloud Storage into your local machine, decompress it, and use it as you wish.

As an example, and a quick step-by-step guide using the CLI:

  1. Create an image from the boot disk with gcloud compute images create:

    gcloud compute images create my-image \
      --source-disk my-disk \
      --source-disk-zone zone
    

    Replace my-image with the name you want to give to the image, my-disk with the name of the boot disk and zone with the name of the zone the disk is located at, i.e us-central1-a.

  2. Export it to Cloud Storage with gcloud compute images export:

    If you don't have a Cloud Storage bucket, you'd indeed, need to create one first, otherwise, skip this part. By using the CLI you can create a bucket with gsutil mb, i.e gsutil mb gs://my-bucket/. Replace my-bucket with the name you desire to give it. Be aware that the name has a single namespace, so you are not allowed to create a bucket with a name already in use by another user.

    gcloud compute images export \
        --destination-uri gs://my-bucket/my-image-file.tar.gz \
        --image my-image 
    

    Replace my-bucket with the name of the Cloud Storage bucket you want to export it to, my-image-file with the name of the file containing the image and my-image with the name of the image you previously created.

    You might be prompted to enable the Cloud Build API and to add some permissions to it at this point - enter y as it's a necessary step for the export tool.

  3. Once the image has finished uploading to Cloud Storage, download it to your local machine with gsutil cp:

    gsutil cp gs://my-bucket/my-image-file.tar.gz /local/path/to/file
    

    Replace my-bucket with the name of the bucket you previously specified , my-image-file with the name you gave to the file containing the image, and /local/path/to/file with the local path you wish it to be download to.

Upvotes: 10

Related Questions