我有一个GCE虚拟机实例,我想将其下载以便使用VirtualBox进行开发。
关于如何上传虚拟机到Google Cloud的信息非常丰富,但是没有介绍如何下载它。
我怎样才能从Google Cloud下载GCE虚拟机实例呢?
我有一个GCE虚拟机实例,我想将其下载以便使用VirtualBox进行开发。
关于如何上传虚拟机到Google Cloud的信息非常丰富,但是没有介绍如何下载它。
我怎样才能从Google Cloud下载GCE虚拟机实例呢?
文档中有详细说明;您需要先从引导磁盘创建一个镜像, 将其导出到Cloud Storage作为tar.gz
格式,然后从那里下载到本地机器,解压缩并根据您的需要使用它。
以下是使用CLI的快速逐步指南示例:
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
.
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.
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.