Migrate VM Images
  • 18 Nov 2024
  • 3 Minutes to read
  • Contributors
  • Dark
    Light

Migrate VM Images

  • Dark
    Light

Article summary

Overview

This document provides step-by-step instructions on how to use the CloudLabs PowerShell tool to migrate VM images from your Azure subscription to the CloudLabs image gallery. Once migrated, these images can be utilized to create new VM labs or facilitate the migration of existing labs. Additionally, this guide details all the options available with the migration tool, ensuring you can leverage its full capabilities.

Note:

Microsoft Azure does not support migration of VMs with the Security Type “ConfidentialVM”.


Prerequisites

  • Azure Account with one of the following access

    • Role: Contributor or higher.
      Scope: Resource group or subscription of compute gallery hosting images.

      OR

    • Role: Custom role with reader permission and the ability to create a managed disk.
      Scope: Resource group or subscription of compute gallery hosting images.

  • An admin account on https://portal.cloudlabs.ai/ with the following information:

    • CloudLabs resource group

    • CloudLabs tenant ID

    • CloudLabs subscription ID

    • CloudLabs Application ID

    • CloudLabs Application secret

    **This information should have been provided by the CloudLabs team


Premigration Checklist

  • Identify and gather the following information on the target images from the Azure Portal:

    • Image definition name

    • Compute gallery name

    • Resource group name

    • Subscription ID

  • Install the Azure PowerShell module on your device.

  • Connect to your source environment in Azure PowerShell.


Migrating Images

  1. Ensure that you’ve got the Azure PowerShell module installed locally. You may install the module by running the following PowerShell command:

    Install-Module Az
    
  2. Launch PowerShell ISE as an administrator on your computer. You can do this by clicking the Start menu (1) and searching for PowerShell ISE (2), then right-clicking on it and choosing Run as administrator (3).

  3. Download and save the PowerShell from this URL: https://cloudlabs.ai/alb-imagemigration-script.

    You can also use the Invoke-WebRequest cmdlet to download the script and save it to a local folder, for example:

    Invoke-WebRequest -Uri https://cloudlabs.ai/alb-imagemigration-script -OutFile C:\MigrateVMImagestoCloudLabs.ps1
  4. Connect to your Source Azure environment by running Connect-AzAccount. Ensure that you log in with an account that has the permissions outlined in the prerequisite section.

    Connect-AzAccount
  5. Prepare a command line that will run the script with the parameters that match your source and destination Azure environments and the image gallery information that you noted earlier. The command line should have the following format:

    .\MigrateVMImagestoCloudLabs.ps1 -sourceResourceGroupName “youranswer” -sourceImageGalleryName “youranswer” -sourceSubscriptionId “youranswer” -VMImagesList “youranswer"," youranswer2","youranswer3" -cloudLabsResourceGroup "youranswer" -cloudLabsTenantId "youranswer" -cloudLabsSubscriptionId "youranswer" -cloudLabsApplicationId "youranswer" -cloudLabsApplicationSecret (ConvertTo-SecureString -String "yoursecret" -AsPlainText -Force)

  6. Refer to the following table for a breakdown of all the parameters available:

    Parameters

    Description

    -sourceResourceGroupName

    The name of the resource group in the source Azure environment that contains the image gallery.

    -sourceImageGalleryName

    The name of the image gallery is in the source azure environment that contains the images to be migrated.

    -sourceSubscriptionId

    The subscription ID of the source Azure environment.

    -VMImagesList

    A comma-separated list of the names of the images to be migrated, enclosed in double quotes, such as “image1"," image2","image3"

    -cloudLabsResourceGroup

    Provided by CloudLabs Team

    -cloudLabsTenantId

    Provided by CloudLabs Team

    -cloudLabsSubscriptionId

    Provided by CloudLabs Team

    -cloudLabsApplicationId

    Provided by CloudLabs Team

    -cloudLabsApplicationSecret

    Provided by CloudLabs Team

  7. The script will copy the managed disk of the source image to the destination environment. This can take time, depending on the size and number of disks. The copy operations are on the Azure Server side; no data is downloaded/uploaded from your computer.

  8. The script will check the latest copy status every 2 minutes and display it on the screen. Do not close the PowerShell window or press Ctrl + C while the script is executing. You must keep it running until the migration is completed successfully. The script will inform you when the migration is done.

  9. Once the script execution is completed, you can navigate to your CloudLabs portal and start using the image from CloudLabs.

  10. You may run the script multiple times to migrate various images. Please be sure to run Connect-AzAccount each time before you run the script to ensure authentication is successful.


Verification

  1. Login to https://portal.cloudlabs.ai/.

  2. Navigate to Manage VM Lab (1) > Settings > Custom Images (2) and click on Add Existing Image Gallery (3).

  3. Look for the gallery named <sourcegallery>_migrated (1), select the gallery, and click on Add (2).

  4. Navigate back to the Custom Images tab. You should be able to see the newly created gallery (1) in the list and click on the Manage Images (2) button.

  5. Click on the Sync Image (1) button, and you should be able to see your newly migrated image (2) in the list.


Cleanup

The script creates temporary disks in your source Azure resource group to use for migration. After the migration is done, the script automatically deletes the disk.


Troubleshooting

If you encounter any errors, please find the log file named CloudLabsVMImageMigration_ScriptLog_datetime in the same folder where you ran the script. Please send this to the CloudLabs team for more support information. In case some of the images have failed to migrate, please correct and restart the migration process only for those images again by deleting the temporary disks in the source resource group.
If you encounter any common Azure/PowerShell errors, such as insufficient permissions, you can adjust the permissions and attempt again.