Importing Virtual Disks

If you have virtual disks in your on-premises environment with software and configurations that you need (sometimes referred to as golden disks or golden images), you can save time by importing those virtual disks into Compute Engine and using the resulting image to create new virtual machines. The import tool supports most virtual disk file formats, including VMDK and VHD.

If you exported your disk from Compute Engine then you do not need to re-import it. You can create further images from the disk instead.

If you need an automated system for migrating several virtual machines, see the Migrating VMs to Compute Engine overview.

Before you begin

Supported operating systems

In order to be made bootable on Compute Engine, your virtual disks must be running one of the following operating systems.

  • Linux operating systems:
    • CentOS 6, CentOS 7
    • Debian 8, Debian 9
    • Red Hat Enterprise Linux 6, Red Hat Enterprise Linux 7
    • Ubuntu 14.04 LTS, Ubuntu 16.04 LTS
  • Windows Server operating systems:
    • Windows Server 2008 R2, Windows Server 2012 R2, Windows Server 2012 R2 Core, Windows Server 2016, Windows Server 2016 Core

Limitations

This feature has the following limitations:

  • Linux virtual disks must use grub as the bootloader.
  • UEFI bootloaders are not supported for either Windows or Linux.
  • Linux virtual disks must meet the same requirements as custom OS images, including support for Virtio-SCSI Storage Controller devices.
  • When installed on Windows virtual disks, application-whitelisting software, such as Cb Protection by Carbon Black, can cause the import process to fail. You may need to uninstall such software prior to import.
  • If you are importing a virtual disk running RHEL, Bring Your Own License (BYOL) is supported only if the python-boto package is installed on the virtual disk prior to import.
  • The ability to Bring Your Own License is not supported for virtual disks with Windows Server operating systems.

Importing virtual disks

Checking for compatibility

Before you attempt to import your virtual machine's disk, download and run our precheck tool inside your virtual machine. The precheck tool verifies that there are no incompatibilities.

Importing a bootable virtual disk

Use the gcloud compute images import command to create a bootable Compute Engine image. Although Compute Engine can boot most boot disk images, the import command ensures that the disk has the required drivers and latest guest environment packages, which are required to start an instance and connect to it using SSH or RDP.

You can import virtual disk files from either a Cloud Storage bucket or from your local workstation. If you import the virtual disk file from your workstation, the import tool automatically uploads the file to a Cloud Storage bucket for you. If you prefer, you can upload the virtual disk file to Cloud Storage yourself before you start the import process, but you must upload the file to a storage bucket in the same project that will be used for the import process.

gcloud compute images import [IMAGE_NAME] \
    --source-file [SOURCE_FILE] \
    --os [OS]

where:

  • [IMAGE_NAME] is the name of your destination image.
  • [SOURCE_FILE] is a virtual disk file. It can be a local file or a file stored in Cloud Storage. If your virtual disk is a local file, you can use an absolute or relative path. If your virtual disk file is already stored in Cloud Storage, the file must exist in a storage bucket in the project that is used for the import process, and you must specify the full path of the file in the gs://[BUCKET_NAME]/[OBJECT_NAME] format.
  • [OS] is the operating system of the SOURCE_FILE. It must be one of: centos-6, centos-7, debian-8, debian-9, rhel-6, rhel-7, rhel-6-byol, rhel-7-byol, ubuntu-1404, ubuntu-1604, windows-2008r2, windows-2012r2, windows-2016.

If you specify a local file, the upload operation can take a long time depending on the size of your virtual disk and the speed of your network connection. The import operation can take tens of minutes to run depending on the size of the disk.

The following example imports a debian-9 virtual disk named your_server.vmdk stored in gs://your_gcs_bucket.

gcloud compute images import my-imported-image \
    --source-file gs://your_gcs_bucket/your_server.vmdk \
    --os debian-9

Importing a non-bootable virtual disk

If your virtual disk does not have a bootable operating system installed on it, you can still import it using the --data-disk flag in place of the --os flag. This skips over the step that installs drivers and guest environment packages to make the image bootable on Compute Engine.

gcloud compute images import [IMAGE_NAME] \
        --source-file [SOURCE_FILE] \
        --data-disk

where:

  • [IMAGE_NAME] is the name of your destination image.
  • [SOURCE_FILE] is a virtual disk file. It can be a local file or a file stored in Cloud Storage. If your virtual disk is a local file, you can use an absolute or relative path. If your virtual disk file is already stored in Cloud Storage, the file must exist in a storage bucket in the project that is used for the import process, and you must specify the full path of the file in the gs://[BUCKET_NAME]/[OBJECT_NAME] format.

Making an image bootable

If you have a Compute Engine custom image that has a bootable operating system on it but does not have the necessary Compute Engine drivers or guest environment packages, you can use the image import tool to make that image bootable on Compute Engine.

Use the --source-image flag to specify a custom image to make bootable, instead of using the --source-file flag that specifies a new disk to import.

gcloud compute images import [IMAGE_NAME] \
        --source-image [SOURCE_IMAGE] \
        --os [OS]

where

  • [IMAGE_NAME] is the name of your destination image.
  • [SOURCE_IMAGE] is the name of your source image.
  • [OS] is the operating system of the SOURCE_IMAGE. It must be one of the following: centos-6, centos-7, debian-8, debian-9, rhel-6, rhel-7, rhel-6-byol, rhel-7-byol, ubuntu-1404, ubuntu-1604, windows-2008r2, windows-2012r2, windows-2016.

The following example turns a Compute Engine image named my-image into a bootable image named my-bootable-image. In this example, the operating system installed on the image is Ubuntu 16.04.

gcloud compute images import my-bootable-image --source-image=my-image --os=ubuntu-1604

Support for Bring Your Own License (BYOL)

By default, virtual disks that use Windows Server and Red Hat Enterprise Linux (RHEL) operating systems are imported and configured as premium OS images that incur additional charges.

If you prefer to use your own software subscriptions for RHEL, you can import the disks as BYOL-licensed images by specifying one of the following BYOL values for the [OS] field.

  • rhel-6-byol
  • rhel-7-byol

BYOL is not currently supported for Windows Server virtual disks.

Resource cleanup

Files stored on Cloud Storage and images in Compute Engine incur charges. The import tool imports the virtual disk file to Cloud Storage and creates one Compute Engine custom image.

After you verify that the image is imported correctly and that it boots correctly as a Compute Engine instance, you can delete the virtual disk file from Cloud Storage. The tool prints the URI of the file as it uploads it to Cloud Storage. This URI has the following form: gs://<bucket name>/tmpimage/<image name>.

If you imported an image using the --data-disk flag and then ran the import tool a second time with the --source-image flag to make that image bootable, then the first image will still exist. If you have no need for it, consider also deleting that image. If you specify the same image name for both the [IMAGE_NAME] and [SOURCE_IMAGE] parameters, then the image will be automatically overwritten and no further cleanup is required.

What's next

Was this page helpful? Let us know how we did:

Send feedback about...

Compute Engine Documentation