Export your Google Cloud Compute Engine VM
The process doesn’t limit to only Google Cloud Compute Engine VM and can be used on almost any systems. This process can be used to export a RAW image that later can be imported to Compute Engine on another account maybe.
- Connect to the terminal on the system that has the boot disk that is planned to be exported
- Use the
lsblk
command to identify the source boot disk from which you want to create an image and the location where you have sufficient space to write the image files. For this example,/dev/sda
is the source boot disk and/dev/sdb
is a large secondary disk mounted at the/tmp
directory. Although/dev/sda
is running, you can still create an image from it. It is best to do this on a quiet system that is not actively processing data or running your applications.lsblk
and the result will be something like :
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 100G 0 disk ├─sda1 8:1 0 96G 0 part / ├─sda2 8:2 0 1K 0 part └─sda3 8:5 0 4G 0 part [SWAP] sdb 8:16 0 500G 0 disk /tmp sr0 11:0 1 1024M 0 rom
- Create the image file from your boot disk :
sudo dd if=/dev/sda of=/tmp/disk.raw bs=4M conv=sparse
keep in mind that the name should be disk.raw in order to import it later to another Google Cloud Compute Engine - Change to the directory where you wrote the disk.raw file:
cd /tmp
- Compress the raw disk into tar.gz format :
sudo tar --format=oldgnu -Sczf /tmp/compressed-image.tar.gz disk.raw
Upload the image to Google Cloud Storage
Now we need to get that image out of the VM and the easiest way to do it is via a Google Cloud Storage bucket. You will need to create a bucket where the image will be uploaded. I assume you know to to that (it is not the subject of this post)
The process is as follows:
- Connect to gcloud:
gcloud auth login
- Use the gsutil to upload the image to the bucket:
gsutil cp compressed-image.tar.gz gs://mybucket
And that is it. Now you have the VM in RAW format in Google Storage bucket from where you can download it and import it somewhere else