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

  • If you want to use the command-line examples in this guide:
    1. Install or update to the latest version of the gcloud command-line tool.
    2. Set a default region and zone.
  • Enable the Cloud Build API. This feature uses the Cloud Build service to import and create Compute Engine images. You must enable the Cloud Build API to use this feature.

    Enable the Cloud Build API

    Compute Engine will also grant the Cloud Build service account the following roles so it can import images into Compute Engine:

    • roles/iam.serviceAccountTokenCreator
    • roles/compute.admin
    • roles/iam.serviceAccountUser

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 operating systems:
    • Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server 2012 R2 Core, Windows Server 2016, Windows Server 2016 Core
    • Windows 7 SP1 x64 and Windows 10 Enterprise x64 (supported for BYOL only)

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 might 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.
  • Operating systems on virtual disks must support ACPI.

Permissions

The image import tool performs several steps when you import a virtual disk file including uploading your file to Google Cloud Storage, creating a new bucket if necessary, downloading the file to Compute Engine, and then creating an image in Compute Engine from the disk file. This process happens automatically; as such, Google recommends that you have the following roles to enable a seamless experience when using this feature:

  • roles/storage.admin on the project
  • roles/viewer on the project
  • roles/resourcemanager.projectIamAdmin on the project

Importing virtual disks

Checking for compatibility

Before you attempt to import the disk for your virtual machine, download and run the precheck tool inside your virtual machine. The precheck tool scans for any compatibility issues that might cause the import process to fail or the disk to not work properly on Compute Engine.

Importing a bootable virtual disk

Console

  1. In the Google Cloud Platform Console, upload the virtual disk file to Cloud Storage.
  2. Go to the Create an image page .
    GO TO THE CREATE AN IMAGE PAGE
  3. Specify a Name for your image.
  4. Under Source, select Virtual disk (VMDK, VHD,..).
  5. Browse to or manually input the storage location for the Cloud Storage file.
  6. Select the operating system that is available on the imported disk. You can also make the following changes:

    • You can choose to Install guest packages. It is recommended that you install the guest environment. For more information about the guest environment, read guest environment.

    • For Windows or Red Hat Enterprise Linux (RHEL) operating systems, you can also choose a licensing option. You can either allow Compute Engine to provide a license or you can bring your own license. For more information about bringing your own license on Windows, read Bring your own license.

  7. (Optional) Specify additional properties for your image. For example, you can organize this image as part of an image family.

  8. Click Create to import the image.

gcloud

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 beta 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 provide 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, ubuntu-1404, ubuntu-1604, windows-2008r2, windows-2012, windows-2012r2, windows-2016 or a BYOL-licensed image.

    (Beta) 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 want 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
    • If you want to bring your own license for Windows, you can import the disks as BYOL-licensed images by specifying one of the following BYOL values for the [OS] field:

      • windows-2008r2-byol
      • windows-2012-byol
      • windows-2012r2-byol
      • windows-2016-byol
      • windows-7-byol
      • windows-10-byol

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.

Sample command

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

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

Optional parameters

By default guest environment packages are added to all imported boot disk images. If you do not want these packages, add the --no-guest-environment flag to your import command.

Importing a non-bootable virtual disk

Console

  1. In the Google Cloud Platform Console, upload the virtual disk file to Cloud Storage.
  2. Go to the Create an image page.
    GO TO THE CREATE AN IMAGE PAGE
  3. Specify a Name for your image.
  4. Under Source, select Virtual disk (VMDK, VHD, ...).
  5. Browse to or manually input the storage location for the Cloud Storage file.
  6. Under operating system, select No operating system. Data only.
  7. (Optional) Specify additional properties for your image. For example, you can organize this image as part of an image family.
  8. Click Create to import the image.

gcloud

You can use the gcloud compute images import command to create a non-bootable Compute Engine image. 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.

Sample command

The following example imports a virtual disk named your_disk.vmdk stored in gs://your_gcs_bucket.

gcloud compute images import my-imported-image \
    --source-file gs://your_gcs_bucket/your_disk.vmdk \
    --data-disk

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, ubuntu-1404, ubuntu-1604, windows-2008r2, windows-2012, windows-2012r2, windows-2016 or a BYOL-licensed image.

Support for Bring Your Own License (BYOL)

  • If you are using your own software subscriptions from RHEL, you can make the BYOL-licensed image bootable by specifying one of the following BYOL values for the [OS] field:

    • rhel-6-byol
    • rhel-7-byol
  • If you are using a bring your own license image for Windows, you can make the BYOL-licensed image bootable by specifying one of the following BYOL values for the [OS] field:

    • windows-2008r2-byol
    • windows-2012-byol
    • windows-2012r2-byol
    • windows-2016-byol
    • windows-7-byol
    • windows-10-byol

Sample command

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

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

Σας βοήθησε αυτή η σελίδα; Πείτε μας τη γνώμη σας:

Αποστολή σχολίων σχετικά με…

Αυτή η σελίδα
Compute Engine Documentation