Importing a VM as an image using VM Import/Export - VM Import/Export

Importing a VM as an image using VM Import/Export

Tip

To import your virtual machines (VMs) with a console-based experience, you can use the Import virtual machine images to AWS template in the Migration Hub Orchestrator console. For more information, see the AWS Migration Hub Orchestrator User Guide.

You can use VM Import/Export to import virtual machine (VM) images from your virtualization environment to Amazon EC2 as Amazon Machine Images (AMI), which you can use to launch instances. Subsequently, you can export the VM images from an instance back to your virtualization environment. This enables you to leverage your investments in the VMs that you have built to meet your IT security, configuration management, and compliance requirements by bringing them into Amazon EC2.

Important
  • AWS VM Import/Export strongly recommends specifying a value for either the --license-type or --usage-operation parameter when you create a new VM Import task. This ensures your operating system is licensed appropriately and your billing is optimized. For more information, see Licensing options.

  • AWS VM Import/Export only supports images that were natively installed inside the source VM and not those created using a physical-to-virtual (P2V) conversion process. For more information, see the VM Import/Export Requirements.

Export your VM from its virtualization environment

After you have prepared your VM for export, you can export it from your virtualization environment. When importing a VM as an image, you can import disks in the following formats: Open Virtualization Archive (OVA), Virtual Machine Disk (VMDK), Virtual Hard Disk (VHD/VHDX), and raw. With some virtualization environments, you would export to Open Virtualization Format (OVF), which typically includes one or more VMDK, VHD, or VHDX files, and then package the files into an OVA file.

For more information, see the documentation for your virtualization environment. For example:

Programmatic modifications to VMs

When importing a VM using the ImportImage API, AWS modifies the file system to make the imported VM accessible. When writing a modified file, AWS retains the original file at the same location under a new name. The following actions may occur:

General
  • For parity with images provided by AWS, the AWS Systems Manager client is installed on the VM.

Windows
  • Modifying registry settings to make the VM bootable.

Linux
  • Installing Citrix PV drivers either directly in OS or modify initrd/initramfs to contain them.

  • Modifying network scripts to replace static IPs with dynamic IPs.

  • Modifying /etc/fstab, commenting out invalid entries and replacing device names with UUIDs. If no matching UUID can be found for a device, the nofail option is added to the device description. You must correct the device naming and remove nofail after import. As a best practice when preparing your VMs for import, we recommend that you specify your VM disk devices by UUID rather than device name.

    Entries in /etc/fstab that contain non-standard file system types (cifs, smbfs, vboxsf, sshfs, etc.) are disabled.

  • Modifying grub bootloader settings such as the default entry and timeout.

Import your VM as an image

After exporting your VM from your virtualization environment, you can import it to Amazon EC2. The import process is the same regardless of the origin of the VM.

Prerequisites

Upload the image to Amazon S3

Upload your VM image file to your Amazon S3 bucket using the upload tool of your choice. For information about uploading objects through the Amazon S3 console, see Uploading Objects.

Import the VM

After you upload your VM image file to Amazon S3, you can use the AWS CLI to import the image. These tools accept either the Amazon S3 bucket and path to the file or a URL for a public Amazon S3 file. Private Amazon S3 files require a presigned URL. You can also use the Import virtual machine images to AWS template in the Migration Hub Orchestrator console to import your on-premises virtual machine images to AWS. For more information, see Example 4.

The following examples use the AWS CLI command import-image to create import tasks.

Example 1: Import an image with a single disk

Use the following command to import an image with a single disk.

aws ec2 import-image --description "My server VM" --disk-containers "file://C:\import\containers.json"

The following is an example containers.json file that specifies the image using an S3 bucket.

[ { "Description": "My Server OVA", "Format": "ova", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.ova" } } ]

The following is an example containers.json file that specifies the image using a URL in Amazon S3.

[ { "Description": "My Server OVA", "Format": "ova", "Url": "s3://my-import-bucket/vms/my-server-vm.ova" } ]

Example 2: Import an image with multiple disks

Use the following command to import an image with multiple disks.

$ C:\> aws ec2 import-image --description "My server disks" --disk-containers "file://C:\import\containers.json"

The following is an example containers.json file.

[ { "Description": "First disk", "Format": "vmdk", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "disks/my-server-vm-disk1.vmdk" } }, { "Description": "Second disk", "Format": "vmdk", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "disks/my-server-vm-disk2.vmdk" } } ]

Example 3: Import with the encrypted option enabled

Use the following command to import an image with an encrypted root volume.

aws ec2 import-image --description "My server disks" --encrypted --kms-key-id 0ea3fef3-80a7-4778-9d8c-1c0c6EXAMPLE --disk-containers "file://C:\import\containers.json"

The CMK provided for encryption must not be disabled during the entire import process. For more information, see Amazon EBS Encryption in the Amazon EC2 User Guide.

Example 4: Import an image using the Import virtual machine images to AWS template in Migration Hub Orchestrator

  1. Open the Migration Hub Orchestrator console.

  2. In the navigation pane, choose Create migration workflow.

  3. On the Choose a workflow template page, choose the Import virtual images to AWS template.

  4. Configure and submit your workflow to begin the VM import. For more information, see the AWS Migration Hub Orchestrator User Guide.

Monitor an import image task

Use the describe-import-image-tasks command to return the status of an import task.

aws ec2 describe-import-image-tasks --import-task-ids import-ami-1234567890abcdef0

Status values include the following:

  • active — The import task is in progress.

  • deleting — The import task is being canceled.

  • deleted — The import task is canceled.

  • updating — Import status is updating.

  • validating — The imported image is being validated.

  • validated — The imported image was validated.

  • converting — The imported image is being converted into an AMI.

  • completed — The import task is completed and the AMI is ready to use.

After the import image task is completed, the output includes the ID of the AMI. The following is example output that includes ImageId.

{ "ImportImageTasks": [ { "ImportTaskId": "import-ami-01234567890abcdef", "ImageId": "ami-1234567890EXAMPLE", "SnapshotDetails": [ { "DiskImageSize": 705638400.0, "Format": "ova", "SnapshotId": "snap-111222333444aaabb" "Status": "completed", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.ova" } } ], "Status": "completed" } ] }

Cancel an import image task

If you need to cancel an active import task, use the cancel-import-task command.

aws ec2 cancel-import-task --import-task-id import-ami-1234567890abcdef0

Next steps

After the import image task is complete, you can launch an instance using the resulting AMI or copy the AMI to another Region.

For some operating systems, the device drivers for enhanced networking and NVMe block devices that are required by Nitro-based instances are not installed automatically during import. To install these drivers manually, use the directions in the following documentation. Next, create a new AMI from the customized instance.