0
votes

I have a custom vhd which I have in my Azure VM. It's a linux machine. I need to use azure cli to create an Image from this vhd file. This image will then be used to create VMs which have a username and Password. I have successfully used the vhd to create an Image using the Portal and created a VM out of it. However, I am unable to create an image using cli commands. This is what I get when I run the command -

jenkins@Jenkins-vm:~/testFolder$ az image create -g myRG -n myImage --os-type Linux --source ./myCustom.vhd
usage: az image create [-h] [--verbose] [--debug] [--only-show-errors]
                       [--output {json,jsonc,yaml,yamlc,table,tsv,none}]
                       [--query JMESPATH] [--subscription _SUBSCRIPTION]
                       --resource-group RESOURCE_GROUP_NAME --name NAME
                       --source SOURCE [--os-type {Windows,Linux}]
                       [--data-disk-sources DATA_DISK_SOURCES [DATA_DISK_SOURCES ...]]
                       [--location LOCATION]
                       [--storage-sku {Standard_LRS,Premium_LRS,StandardSSD_LRS,UltraSSD_LRS}]
                       [--hyper-v-generation {V1,V2}]
                       [--os-disk-caching {None,ReadOnly,ReadWrite}]
                       [--data-disk-caching {None,ReadOnly,ReadWrite}]
                       [--tags [TAGS [TAGS ...]]]
                       [--zone-resilient [{true,false}]]
az image create: error: 'NoneType' object has no attribute 'os_disk'

I don't understand the meaning of the error displayed. I'm very new to Azure so feeling a little lost.

1

1 Answers

1
votes

You can see the description of the CLI command az image create:

Create a custom Virtual Machine Image from managed disks or snapshots.

And the description of the parameter --source:

OS disk source from the same region, including a virtual machine ID or name, OS disk blob URI, managed OS disk ID or name, or OS snapshot ID or name.

It means the CLI command only can create VM images from Azure, not matter the VM blob URI, managed disk, or snapshot, all of them should exist in Azure. So you need to upload the VHD file to Azure Storage Blob, and then use the VHD URI to create the VM image via the CLI command. And one thing you need to watch out is that the VHD file should be the OS disk.