Bring a Windows custom image to shared image gallery

You can use shared image gallery to bring your own Windows custom images and use these images to create labs in Azure Lab Services. This article shows how to bring a custom image from:

This task is typically performed by a school's IT department.

Bring a Windows custom image from a physical lab environment

The steps in this section show how to import a custom image that starts from your physical lab environment. With this approach, you create a VHD from your physical environment and import the VHD into shared image gallery so that it can be used within Lab Services. Here are some key benefits with this approach:

The steps in this section require that you have permission to create a managed disk in your school's Azure subscription.

Important

When moving images from a physical lab environment to Lab Services, you should restructure each image so that it only includes software needed for a lab's class. For more information, read the Moving from a Physical Lab to Azure Lab Services blog post.

Many options exist for creating a VHD from a physical lab environment. The below steps show how to create a VHD from a Windows Hyper-V virtual machine (VM) using Hyper-V Manager.

  1. Start with a Hyper-V VM in your physical lab environment that has been created from your image. Read the article on how to create a virtual machine in Hyper-V for more information.

    1. The VM must be created as a Generation 1 VM.

    2. The VM's virtual disk must be a fixed size VHD. The disk size must not be greater than 128 GB. When you create the VM, enter the size of the disk as shown in the below image.

      Connect virtual hard disk

    Important

    Images with disk size greater than 128 GB are not supported by Lab Services.

  2. Connect to the Hyper-V VM and prepare it for Azure by following these steps:

    1. Set Windows configurations for Azure.
    2. Check the Windows Services that are needed to ensure VM connectivity.
    3. Update remote desktop registry settings.
    4. Configure Windows Firewall rules.
    5. Install Windows Updates.
    6. Install Azure VM Agent and additional configuration as shown here

    You can upload either specialized or generalized images to shared image gallery and use them to create labs. The steps above will create a specialized image. If you need to instead create a generalized image, you also will need to run SysPrep.

    Important

    You should create a specialized image if you want to maintain machine-specific information and user profiles. For more information about the differences between generalized and specialized images, see Generalized and specialized images.

  3. Since Hyper-V creates a VHDX file by default, you need to convert this to a VHD file.

    1. Navigate to Hyper-V Manager -> Action -> Edit Disk.
    2. Next, Convert the disk from a VHDX to a VHD.
    • If you expand the disk size, make sure that you do not exceed 128 GB.
      Choose action

    For more information, read the article that shows how to convert the virtual disk to a fixed size VHD.

  4. Upload the VHD to Azure to create a managed disk.

    1. You can use either Storage Explorer or AzCopy from the command line, as shown in Upload a VHD to Azure or copy a managed disk to another region.

    2. After you've uploaded the VHD, you should now have a managed disk that you can see in the Azure portal.

    Warning

    If your machine goes to sleep or locks, the upload process may get interrupted and fail.

    Important

    The Azure portal's Size+Performance tab for the managed disk allows you to change your disk size. As mentioned before, the size must not be greater than 128 GB.

  5. Take a snapshot of the managed disk. This can be done either from PowerShell, using the Azure portal, or from within Storage Explorer, as shown in Create a snapshot using the portal or PowerShell.

  6. In shared image gallery, create an image definition and version:

    1. Create an image definition.
    • Choose Gen 1 for the VM generation.
    • Choose whether you are creating a specialized or generalized image for the Operating system state.

    For more information about the values you can specify for an image definition, see Image definitions.

    Note

    You can also choose to use an existing image definition and create a new version for your custom image.

  7. Create an image version.

    • The Version number property uses the following format: MajorVersion.MinorVersion.Patch. When you use Lab Services to create a lab and choose a custom image, the most recent version of the image is automatically used. The most recent version is chosen based on the highest value of MajorVersion, then MinorVersion, then Patch.
    • For the Source, choose Disks and/or snapshots from the drop-down list.
    • For the OS disk property, choose the snapshot that you created in previous steps.

    For more information about the values you can specify for an image definition, see Image versions.

  8. Create the lab in Lab Services and select the custom image from the shared image gallery.

    If you expanded the disk after the OS was installed on the original Hyper-V VM, you also will need to extend the C drive in Windows to use the unallocated disk space:

Bring a Windows custom image from an Azure virtual machine

Another approach is to set up your Windows image using an Azure virtual machine. Using an Azure virtual machine (VM) gives you flexibility to create either a specialized or generalized image to use with your labs. The process to prepare an image from an Azure VM are simpler compared to creating an image from a VHD because the image is already prepared to run in Azure.

You will need permission to create an Azure VM in your school's Azure subscription to complete the below steps:

  1. Create an Azure VM using the Azure portal, PowerShell, the Azure CLI, or from an ARM template.

    • When you specify the disk settings, ensure the disk's size is not greater than 128 GB.
  2. Install software and make any necessary configuration changes to the Azure VM's image.

  3. Run SysPrep if you need to create a generalized image. For more information, see Generalized and specialized images.

  4. In shared image gallery, create an image definition or choose an existing image definition.

    • Choose Gen 1 for the VM generation.
    • Choose whether you are creating a specialized or generalized image for the Operating system state.
  5. Create an image version.

    • The Version number property uses the following format: MajorVersion.MinorVersion.Patch.
    • For the Source, choose Disks and/or snapshots from the drop-down list.
    • For the OS disk property, choose your Azure VM's disk that you created in previous steps.
  6. Create the lab in Lab Services and select the custom image from the shared image gallery.

You can also import your custom image from an Azure VM to shared image gallery using PowerShell. See the following script and accompanying ReadMe for more information:

Next steps