3.7. 上传并创建 Azure 镜像

完成以下步骤,将 VHD 文件上传到容器,并创建 Azure 自定义镜像。

注意

系统重启后,导出的存储连接字符串不会保留。如果以下步骤中的任何命令失败,请再次导出连接字符串。

步骤

  1. VHD 文件上传到存储容器。它可能需要几分钟时间。要获取存储容器的列表,请输入 az storage container list 命令。

    $ az storage blob upload \
        --account-name <storage-account-name> --container-name <container-name> \
        --type page --file <path-to-vhd> --name <image-name>.vhd

    例如:

    [clouduser@localhost]$ az storage blob upload \
    --account-name azrhelclistact --container-name azrhelclistcont \
    --type page --file rhel-image-{ProductNumber}.vhd --name rhel-image-{ProductNumber}.vhd
    
    Percent complete: %100.0
  2. 获取上传的 VHD 文件的 URL,以便在下面的步骤中使用。

    $ az storage blob url -c <container-name> -n <image-name>.vhd

    例如:

    $ az storage blob url -c azrhelclistcont -n rhel-image-9.vhd "https://azrhelclistact.blob.core.windows.net/azrhelclistcont/rhel-image-9.vhd"
  3. 创建 Azure 自定义镜像。

    $ az image create -n <image-name> -g <resource-group> -l <azure-region> --source <URL> --os-type linux
    注意

    虚拟机的默认 hypervisor 系列为 V1。您可以通过包含 --hyper-v-generation V2 选项来(可选)指定 V2 管理程序生成。第二代虚拟机使用基于 UEFI 的引导架构。有关第 2 代虚拟机的信息,请参阅 对 Azure 上 2 代虚拟机的支持

    命令可能会返回错误"Only blobs formatted as VHDs can be imported." 此错误可能意味着在转换为 VHD 之前,镜像与最接近的 1 MB 边界不一致。

    例如:

    $ az image create -n rhel9 -g azrhelclirsgrp2 -l southcentralus --source https://azrhelclistact.blob.core.windows.net/azrhelclistcont/rhel-image-9.vhd --os-type linux