Importing a Virtual Machine into GCE

Ivan Kenneth Wang
Ninja Van Tech
Published in
3 min readAug 6, 2018

When someone says Cloud Computing, Amazon Web Services aka AWS has always been the first thing that comes to my mind. That’s because AWS has been there for over a decade now, and they have been the leader in terms of Cloud Computing which includes IaaS, PaaS and SaaS. However, in the past few years, more and more reputable companies are starting to compete with AWS. Competitors include Microsoft Azure and Google Cloud Platform.

Without a doubt, AWS Marketplace has far more official and non-official OS images than the rest. That should not come as a surprise given that AWS was launched at least a decade ago.

In my experience, I have had a few occasions where I can find an image in AWS but not in GCP. Such examples are VyOS, FreePBX, etc.

After a few trial and errors, I finally managed to import a VM using VirtualBox into GCE Image. I will be sharing my setup and the steps I did. In this example, I’m going to make a FreePBX in GCE.

Requirement:

  • VirtualBox 5.1.18
  • tar (GNU tar) 1.30

Steps:

FreePBX is based from Red Hat
  • Download FreePBX iso and create Virtual Box machine with VDI disk.
    Tip: Keep the disk size small to save time and billing cost (network i/o, storage, image, vm). You can always resize and expand the disk after creating your GCE VM.
VDI disk image. Keep the size as small as possible.
  • Install FreePBX into the VM and remove the CD afterwards.

Make sure it boots up, k?

  • Unmount the disk from the VM
Unmount the disk from the VM. {Before (Left) | After (Right)}
  • List your Virtual Box disks. Make sure you see the FreePBX VDI disk
$ VBoxManage list hdds
UUID: 7c5fe3b3-8b08-4aaa-a0b5-ba8ebde99acf
Parent UUID: base
State: created
Type: normal (base)
Location: /Users/ivan/VirtualBox VMs/FreePBX/FreePBX.vdi
Storage format: VDI
Capacity: 5120 MBytes
Encryption: disabled
  • Clone the disk in RAW format and filename must be disk.raw
$ VBoxManage clonehd ~/VirtualBox\ VMs/FreePBX/FreePBX.vdi ~/disk.raw --format RAW
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone medium created in format 'RAW'. UUID: 3a330a4b-b1d1-4305-92ac-300d026a6f2f
  • Install GNU tar.
    Note: OS X comes with bsdtar and that does not work
$ brew install gnu-tar
  • Compress disk.raw into .tar.gz using GNU tar.
$ cd ~
$ gtar -Sczf /tmp/freepbx.tar.gz disk.raw
  • Upload freepbx.tar.gz in Google Storage
Google Storage
  • Create a GCE Image
Google Compute Engine > Images
  • Voila, you may now start a new VM using this image.

Reference:
https://cloud.google.com/compute/docs/images/import-existing-image

--

--