1
votes

I have some custom images which were created from VMs running in Google Compute Engine. Now I want to transfer and keep those images in Google storage bucket for future usage. What is the best possible way to achieve this?

I have gone through the document "https://cloud.google.com/compute/docs/creating-custom-image#export_an_image_to_google_cloud_storage" , but that says to create an image out of a running VM into a .tar file and then export it. Also that is little but confusing for me.

2

2 Answers

0
votes

The recommended approach to export the image to Google Cloud storage is to use gcimagebundle. To ensure the image created for your boot disk has consistent data, you can flush the file system cache and pause the IOs coming from file system before creating the image. This can be done using the following commands:

$ sudo sync
$ sudo fsfreeze -f example-disk_location (e.g. /mnt/my-disk)

Alternatively, you can use Unix tool dd to create the image (copy) of your boot disk as YOURDISK.raw to a temporary disk. Once done, compress the image, create a tarball and export it to Google Cloud Storage.

0
votes

To copy your images into a gcs bucket, create a gzip tar file of your image and then copy it into a bucket. This way you can share your custom image across projects.

Here're the commands:

sudo tar czvf myimage.tar.gz disk.raw
gsutil cp /[path]/myimage.tar.gz gs://[BUCKET_NAME]

where path is the path to your image file and BUCKET_NAME is your bucket name.